LBJ2.learn
Class MuxLearner

java.lang.Object
  extended by LBJ2.classify.Classifier
      extended by LBJ2.learn.Learner
          extended by LBJ2.learn.MuxLearner
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class MuxLearner
extends Learner

A MuxLearner uses one of many Learners indexed by the first feature in an example to produce a classification. During training, the features produced by the first child classifier of this classifier's composite generator feature extractor are taken to determine which Learners will learn from the training object. For any given example, there must be one Feature produced by the labeler for each Feature produced by the first child classifier. If this classifier's feature extractor is not a composite generator, the first feature it produces is the only one taken.

It is assumed that the Learner being multiplexed expects a single label feature on each training example, and that the feature(s) used to do the multiplexing are DiscreteFeature(s). Furthermore, if this classifier's feature extractor is a composite generator, it must produce the same number of features as this classifier's labeler, and they must correspond to each other in the order produced.

This algorithm's user-configurable parameters are stored in member fields of this class. They may be set via either a constructor that names each parameter explicitly or a constructor that takes an instance of Parameters as input. The documentation in each member field in this class indicates the default value of the associated parameter when using the former type of constructor. The documentation of the associated member field in the Parameters class indicates the default value of the parameter when using the latter type of constructor.

See Also:
Serialized Form

Nested Class Summary
static class MuxLearner.Parameters
          Simply a container for all of MuxLearner's configurable parameters.
 
Field Summary
protected  Learner baseLearner
          Instances of this learning algorithm will be multiplexed; default null.
static Learner defaultBaseLearner
          Default for baseLearner.
static java.lang.String defaultDefaultPrediction
          Default for defaultPrediction.
protected  Feature defaultFeature
          A feature whose value is defaultPrediction.
protected  java.lang.String defaultPrediction
          This string is returned during testing when the multiplexed Learner doesn't exist; default defaultDefaultPrediction.
protected  OVector network
          A map from feature values to learners.
 
Fields inherited from class LBJ2.learn.Learner
encoding, extractor, labeler, labelLexicon, lcFilePath, lexFilePath, lexicon, predictions, readLexiconOnDemand
 
Fields inherited from class LBJ2.classify.Classifier
containingPackage, name
 
Constructor Summary
MuxLearner()
          For the LBJ compiler; not for use by the LBJ user.
MuxLearner(Learner base)
          Instantiates this multiplexed learner using the specified base learning algorithm.
MuxLearner(Learner base, java.lang.String d)
          Instantiates this multiplexed learner using the specified base learning algorithm.
MuxLearner(MuxLearner.Parameters p)
          Initializing constructor.
MuxLearner(java.lang.String n)
          For the LBJ compiler; not for use by the LBJ user.
MuxLearner(java.lang.String n, Learner base)
          Instantiates this multiplexed learner using the specified base learning algorithm.
MuxLearner(java.lang.String n, Learner base, java.lang.String d)
          Instantiates this multiplexed learner using the specified base learning algorithm.
MuxLearner(java.lang.String n, MuxLearner.Parameters p)
          Initializing constructor.
 
Method Summary
 FeatureVector classify(int[] exampleFeatures, double[] exampleValues)
          This method performs the multiplexing and returns the output of the selected Learner.
 java.lang.Object clone()
          Returns a deep clone of this learning algorithm.
 java.lang.String discreteValue(int[] exampleFeatures, double[] exampleValues)
          Returns the value of the discrete feature that would be returned by this classifier.
 Feature featureValue(int[] f, double[] v)
          Returns the classification of the given example as a single feature instead of a FeatureVector.
 void forget()
          Clears the network.
 Learner.Parameters getParameters()
          Retrieves the parameters that are set in this learner.
 void learn(int[] exampleFeatures, double[] exampleValues, int[] exampleLabels, double[] labelValues)
          The training example is multiplexed to the appropriate Learner(s).
 void read(ExceptionlessInputStream in)
          Reads the binary representation of a learner with this object's run-time type, overwriting any and all learned or manually specified parameters as well as the label lexicon but without modifying the feature lexicon.
 double realValue(int[] f, double[] v)
          Returns the value of the real feature that would be returned by this classifier.
 ScoreSet scores(int[] exampleFeatures, double[] exampleValues)
          Produces a set of scores indicating the degree to which each possible discrete classification value is associated with the given example object.
 void setBase(Learner base)
          Sets baseLearner.
protected  void setDefaultFeature()
          Sets the value of defaultFeature according to the current value of defaultPrediction.
 void setLabeler(Classifier l)
          Sets the labeler.
 void setLabelLexicon(Lexicon l)
          Sets the label lexicon.
 void setParameters(MuxLearner.Parameters p)
          Sets the values of parameters that control the behavior of this learning algorithm.
 void write(ExceptionlessOutputStream out)
          Writes the learned function's internal representation in binary form.
 void write(java.io.PrintStream out)
          Writes the algorithm's internal representation as text.
 
Methods inherited from class LBJ2.learn.Learner
classify, classify, classify, classify, countFeatures, createPrediction, createPrediction, demandLexicon, discreteValue, discreteValue, doneLearning, doneWithRound, emptyClone, featureValue, featureValue, getExampleArray, getExampleArray, getExtractor, getLabeler, getLabelLexicon, getLexicon, getLexiconDiscardCounts, getLexiconLocation, getModelLocation, getPrunedLexiconSize, initialize, learn, learn, learn, learn, read, readLabelLexicon, readLearner, readLearner, readLearner, readLearner, readLearner, readLearner, readLexicon, readLexicon, readLexiconOnDemand, readLexiconOnDemand, readModel, readModel, readParameters, realValue, realValue, save, saveLexicon, saveModel, scores, scores, setEncoding, setExtractor, setLexicon, setLexiconLocation, setLexiconLocation, setModelLocation, setModelLocation, setParameters, unclone, write, writeLexicon, writeModel, writeParameters
 
Methods inherited from class LBJ2.classify.Classifier
allowableValues, classify, discreteValueArray, getCompositeChildren, getInputType, getOutputType, realValueArray, test, toString, valueIndexOf
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultBaseLearner

public static final Learner defaultBaseLearner
Default for baseLearner.


defaultDefaultPrediction

public static final java.lang.String defaultDefaultPrediction
Default for defaultPrediction.


baseLearner

protected Learner baseLearner
Instances of this learning algorithm will be multiplexed; default null.


network

protected OVector network
A map from feature values to learners.


defaultPrediction

protected java.lang.String defaultPrediction
This string is returned during testing when the multiplexed Learner doesn't exist; default defaultDefaultPrediction.


defaultFeature

protected Feature defaultFeature
A feature whose value is defaultPrediction.

Constructor Detail

MuxLearner

public MuxLearner()
For the LBJ compiler; not for use by the LBJ user.


MuxLearner

public MuxLearner(Learner base)
Instantiates this multiplexed learner using the specified base learning algorithm. This constructor will normally only be called by the compiler.

Parameters:
base - Instances of this learner will be multiplexed.

MuxLearner

public MuxLearner(Learner base,
                  java.lang.String d)
Instantiates this multiplexed learner using the specified base learning algorithm.

Parameters:
base - Instances of this learner will be multiplexed.
d - This prediction will be returned during testing when the multiplexed Learner does not exist.

MuxLearner

public MuxLearner(MuxLearner.Parameters p)
Initializing constructor. Sets all member variables to their associated settings in the MuxLearner.Parameters object.

Parameters:
p - The settings of all parameters.

MuxLearner

public MuxLearner(java.lang.String n)
For the LBJ compiler; not for use by the LBJ user.


MuxLearner

public MuxLearner(java.lang.String n,
                  Learner base)
Instantiates this multiplexed learner using the specified base learning algorithm.

Parameters:
n - The name of the classifier.
base - Instances of this learner will be multiplexed.

MuxLearner

public MuxLearner(java.lang.String n,
                  Learner base,
                  java.lang.String d)
Instantiates this multiplexed learner using the specified base learning algorithm.

Parameters:
n - The name of the classifier.
base - Instances of this learner will be multiplexed.
d - This prediction will be returned during testing when the multiplexed Learner does not exist.

MuxLearner

public MuxLearner(java.lang.String n,
                  MuxLearner.Parameters p)
Initializing constructor. Sets all member variables to their associated settings in the MuxLearner.Parameters object.

Parameters:
n - The name of the classifier.
p - The settings of all parameters.
Method Detail

setParameters

public void setParameters(MuxLearner.Parameters p)
Sets the values of parameters that control the behavior of this learning algorithm.

Parameters:
p - The parameters.

setDefaultFeature

protected void setDefaultFeature()
Sets the value of defaultFeature according to the current value of defaultPrediction.


getParameters

public Learner.Parameters getParameters()
Retrieves the parameters that are set in this learner.

Overrides:
getParameters in class Learner
Returns:
An object containing all the values of the parameters that control the behavior of this learning algorithm.

setBase

public void setBase(Learner base)
Sets baseLearner. This method will not have any effect on the learners that already exist in the network. However, new learners created after this method is executed will be of the same type as the object specified.

Parameters:
base - The new base learning algorithm.

setLabeler

public void setLabeler(Classifier l)
Sets the labeler.

Overrides:
setLabeler in class Learner
Parameters:
l - A labeling classifier.

setLabelLexicon

public void setLabelLexicon(Lexicon l)
Sets the label lexicon.

Overrides:
setLabelLexicon in class Learner
Parameters:
l - A feature lexicon.

learn

public void learn(int[] exampleFeatures,
                  double[] exampleValues,
                  int[] exampleLabels,
                  double[] labelValues)
The training example is multiplexed to the appropriate Learner(s).

Specified by:
learn in class Learner
Parameters:
exampleFeatures - The example's array of feature indices.
exampleValues - The example's array of feature values.
exampleLabels - The example's label(s).
labelValues - The labels' values.

forget

public void forget()
Clears the network.

Overrides:
forget in class Learner

scores

public ScoreSet scores(int[] exampleFeatures,
                       double[] exampleValues)
Produces a set of scores indicating the degree to which each possible discrete classification value is associated with the given example object. These scores are just the scores produced by the multiplexed Learner's scores(Object) method.

Specified by:
scores in class Learner
Parameters:
exampleFeatures - The example's array of feature indices.
exampleValues - The example's array of feature values.
Returns:
A set of scores indicating the degree to which each possible discrete classification value is associated with the given example object.
See Also:
Learner.scores(Object)

discreteValue

public java.lang.String discreteValue(int[] exampleFeatures,
                                      double[] exampleValues)
Returns the value of the discrete feature that would be returned by this classifier.

Overrides:
discreteValue in class Learner
Parameters:
exampleFeatures - The example's array of feature indices.
exampleValues - The example's array of feature values.
Returns:
A single value with the winning linear threshold unit's associated value.

realValue

public double realValue(int[] f,
                        double[] v)
Returns the value of the real feature that would be returned by this classifier.

Overrides:
realValue in class Learner
Parameters:
f - The features array.
v - The values array.
Returns:
The value of the feature produced for the input object.

featureValue

public Feature featureValue(int[] f,
                            double[] v)
Returns the classification of the given example as a single feature instead of a FeatureVector.

Overrides:
featureValue in class Learner
Parameters:
f - The features array.
v - The values array.
Returns:
The classification of the example as a feature.

classify

public FeatureVector classify(int[] exampleFeatures,
                              double[] exampleValues)
This method performs the multiplexing and returns the output of the selected Learner.

Specified by:
classify in class Learner
Parameters:
exampleFeatures - The example's array of feature indices.
exampleValues - The example's array of feature values.
Returns:
The output of the selected Learner.

write

public void write(java.io.PrintStream out)
Writes the algorithm's internal representation as text.

Specified by:
write in class Learner
Parameters:
out - The output stream.

write

public void write(ExceptionlessOutputStream out)
Writes the learned function's internal representation in binary form.

Overrides:
write in class Learner
Parameters:
out - The output stream.

read

public void read(ExceptionlessInputStream in)
Reads the binary representation of a learner with this object's run-time type, overwriting any and all learned or manually specified parameters as well as the label lexicon but without modifying the feature lexicon.

Overrides:
read in class Learner
Parameters:
in - The input stream.

clone

public java.lang.Object clone()
Returns a deep clone of this learning algorithm.

Overrides:
clone in class Learner
Returns:
A shallow clone.