LBJ2.learn
Class StochasticGradientDescent

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

public class StochasticGradientDescent
extends Learner

Gradient descent is a batch learning algorithm for function approximation in which the learner tries to follow the gradient of the error function to the solution of minimal error. This implementation is a stochastic approximation to gradient descent in which the approximated function is assumed to have linear form.

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 StochasticGradientDescent.Parameters
          Simply a container for all of StochasticGradientDescent's configurable parameters.
 
Field Summary
protected  double bias
          The bias is stored here rather than as an element of the weight vector.
static double defaultLearningRate
          Default value for learningRate.
static SparseWeightVector defaultWeightVector
          Default for weightVector.
protected  double learningRate
          The rate at which weights are updated; default defaultLearningRate.
protected  SparseWeightVector weightVector
          The hypothesis vector; default defaultWeightVector.
 
Fields inherited from class LBJ2.learn.Learner
extractor, labeler
 
Fields inherited from class LBJ2.classify.Classifier
containingPackage, name
 
Constructor Summary
StochasticGradientDescent()
          The learning rate takes the default value, while the name of the classifier gets the empty string.
StochasticGradientDescent(double r)
          Sets the learning rate to the specified value, while the name of the classifier gets the empty string.
StochasticGradientDescent(StochasticGradientDescent.Parameters p)
          Initializing constructor.
StochasticGradientDescent(java.lang.String n)
          The learning rate takes the default value.
StochasticGradientDescent(java.lang.String n, double r)
          Use this constructor to specify an alternative subclass of SparseWeightVector.
StochasticGradientDescent(java.lang.String n, StochasticGradientDescent.Parameters p)
          Initializing constructor.
 
Method Summary
 FeatureVector classify(java.lang.Object example)
          Simply computes the dot product of the weight vector and the feature vector extracted from the example object.
 java.lang.Object clone()
          Returns a deep clone of this learning algorithm.
 void forget()
          Resets the weight vector to all zeros.
 double getLearningRate()
          Returns the current value of the learningRate variable.
 java.lang.String getOutputType()
          Returns a string describing the output feature type of this classifier.
 void learn(java.lang.Object example)
          Trains the learning algorithm given an object as an example.
 ScoreSet scores(java.lang.Object example)
          Since this algorithm returns a real feature, it does not return scores.
 void setLearningRate(double t)
          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.Learner
doneLearning, getExtractor, getLabeler, learn, save, setExtractor, setLabeler
 
Methods inherited from class LBJ2.classify.Classifier
allowableValues, binaryRead, binaryRead, binaryRead, binaryRead, binaryWrite, binaryWrite, classify, discreteValue, discreteValueArray, getCompositeChildren, getInputType, 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

defaultWeightVector

public static final SparseWeightVector defaultWeightVector
Default for weightVector.


weightVector

protected SparseWeightVector weightVector
The hypothesis vector; default defaultWeightVector.


bias

protected double bias
The bias is stored here rather than as an element of the weight vector.


learningRate

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

Constructor Detail

StochasticGradientDescent

public StochasticGradientDescent()
The learning rate takes the default value, while the name of the classifier gets the empty string.


StochasticGradientDescent

public StochasticGradientDescent(double r)
Sets the learning rate to the specified value, while the name of the classifier gets the empty string.

Parameters:
r - The desired learning rate value.

StochasticGradientDescent

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

Parameters:
p - The settings of all parameters.

StochasticGradientDescent

public StochasticGradientDescent(java.lang.String n)
The learning rate takes the default value.

Parameters:
n - The name of the classifier.

StochasticGradientDescent

public StochasticGradientDescent(java.lang.String n,
                                 double r)
Use this constructor to specify an alternative subclass of SparseWeightVector.

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

StochasticGradientDescent

public StochasticGradientDescent(java.lang.String n,
                                 StochasticGradientDescent.Parameters p)
Initializing constructor. Sets all member variables to their associated settings in the StochasticGradientDescent.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 t)
Sets the learningRate member variable to the specified value.

Parameters:
t - The new value for learningRate.

forget

public void forget()
Resets the weight vector to all zeros.

Specified by:
forget in class Learner

getOutputType

public java.lang.String getOutputType()
Returns a string describing the output feature type of this classifier.

Overrides:
getOutputType in class Classifier
Returns:
"real"

learn

public void learn(java.lang.Object example)
Trains the learning algorithm given an object as an example.

Specified by:
learn in class Learner
Parameters:
example - An example of the desired learned classifier's behavior.

scores

public ScoreSet scores(java.lang.Object example)
Since this algorithm returns a real feature, it does not return scores.

Specified by:
scores in class Learner
Parameters:
example - The object to make decisions about.
Returns:
null

classify

public FeatureVector classify(java.lang.Object example)
Simply computes the dot product of the weight vector and the feature vector extracted from the example object.

Specified by:
classify in class Classifier
Parameters:
example - The example to be evaluated.
Returns:
The computed feature (in a vector).

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 and 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.