LBJ2.learn
Class SparsePerceptron

java.lang.Object
  extended by LBJ2.classify.Classifier
      extended by LBJ2.learn.Learner
          extended by LBJ2.learn.LinearThresholdUnit
              extended by LBJ2.learn.SparsePerceptron
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
BinaryMIRA, SparseAveragedPerceptron

public class SparsePerceptron
extends LinearThresholdUnit

Simple sparse Perceptron implementation. It is assumed that Learner.labeler is a single discrete classifier that produces the same feature for every example object and that the values that feature may take are available through the Classifier.allowableValues() method. The second value returned from Classifier.allowableValues() is treated as "positive", and it is assumed there are exactly 2 allowable values. Assertions will produce error messages if these assumptions do not hold.

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 SparsePerceptron.Parameters
          Simply a container for all of SparsePerceptron's configurable parameters.
 
Field Summary
static double defaultLearningRate
          Default value for learningRate.
protected  double learningRate
          The rate at which weights are updated; default defaultLearningRate.
 
Fields inherited from class LBJ2.learn.LinearThresholdUnit
allowableValues, bias, defaultInitialWeight, defaultThickness, defaultThreshold, defaultWeightVector, initialWeight, negativeThickness, positiveThickness, threshold, weightVector
 
Fields inherited from class LBJ2.learn.Learner
extractor, labeler
 
Fields inherited from class LBJ2.classify.Classifier
containingPackage, name
 
Constructor Summary
SparsePerceptron()
          The learning rate and threshold take default values, while the name of the classifier gets the empty string.
SparsePerceptron(double r)
          Sets the learning rate to the specified value, and the threshold takes the default, while the name of the classifier gets the empty string.
SparsePerceptron(double r, double t)
          Sets the learning rate and threshold to the specified values, while the name of the classifier gets the empty string.
SparsePerceptron(double r, double t, double pt)
          Use this constructor to fit a thick separator, where both the positive and negative sides of the hyperplane will be given the specified thickness, while the name of the classifier gets the empty string.
SparsePerceptron(double r, double t, double pt, double nt)
          Use this constructor to fit a thick separator, where the positive and negative sides of the hyperplane will be given the specified separate thicknesses, while the name of the classifier gets the empty string.
SparsePerceptron(double r, double t, double pt, double nt, SparseWeightVector v)
          Use this constructor to specify an alternative subclass of SparseWeightVector, while the name of the classifier gets the empty string.
SparsePerceptron(SparsePerceptron.Parameters p)
          Initializing constructor.
SparsePerceptron(java.lang.String n)
          The learning rate and threshold take default values.
SparsePerceptron(java.lang.String n, double r)
          Sets the learning rate to the specified value, and the threshold takes the default.
SparsePerceptron(java.lang.String n, double r, double t)
          Sets the learning rate and threshold to the specified values.
SparsePerceptron(java.lang.String n, double r, double t, double pt)
          Use this constructor to fit a thick separator, where both the positive and negative sides of the hyperplane will be given the specified thickness.
SparsePerceptron(java.lang.String n, double r, double t, double pt, double nt)
          Use this constructor to fit a thick separator, where the positive and negative sides of the hyperplane will be given the specified separate thicknesses.
SparsePerceptron(java.lang.String n, double r, double t, double pt, double nt, SparseWeightVector v)
          Use this constructor to specify an alternative subclass of SparseWeightVector.
SparsePerceptron(java.lang.String n, SparsePerceptron.Parameters p)
          Initializing constructor.
 
Method Summary
 java.lang.Object clone()
          Returns a deep clone of this learning algorithm.
 void demote(java.lang.Object example)
          Scales the feature vector produced by the extractor by the learning rate and subtracts it from the weight vector.
 double getLearningRate()
          Returns the current value of the learningRate variable.
 void promote(java.lang.Object example)
          Scales the feature vector produced by the extractor by the learning rate and adds it to the weight vector.
 void setLearningRate(double r)
          Sets the learningRate member variable to the specified value.
 void write(java.io.PrintStream out)
          Writes the algorithm's internal representation as text.
 
Methods inherited from class LBJ2.learn.LinearThresholdUnit
allowableValues, classify, forget, getInitialWeight, getNegativeThickness, getPositiveThickness, getThreshold, learn, score, scores, setInitialWeight, setLabeler, setNegativeThickness, setPositiveThickness, setThickness, setThreshold
 
Methods inherited from class LBJ2.learn.Learner
doneLearning, getExtractor, getLabeler, learn, save, setExtractor
 
Methods inherited from class LBJ2.classify.Classifier
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

defaultLearningRate

public static final double defaultLearningRate
Default value for learningRate.

See Also:
Constant Field Values

learningRate

protected double learningRate
The rate at which weights are updated; default defaultLearningRate.

Constructor Detail

SparsePerceptron

public SparsePerceptron()
The learning rate and threshold take default values, while the name of the classifier gets the empty string.


SparsePerceptron

public SparsePerceptron(double r)
Sets the learning rate to the specified value, and the threshold takes the default, while the name of the classifier gets the empty string.

Parameters:
r - The desired learning rate value.

SparsePerceptron

public SparsePerceptron(double r,
                        double t)
Sets the learning rate and threshold to the specified values, while the name of the classifier gets the empty string.

Parameters:
r - The desired learning rate value.
t - The desired threshold value.

SparsePerceptron

public SparsePerceptron(double r,
                        double t,
                        double pt)
Use this constructor to fit a thick separator, where both the positive and negative sides of the hyperplane will be given the specified thickness, while the name of the classifier gets the empty string.

Parameters:
r - The desired learning rate value.
t - The desired threshold value.
pt - The desired thickness.

SparsePerceptron

public SparsePerceptron(double r,
                        double t,
                        double pt,
                        double nt)
Use this constructor to fit a thick separator, where the positive and negative sides of the hyperplane will be given the specified separate thicknesses, while the name of the classifier gets the empty string.

Parameters:
r - The desired learning rate value.
t - The desired threshold value.
pt - The desired positive thickness.
nt - The desired negative thickness.

SparsePerceptron

public SparsePerceptron(double r,
                        double t,
                        double pt,
                        double nt,
                        SparseWeightVector v)
Use this constructor to specify an alternative subclass of SparseWeightVector, while the name of the classifier gets the empty string.

Parameters:
r - The desired learning rate value.
t - The desired threshold value.
pt - The desired positive thickness.
nt - The desired negative thickness.
v - An empty sparse weight vector.

SparsePerceptron

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

Parameters:
p - The settings of all parameters.

SparsePerceptron

public SparsePerceptron(java.lang.String n)
The learning rate and threshold take default values.

Parameters:
n - The name of the classifier.

SparsePerceptron

public SparsePerceptron(java.lang.String n,
                        double r)
Sets the learning rate to the specified value, and the threshold takes the default.

Parameters:
n - The name of the classifier.
r - The desired learning rate value.

SparsePerceptron

public SparsePerceptron(java.lang.String n,
                        double r,
                        double t)
Sets the learning rate and threshold to the specified values.

Parameters:
n - The name of the classifier.
r - The desired learning rate value.
t - The desired threshold value.

SparsePerceptron

public SparsePerceptron(java.lang.String n,
                        double r,
                        double t,
                        double pt)
Use this constructor to fit a thick separator, where both the positive and negative sides of the hyperplane will be given the specified thickness.

Parameters:
n - The name of the classifier.
r - The desired learning rate value.
t - The desired threshold value.
pt - The desired thickness.

SparsePerceptron

public SparsePerceptron(java.lang.String n,
                        double r,
                        double t,
                        double pt,
                        double nt)
Use this constructor to fit a thick separator, where the positive and negative sides of the hyperplane will be given the specified separate thicknesses.

Parameters:
n - The name of the classifier.
r - The desired learning rate value.
t - The desired threshold value.
pt - The desired positive thickness.
nt - The desired negative thickness.

SparsePerceptron

public SparsePerceptron(java.lang.String n,
                        double r,
                        double t,
                        double pt,
                        double nt,
                        SparseWeightVector v)
Use this constructor to specify an alternative subclass of SparseWeightVector.

Parameters:
n - The name of the classifier.
r - The desired learning rate value.
t - The desired threshold value.
pt - The desired positive thickness.
nt - The desired negative thickness.
v - An empty sparse weight vector.

SparsePerceptron

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

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

getLearningRate

public double getLearningRate()
Returns the current value of the learningRate variable.

Returns:
The value of the learningRate variable.

setLearningRate

public void setLearningRate(double r)
Sets the learningRate member variable to the specified value.

Parameters:
r - The new value for learningRate.

promote

public void promote(java.lang.Object example)
Scales the feature vector produced by the extractor by the learning rate and adds it to the weight vector.

Specified by:
promote in class LinearThresholdUnit
Parameters:
example - The example object.

demote

public void demote(java.lang.Object example)
Scales the feature vector produced by the extractor by the learning rate and subtracts it from the weight vector.

Specified by:
demote in class LinearThresholdUnit
Parameters:
example - The example object.

write

public void write(java.io.PrintStream out)
Writes the algorithm's internal representation as text. In the first line of output, the name of the classifier is printed, followed by learningRate, LinearThresholdUnit.initialWeight, LinearThresholdUnit.threshold, LinearThresholdUnit.positiveThickness, LinearThresholdUnit.negativeThickness, and finally LinearThresholdUnit.bias.

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.