LBJ2.learn
Class SparseWinnow

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

public class SparseWinnow
extends LinearThresholdUnit

Simple sparse Winnow implementation. It is assumed that Learner.labeler is a single discrete classifier whose returned feature values 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 SparseWinnow.Parameters
          Simply a container for all of SparseWinnow's configurable parameters.
 
Field Summary
protected  double alpha
          The rate at which weights are promoted; default defaultAlpha.
protected  double beta
          The rate at which weights are demoted; default equal to 1 / alpha.
static double defaultAlpha
          Default for alpha.
static double defaultInitialWeight
          Default for LinearThresholdUnit.initialWeight.
static double defaultThreshold
          Default for LinearThresholdUnit.threshold.
 
Fields inherited from class LBJ2.learn.LinearThresholdUnit
allowableValues, bias, defaultThickness, 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
SparseWinnow()
          alpha, beta, and LinearThresholdUnit.threshold take default values, while the name of the classifier gets the empty string.
SparseWinnow(double a)
          Sets alpha to the specified value, beta to 1 / alpha, and the LinearThresholdUnit.threshold takes the default, while the name of the classifier gets the empty string.
SparseWinnow(double a, double b)
          Sets alpha and beta to the specified values, and the LinearThresholdUnit.threshold takes the default, while the name of the classifier gets the empty string.
SparseWinnow(double a, double b, double t)
          Sets alpha, beta, and LinearThresholdUnit.threshold to the specified values, while the name of the classifier gets the empty string.
SparseWinnow(double a, double b, 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.
SparseWinnow(double a, double b, 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.
SparseWinnow(double a, double b, 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.
SparseWinnow(SparseWinnow.Parameters p)
          Initializing constructor.
SparseWinnow(java.lang.String n)
          alpha, beta, and LinearThresholdUnit.threshold take default values.
SparseWinnow(java.lang.String n, double a)
          Sets alpha to the specified value, beta to 1 / alpha, and the LinearThresholdUnit.threshold takes the default.
SparseWinnow(java.lang.String n, double a, double b)
          Sets alpha and beta to the specified values, and the LinearThresholdUnit.threshold takes the default.
SparseWinnow(java.lang.String n, double a, double b, double t)
          Sets alpha, beta, and LinearThresholdUnit.threshold to the specified values.
SparseWinnow(java.lang.String n, double a, double b, 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.
SparseWinnow(java.lang.String n, double a, double b, 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.
SparseWinnow(java.lang.String n, double a, double b, double t, double pt, double nt, SparseWeightVector v)
          Use this constructor to specify an alternative subclass of SparseWeightVector.
SparseWinnow(java.lang.String n, SparseWinnow.Parameters p)
          Initializing constructor.
 
Method Summary
 java.lang.Object clone()
          Returns a deep clone of this learning algorithm.
 void demote(java.lang.Object example)
          Demotion is simply w_i *= betax_i.
 double getAlpha()
          Returns the current value of the alpha variable.
 double getBeta()
          Returns the current value of the beta variable.
 void promote(java.lang.Object example)
          Promotion is simply w_i *= alphax_i.
 void setAlpha(double t)
          Sets the alpha member variable to the specified value.
 void setBeta(double t)
          Sets the beta member variable to the specified value.
 void update(java.lang.Object example, double base)
          This method performs an update w_i *= basex_i, initalizing weights in the weight vector as needed.
 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

defaultAlpha

public static final double defaultAlpha
Default for alpha.

See Also:
Constant Field Values

defaultThreshold

public static final double defaultThreshold
Default for LinearThresholdUnit.threshold.

See Also:
Constant Field Values

defaultInitialWeight

public static final double defaultInitialWeight
Default for LinearThresholdUnit.initialWeight.

See Also:
Constant Field Values

alpha

protected double alpha
The rate at which weights are promoted; default defaultAlpha.


beta

protected double beta
The rate at which weights are demoted; default equal to 1 / alpha.

Constructor Detail

SparseWinnow

public SparseWinnow()
alpha, beta, and LinearThresholdUnit.threshold take default values, while the name of the classifier gets the empty string.


SparseWinnow

public SparseWinnow(double a)
Sets alpha to the specified value, beta to 1 / alpha, and the LinearThresholdUnit.threshold takes the default, while the name of the classifier gets the empty string.

Parameters:
a - The desired value of the promotion parameter.

SparseWinnow

public SparseWinnow(double a,
                    double b)
Sets alpha and beta to the specified values, and the LinearThresholdUnit.threshold takes the default, while the name of the classifier gets the empty string.

Parameters:
a - The desired value of the promotion parameter.
b - The desired value of the demotion parameter.

SparseWinnow

public SparseWinnow(double a,
                    double b,
                    double t)
Sets alpha, beta, and LinearThresholdUnit.threshold to the specified values, while the name of the classifier gets the empty string.

Parameters:
a - The desired value of the promotion parameter.
b - The desired value of the demotion parameter.
t - The desired threshold value.

SparseWinnow

public SparseWinnow(double a,
                    double b,
                    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:
a - The desired value of the promotion parameter.
b - The desired value of the demotion parameter.
t - The desired threshold value.
pt - The desired positive thickness.

SparseWinnow

public SparseWinnow(double a,
                    double b,
                    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:
a - The desired value of the promotion parameter.
b - The desired value of the demotion parameter.
t - The desired threshold value.
pt - The desired positive thickness.
nt - The desired negative thickness.

SparseWinnow

public SparseWinnow(double a,
                    double b,
                    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:
a - The desired value of the promotion parameter.
b - The desired value of the demotion parameter.
t - The desired threshold value.
pt - The desired positive thickness.
nt - The desired negative thickness.
v - An empty sparse weight vector.

SparseWinnow

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

Parameters:
p - The settings of all parameters.

SparseWinnow

public SparseWinnow(java.lang.String n)
alpha, beta, and LinearThresholdUnit.threshold take default values.

Parameters:
n - The name of the classifier.

SparseWinnow

public SparseWinnow(java.lang.String n,
                    double a)
Sets alpha to the specified value, beta to 1 / alpha, and the LinearThresholdUnit.threshold takes the default.

Parameters:
n - The name of the classifier.
a - The desired value of the promotion parameter.

SparseWinnow

public SparseWinnow(java.lang.String n,
                    double a,
                    double b)
Sets alpha and beta to the specified values, and the LinearThresholdUnit.threshold takes the default.

Parameters:
n - The name of the classifier.
a - The desired value of the promotion parameter.
b - The desired value of the demotion parameter.

SparseWinnow

public SparseWinnow(java.lang.String n,
                    double a,
                    double b,
                    double t)
Sets alpha, beta, and LinearThresholdUnit.threshold to the specified values.

Parameters:
n - The name of the classifier.
a - The desired value of the promotion parameter.
b - The desired value of the demotion parameter.
t - The desired threshold value.

SparseWinnow

public SparseWinnow(java.lang.String n,
                    double a,
                    double b,
                    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.
a - The desired value of the promotion parameter.
b - The desired value of the demotion parameter.
t - The desired threshold value.
pt - The desired positive thickness.

SparseWinnow

public SparseWinnow(java.lang.String n,
                    double a,
                    double b,
                    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.
a - The desired value of the promotion parameter.
b - The desired value of the demotion parameter.
t - The desired threshold value.
pt - The desired positive thickness.
nt - The desired negative thickness.

SparseWinnow

public SparseWinnow(java.lang.String n,
                    double a,
                    double b,
                    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.
a - The desired value of the promotion parameter.
b - The desired value of the demotion parameter.
t - The desired threshold value.
pt - The desired positive thickness.
nt - The desired negative thickness.
v - An empty sparse weight vector.

SparseWinnow

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

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

getAlpha

public double getAlpha()
Returns the current value of the alpha variable.

Returns:
The value of the alpha variable.

setAlpha

public void setAlpha(double t)
Sets the alpha member variable to the specified value.

Parameters:
t - The new value for alpha.

getBeta

public double getBeta()
Returns the current value of the beta variable.

Returns:
The value of the beta variable.

setBeta

public void setBeta(double t)
Sets the beta member variable to the specified value.

Parameters:
t - The new value for beta.

promote

public void promote(java.lang.Object example)
Promotion is simply w_i *= alphax_i.

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

demote

public void demote(java.lang.Object example)
Demotion is simply w_i *= betax_i.

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

update

public void update(java.lang.Object example,
                   double base)
This method performs an update w_i *= basex_i, initalizing weights in the weight vector as needed.

Parameters:
example - The example object.
base - As described above.

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 alpha, beta, 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.