LBJ2.learn
Class SparseNetworkLearner

java.lang.Object
  extended by LBJ2.classify.Classifier
      extended by LBJ2.learn.Learner
          extended by LBJ2.learn.SparseNetworkLearner
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
MultiLabelLearner

public class SparseNetworkLearner
extends Learner

A SparseNetworkLearner uses multiple LinearThresholdUnits to make a multi-class classification. Any LinearThresholdUnit may be used, so long as it implements its clone() method and a public constructor that takes no arguments.

It is assumed that a single discrete label feature will be produced in association with each example object. A feature taking one of the values observed in that label feature will be produced by the learned classifier.

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 SparseNetworkLearner.Parameters
          Simply a container for all of SparseNetworkLearner's configurable parameters.
 
Field Summary
protected  LinearThresholdUnit baseLTU
          The underlying algorithm used to learn each class separately as a binary classifier; default defaultBaseLTU.
static LinearThresholdUnit defaultBaseLTU
          Default for baseLTU.
protected  java.util.HashMap network
          A map from labels to the linear threshold unit used to learn each label.
 
Fields inherited from class LBJ2.learn.Learner
extractor, labeler
 
Fields inherited from class LBJ2.classify.Classifier
containingPackage, name
 
Constructor Summary
SparseNetworkLearner()
          Instantiates this multi-class learner with the default learning algorithm: defaultBaseLTU.
SparseNetworkLearner(LinearThresholdUnit ltu)
          Instantiates this multi-class learner using the specified algorithm to learn each class separately as a binary classifier.
SparseNetworkLearner(SparseNetworkLearner.Parameters p)
          Initializing constructor.
SparseNetworkLearner(java.lang.String n)
          Instantiates this multi-class learner with the default learning algorithm: defaultBaseLTU.
SparseNetworkLearner(java.lang.String n, LinearThresholdUnit ltu)
          Instantiates this multi-class learner using the specified algorithm to learn each class separately as a binary classifier.
SparseNetworkLearner(java.lang.String n, SparseNetworkLearner.Parameters p)
          Initializing constructor.
 
Method Summary
 FeatureVector classify(java.lang.Object example)
          This implementation uses a winner-take-all comparison of the outputs from the individual linear threshold units' score methods.
 java.lang.Object clone()
          Returns a deep clone of this learning algorithm.
 void doneLearning()
          Simply calls doneLearning() on every LTU in the network.
 void forget()
          Clears the network.
 void learn(java.lang.Object example)
          Each example is treated as a positive example for the linear threshold unit associated with the label's value that is active for the example and as a negative example for all other linear threshold units in the network.
 ScoreSet scores(java.lang.Object example)
          Produces a set of scores indicating the degree to which each possible discrete classification value is associated with the given example object.
 ScoreSet scores(java.lang.Object example, java.util.Collection candidates)
          Returns scores for only those labels in the given collection.
 void setExtractor(Classifier e)
          Sets the extractor.
 void setLabeler(Classifier l)
          Sets the labeler.
 void setLTU(LinearThresholdUnit ltu)
          Sets the baseLTU variable.
 java.lang.String valueOf(java.lang.Object example, java.util.Collection candidates)
          Using this method, the winner-take-all competition is narrowed to involve only those labels contained in the specified list.
 void write(java.io.PrintStream out)
          Writes the algorithm's internal representation as text.
 
Methods inherited from class LBJ2.learn.Learner
getExtractor, getLabeler, learn, save
 
Methods inherited from class LBJ2.classify.Classifier
allowableValues, binaryRead, binaryRead, binaryRead, binaryRead, binaryWrite, binaryWrite, classify, discreteValue, discreteValueArray, getCompositeChildren, getInputType, getOutputType, realValue, realValueArray, test, toString, valueIndexOf
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultBaseLTU

public static final LinearThresholdUnit defaultBaseLTU
Default for baseLTU.


baseLTU

protected LinearThresholdUnit baseLTU
The underlying algorithm used to learn each class separately as a binary classifier; default defaultBaseLTU.


network

protected java.util.HashMap network
A map from labels to the linear threshold unit used to learn each label.

Constructor Detail

SparseNetworkLearner

public SparseNetworkLearner()
Instantiates this multi-class learner with the default learning algorithm: defaultBaseLTU.


SparseNetworkLearner

public SparseNetworkLearner(LinearThresholdUnit ltu)
Instantiates this multi-class learner using the specified algorithm to learn each class separately as a binary classifier. This constructor will normally only be called by the compiler.

Parameters:
ltu - The linear threshold unit used to learn binary classifiers.

SparseNetworkLearner

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

Parameters:
p - The settings of all parameters.

SparseNetworkLearner

public SparseNetworkLearner(java.lang.String n)
Instantiates this multi-class learner with the default learning algorithm: defaultBaseLTU.

Parameters:
n - The name of the classifier.

SparseNetworkLearner

public SparseNetworkLearner(java.lang.String n,
                            LinearThresholdUnit ltu)
Instantiates this multi-class learner using the specified algorithm to learn each class separately as a binary classifier.

Parameters:
n - The name of the classifier.
ltu - The linear threshold unit used to learn binary classifiers.

SparseNetworkLearner

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

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

setLTU

public void setLTU(LinearThresholdUnit ltu)
Sets the baseLTU variable. This method will not have any effect on the LTUs that already exist in the network. However, new LTUs created after this method is executed will be of the same type as the object specified.

Parameters:
ltu - The new LTU.

setLabeler

public void setLabeler(Classifier l)
Sets the labeler.

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

setExtractor

public void setExtractor(Classifier e)
Sets the extractor.

Overrides:
setExtractor in class Learner
Parameters:
e - A feature extracting classifier.

learn

public void learn(java.lang.Object example)
Each example is treated as a positive example for the linear threshold unit associated with the label's value that is active for the example and as a negative example for all other linear threshold units in the network.

Specified by:
learn in class Learner
Parameters:
example - The example object.

doneLearning

public void doneLearning()
Simply calls doneLearning() on every LTU in the network.

Overrides:
doneLearning in class Learner

forget

public void forget()
Clears the network.

Specified by:
forget in class Learner

scores

public ScoreSet scores(java.lang.Object example)
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 of each LTU's positive classification as produced by LinearThresholdUnit.scores(Object).

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

classify

public FeatureVector classify(java.lang.Object example)
This implementation uses a winner-take-all comparison of the outputs from the individual linear threshold units' score methods.

Specified by:
classify in class Classifier
Parameters:
example - The example object.
Returns:
A single feature with the winning linear threshold unit's associated value.

valueOf

public java.lang.String valueOf(java.lang.Object example,
                                java.util.Collection candidates)
Using this method, the winner-take-all competition is narrowed to involve only those labels contained in the specified list. The list must contain only Strings.

Parameters:
example - The example object.
candidates - A list of the only labels the example may take.
Returns:
The label chosen by this classifier or null if the network did not contain any of the specified labels.

scores

public ScoreSet scores(java.lang.Object example,
                       java.util.Collection candidates)
Returns scores for only those labels in the given collection. If the given collection is empty, scores for all labels will be returned. If there is no LinearThresholdUnit associated with a given label from the collection, that label's score in the returned ScoreSet will be set to Double.NEGATIVE_INFINITY.

Parameters:
example - The example object.
candidates - A list of the only labels the example may take.
Returns:
Scores for only those labels in candidates.

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.

clone

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

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