LBJ2.learn
Class BinaryMIRA

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

public class BinaryMIRA
extends SparsePerceptron

The Binary MIRA learning algorithm implementation. This algorithm operates very similarly to SparsePerceptron with a thick separator, except the learning rate is a function of each training example's margin. When the weight vector has made a mistake, the full SparsePerceptron.learningRate will be used. When the weight vector did not make a mistake, SparsePerceptron.learningRate is multiplied by the following value before the update takes place.

(beta/2 - y(w*x)) / ||x||2

In the expression above, w is the weight vector, y represents the label of the example vector x, * stands for inner product, and beta is a user supplied parameter. If this expression turns out to be non-positive (i.e., if y(w*x) >= beta/2), no update is made for that example.

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 BinaryMIRA.Parameters
          Simply a container for all of BinaryMIRA's configurable parameters.
 
Field Summary
protected  double beta
          The user supplied learning algorithm parameter; default defaultBeta.
static double defaultBeta
          Default value for beta.
protected  double saveLearningRate
          A copy of the original learning rate value is stored here so that SparsePerceptron.learningRate can be modified without losing it.
static double TOLERANCE
          Used to decide if two values are nearly equal to each other.
 
Fields inherited from class LBJ2.learn.SparsePerceptron
defaultLearningRate, learningRate
 
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
BinaryMIRA()
          The learning rate and beta take default values while the name of the classifier takes the empty string.
BinaryMIRA(BinaryMIRA.Parameters p)
          Initializing constructor.
BinaryMIRA(double r)
          Sets the learning rate to the specified value, and beta to the default, while the name of the classifier takes the empty string.
BinaryMIRA(double r, double B)
          Sets the learning rate and beta to the specified values, while the name of the classifier takes the empty string.
BinaryMIRA(double r, double B, SparseWeightVector v)
          Sets the learning rate, beta and the weight vector to the specified values.
BinaryMIRA(java.lang.String n)
          Sets the name of the classifier to the specified value, while the learning rate and beta take default values.
BinaryMIRA(java.lang.String n, BinaryMIRA.Parameters p)
          Initializing constructor.
BinaryMIRA(java.lang.String n, double r)
          Sets the name of the classifier and learning rate to the specified values, while beta takes the default value.
BinaryMIRA(java.lang.String n, double r, double B)
          Sets the name of the classifier, the learning rate and beta to the specified values.
BinaryMIRA(java.lang.String n, double r, double B, SparseWeightVector v)
          Sets the name of the classifier, the learning rate, beta and the weight vector to the specified values.
 
Method Summary
 double getBeta()
          Returns the current value of the beta member variable.
 void learn(java.lang.Object example)
          Evaluates the example object with the LinearThresholdUnit.score(Object), updates the learning rate, and finally updates LinearThresholdUnit.weightVector as described above.
private static boolean nearlyEqualTo(double a, double b)
          Determines if a is nearly equal to b based on the value of the TOLERANCE member variable.
 void setBeta(double B)
          Sets the beta member variable to the specified value.
private  void updateLearningRate(java.lang.Object example, double s, boolean label)
          Updates the SparsePerceptron.learningRate member variable.
 void write(java.io.PrintStream out)
          Writes the algorithm's internal representation as text.
 
Methods inherited from class LBJ2.learn.SparsePerceptron
clone, demote, getLearningRate, promote, setLearningRate
 
Methods inherited from class LBJ2.learn.LinearThresholdUnit
allowableValues, classify, forget, getInitialWeight, getNegativeThickness, getPositiveThickness, getThreshold, 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

TOLERANCE

public static final double TOLERANCE
Used to decide if two values are nearly equal to each other.

See Also:
nearlyEqualTo(double,double), Constant Field Values

defaultBeta

public static final double defaultBeta
Default value for beta.

See Also:
Constant Field Values

beta

protected double beta
The user supplied learning algorithm parameter; default defaultBeta. The learning rate changes as a function of beta.


saveLearningRate

protected double saveLearningRate
A copy of the original learning rate value is stored here so that SparsePerceptron.learningRate can be modified without losing it.

Constructor Detail

BinaryMIRA

public BinaryMIRA()
The learning rate and beta take default values while the name of the classifier takes the empty string.


BinaryMIRA

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

Parameters:
r - The desired learning rate value.

BinaryMIRA

public BinaryMIRA(double r,
                  double B)
Sets the learning rate and beta to the specified values, while the name of the classifier takes the empty string.

Parameters:
r - The desired learning rate value.
B - the desired beta value.

BinaryMIRA

public BinaryMIRA(double r,
                  double B,
                  SparseWeightVector v)
Sets the learning rate, beta and the weight vector to the specified values.

Parameters:
r - The desired learning rate.
B - The desired beta value.
v - The desired weight vector.

BinaryMIRA

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

Parameters:
p - The settings of all parameters.

BinaryMIRA

public BinaryMIRA(java.lang.String n)
Sets the name of the classifier to the specified value, while the learning rate and beta take default values.

Parameters:
n - The name of the classifier.

BinaryMIRA

public BinaryMIRA(java.lang.String n,
                  double r)
Sets the name of the classifier and learning rate to the specified values, while beta takes the default value.

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

BinaryMIRA

public BinaryMIRA(java.lang.String n,
                  double r,
                  double B)
Sets the name of the classifier, the learning rate and beta to the specified values.

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

BinaryMIRA

public BinaryMIRA(java.lang.String n,
                  double r,
                  double B,
                  SparseWeightVector v)
Sets the name of the classifier, the learning rate, beta and the weight vector to the specified values. Use this constructor to specify an alternative subclass of SparseWeightVector.

Parameters:
n - The name of the classifier.
r - The desired learning rate.
B - The desired beta value.
v - The desired weight vector.

BinaryMIRA

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

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

getBeta

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

Returns:
The value of the beta variable.

setBeta

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

Parameters:
B - The new value for beta.

learn

public void learn(java.lang.Object example)
Evaluates the example object with the LinearThresholdUnit.score(Object), updates the learning rate, and finally updates LinearThresholdUnit.weightVector as described above.

Overrides:
learn in class LinearThresholdUnit
Parameters:
example - The example object

nearlyEqualTo

private static boolean nearlyEqualTo(double a,
                                     double b)
Determines if a is nearly equal to b based on the value of the TOLERANCE member variable.

Parameters:
a - The first value
b - The second value
Returns:
True if they are nearly equal, false otherwise.

updateLearningRate

private void updateLearningRate(java.lang.Object example,
                                double s,
                                boolean label)
Updates the SparsePerceptron.learningRate member variable.

Parameters:
example - The example object
s - The score for the example object
label - The label

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 SparsePerceptron.learningRate, beta, LinearThresholdUnit.initialWeight, LinearThresholdUnit.threshold, LinearThresholdUnit.positiveThickness, LinearThresholdUnit.negativeThickness, and finally LinearThresholdUnit.bias.

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