mulan.classifier
Class MultiLabelLearnerBase

java.lang.Object
  extended by mulan.classifier.MultiLabelLearnerBase
All Implemented Interfaces:
Serializable, MultiLabelLearner, TechnicalInformationHandler
Direct Known Subclasses:
BPMLL, MMPLearner, MultiLabelKNN, MultiLabelMetaLearner, TransformationBasedMultiLabelLearner

public abstract class MultiLabelLearnerBase
extends Object
implements TechnicalInformationHandler, MultiLabelLearner, Serializable

Common root base class for all multi-label learner types. Provides default implementation of MultiLabelLearner interface.

Version:
2010.12.27
Author:
Robert Friberg, Jozef Vilcek, Grigorios Tsoumakas
See Also:
Serialized Form

Field Summary
protected  int[] featureIndices
          An array containing the indexes of the feature attributes within the Instances object of the training data in increasing order.
protected  int[] labelIndices
          An array containing the indexes of the label attributes within the Instances object of the training data in increasing order.
protected  int numLabels
          The number of labels the learner can handle.
 
Constructor Summary
MultiLabelLearnerBase()
           
 
Method Summary
 void build(MultiLabelInstances trainingSet)
          Builds the learner model from specified MultiLabelInstances data.
protected abstract  void buildInternal(MultiLabelInstances trainingSet)
          Learner specific implementation of building the model from MultiLabelInstances training data set.
protected  void debug(String msg)
          Writes the debug message string to the console output if debug for the learner is enabled.
 boolean getDebug()
          Get whether debugging is turned on.
abstract  TechnicalInformation getTechnicalInformation()
          Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.
abstract  String globalInfo()
          Returns a string describing the multi-label learner.
protected  boolean isModelInitialized()
          Gets whether learner's model is initialized by build(MultiLabelInstances).
 boolean isUpdatable()
          Returns value indicating if learner is updatable, so if learner is able to perform on-line learning.
 MultiLabelLearner makeCopy()
          Creates a deep copy of the given learner using serialization.
 MultiLabelOutput makePrediction(Instance instance)
          Returns the prediction of the learner for a given input Instance.
protected abstract  MultiLabelOutput makePredictionInternal(Instance instance)
          Learner specific implementation for predicting on specified data based on trained model.
 void setDebug(boolean debug)
          Set debugging mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numLabels

protected int numLabels
The number of labels the learner can handle. The number of labels are determined form the training data when learner is build.


labelIndices

protected int[] labelIndices
An array containing the indexes of the label attributes within the Instances object of the training data in increasing order. The same order will be followed in the arrays of predictions given by each learner in the MultiLabelOutput object.


featureIndices

protected int[] featureIndices
An array containing the indexes of the feature attributes within the Instances object of the training data in increasing order.

Constructor Detail

MultiLabelLearnerBase

public MultiLabelLearnerBase()
Method Detail

isUpdatable

public boolean isUpdatable()
Description copied from interface: MultiLabelLearner
Returns value indicating if learner is updatable, so if learner is able to perform on-line learning. The fact if learner is updatable or not influences the behavior of MultiLabelLearner.build(MultiLabelInstances) method.

When false is returned, each call of the MultiLabelLearner.build(MultiLabelInstances) will initialize the learner from the scratch, removing any potential knowledge built by previously entered training data. When true is returned, then on the first call of the MultiLabelLearner.build(MultiLabelInstances) the learner is initialized with the passed training data. All other calls contribute to the existing learner's model with new data.

Specified by:
isUpdatable in interface MultiLabelLearner
Returns:
true if learner is updatable (on-line), false otherwise.

build

public final void build(MultiLabelInstances trainingSet)
                 throws Exception
Description copied from interface: MultiLabelLearner
Builds the learner model from specified MultiLabelInstances data. Sequential calls to this method either re-build the learners model with new data (off-line learner) or contribute to the existing model with new data (on-line learner). The behavior is determined by the outcome of MultiLabelLearner.isUpdatable() method.

Specified by:
build in interface MultiLabelLearner
Parameters:
trainingSet - set of training data, upon which the learner model should be built
Throws:
Exception - if learner model was not created successfully
InvalidDataException - if specified instances data is invalid or not supported by the learner
See Also:
MultiLabelLearner.isUpdatable()

buildInternal

protected abstract void buildInternal(MultiLabelInstances trainingSet)
                               throws Exception
Learner specific implementation of building the model from MultiLabelInstances training data set. This method is called from build(MultiLabelInstances) method, where behavior common across all learners is applied.

Parameters:
trainingSet - the training data set
Throws:
Exception - if learner model was not created successfully

isModelInitialized

protected boolean isModelInitialized()
Gets whether learner's model is initialized by build(MultiLabelInstances). This is used to check if makePrediction(weka.core.Instance) can be processed.

Returns:
isModelInitialized returns true if the model has been initialized

makePrediction

public final MultiLabelOutput makePrediction(Instance instance)
                                      throws Exception,
                                             InvalidDataException,
                                             ModelInitializationException
Description copied from interface: MultiLabelLearner
Returns the prediction of the learner for a given input Instance.

Specified by:
makePrediction in interface MultiLabelLearner
Parameters:
instance - the input given to the learner in the form of Instance
Returns:
a prediction of the learner in form of MultiLabelOutput.
Throws:
Exception - if an error occurs while making the prediction.
InvalidDataException - if specified instance data is invalid and can not be processed by the learner
ModelInitializationException - if method is called before MultiLabelLearner.build(MultiLabelInstances)

makePredictionInternal

protected abstract MultiLabelOutput makePredictionInternal(Instance instance)
                                                    throws Exception,
                                                           InvalidDataException
Learner specific implementation for predicting on specified data based on trained model. This method is called from makePrediction(weka.core.Instance) which guards for model initialization and apply common handling/behavior.

Parameters:
instance - the data instance to predict on
Returns:
the output of the learner for the given instance
Throws:
Exception - if an error occurs while making the prediction.
InvalidDataException - if specified instance data is invalid and can not be processed by the learner

setDebug

public void setDebug(boolean debug)
Set debugging mode.

Specified by:
setDebug in interface MultiLabelLearner
Parameters:
debug - true if debug output should be printed

getDebug

public boolean getDebug()
Get whether debugging is turned on.

Returns:
true if debugging output is on

debug

protected void debug(String msg)
Writes the debug message string to the console output if debug for the learner is enabled.

Parameters:
msg - the debug message

makeCopy

public MultiLabelLearner makeCopy()
                           throws Exception
Description copied from interface: MultiLabelLearner
Creates a deep copy of the given learner using serialization.

Specified by:
makeCopy in interface MultiLabelLearner
Returns:
a deep copy of the learner
Throws:
Exception - if an error occurs while making copy of the learner.

getTechnicalInformation

public abstract TechnicalInformation getTechnicalInformation()
Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.

Specified by:
getTechnicalInformation in interface TechnicalInformationHandler
Returns:
the technical information about this class

globalInfo

public abstract String globalInfo()
Returns a string describing the multi-label learner.

Returns:
a description suitable for displaying in a future gui