public class BinaryMIRA extends SparsePerceptron
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
LinearThresholdUnit.learningRate will be used. When the weight vector did not make a
mistake, LinearThresholdUnit.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.
| Modifier and Type | Class and Description |
|---|---|
static class |
BinaryMIRA.Parameters
Simply a container for all of
BinaryMIRA's configurable parameters. |
| Modifier and Type | Field and Description |
|---|---|
protected double |
beta
The user supplied learning algorithm parameter; default
defaultBeta. |
static double |
defaultBeta
Default value for
beta. |
static double |
defaultLearningRate
Default value for
LinearThresholdUnit.learningRate. |
static double |
TOLERANCE
Used to decide if two values are nearly equal to each other.
|
allowableValues, bias, defaultInitialWeight, defaultThickness, defaultThreshold, defaultWeightVector, initialWeight, learningRate, negativeThickness, positiveThickness, threshold, weightVectorcandidates, encoding, extractor, labeler, labelLexicon, lcFilePath, lexFilePath, lexicon, lossFlag, predictions, readLexiconOnDemandcontainingPackage, name| Constructor and Description |
|---|
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(String n)
Sets the name of the classifier to the specified value, while the learning rate and beta take
default values.
|
BinaryMIRA(String n,
BinaryMIRA.Parameters p)
Initializing constructor.
|
BinaryMIRA(String n,
double r)
Sets the name of the classifier and learning rate to the specified values, while beta takes
the default value.
|
BinaryMIRA(String n,
double r,
double B)
Sets the name of the classifier, the learning rate and beta to the specified values.
|
BinaryMIRA(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.
|
| Modifier and Type | Method and Description |
|---|---|
double |
computeLearningRate(int[] exampleFeatures,
double[] exampleValues,
double s,
boolean label)
Computes the learning rate for this example.
|
void |
demote(int[] exampleFeatures,
double[] exampleValues,
double rate)
Scales the feature vector produced by the extractor by the learning rate and subtracts it
from the weight vector.
|
double |
getBeta()
Returns the current value of the
beta member variable. |
double |
getLearningRate()
Returns the original value of the
LinearThresholdUnit.learningRate variable. |
Learner.Parameters |
getParameters()
Retrieves the parameters that are set in this learner.
|
void |
promote(int[] exampleFeatures,
double[] exampleValues,
double rate)
Scales the feature vector produced by the extractor by the learning rate and adds it to the
weight vector.
|
void |
read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
Reads the binary representation of a learner with this object's run-time type, overwriting
any and all learned or manually specified parameters as well as the label lexicon but without
modifying the feature lexicon.
|
void |
setBeta(double B)
Sets the
beta member variable to the specified value. |
void |
setParameters(BinaryMIRA.Parameters p)
Sets the values of parameters that control the behavior of this learning algorithm.
|
boolean |
shouldDemote(boolean label,
double s,
double threshold,
double negativeThickness)
Determines if the weights should be promoted.
|
boolean |
shouldPromote(boolean label,
double s,
double threshold,
double positiveThickness)
Determines if the weights should be promoted.
|
void |
write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
Writes the learned function's internal representation in binary form.
|
void |
write(PrintStream out)
Writes the algorithm's internal representation as text.
|
setLearningRateallowableValues, classify, clone, discreteValue, featureValue, forget, getAllowableValues, getBias, getInitialWeight, getNegativeThickness, getPositiveThickness, getThreshold, getWeightVector, initialize, learn, score, score, scores, setInitialWeight, setLabeler, setNegativeThickness, setParameters, setPositiveThickness, setThickness, setThresholdclassify, classify, classify, classify, countFeatures, createPrediction, createPrediction, demandLexicon, discreteValue, discreteValue, doneLearning, doneWithRound, emptyClone, featureValue, featureValue, getCurrentLexicon, getExampleArray, getExampleArray, getExtractor, getLabeler, getLabelLexicon, getLexicon, getLexiconDiscardCounts, getLexiconLocation, getModelLocation, getPrunedLexiconSize, learn, learn, learn, learn, read, readLabelLexicon, readLearner, readLearner, readLearner, readLearner, readLearner, readLearner, readLexicon, readLexicon, readLexiconOnDemand, readLexiconOnDemand, readModel, readModel, readParameters, realValue, realValue, realValue, save, saveLexicon, saveModel, scores, scores, scoresAugmented, setCandidates, setEncoding, setExtractor, setLabelLexicon, setLexicon, setLexiconLocation, setLexiconLocation, setLossFlag, setModelLocation, setModelLocation, setParameters, setReadLexiconOnDemand, unclone, unsetLossFlag, write, writeLexicon, writeModel, writeParametersclassify, discreteValueArray, getCompositeChildren, getInputType, getOutputType, realValueArray, test, toString, valueIndexOfpublic static final double TOLERANCE
public static final double defaultBeta
beta.public static final double defaultLearningRate
LinearThresholdUnit.learningRate.protected double beta
defaultBeta. The learning
rate changes as a function of beta.public BinaryMIRA()
public BinaryMIRA(double r)
r - The desired learning rate value.public BinaryMIRA(double r,
double B)
r - The desired learning rate value.B - the desired beta value.public BinaryMIRA(double r,
double B,
SparseWeightVector v)
r - The desired learning rate.B - The desired beta value.v - The desired weight vector.public BinaryMIRA(BinaryMIRA.Parameters p)
BinaryMIRA.Parameters object.p - The settings of all parameters.public BinaryMIRA(String n)
n - The name of the classifier.public BinaryMIRA(String n, double r)
n - The name of the classifier.r - The desired learning rate.public BinaryMIRA(String n, double r, double B)
n - The name of the classifier.r - The desired learning rate.B - The desired beta value.public BinaryMIRA(String n, double r, double B, SparseWeightVector v)
SparseWeightVector.n - The name of the classifier.r - The desired learning rate.B - The desired beta value.v - The desired weight vector.public BinaryMIRA(String n, BinaryMIRA.Parameters p)
BinaryMIRA.Parameters object.n - The name of the classifier.p - The settings of all parameters.public void setParameters(BinaryMIRA.Parameters p)
p - The parameters.public Learner.Parameters getParameters()
getParameters in class SparsePerceptronpublic double getBeta()
beta member variable.beta variable.public void setBeta(double B)
beta member variable to the specified value.B - The new value for beta.public boolean shouldPromote(boolean label,
double s,
double threshold,
double positiveThickness)
shouldPromote in class LinearThresholdUnitlabel - The label of the example object.s - The score of the example object.threshold - The LTU threshold.positiveThickness - The thickness of the hyperplane on the positive side.true iff the weights should be promoted.public boolean shouldDemote(boolean label,
double s,
double threshold,
double negativeThickness)
shouldDemote in class LinearThresholdUnitlabel - The label of the example object.s - The score of the example object.threshold - The LTU threshold.negativeThickness - The thickness of the hyperplane on the negative side.true iff the weights should be demoted.public void promote(int[] exampleFeatures,
double[] exampleValues,
double rate)
promote in class SparsePerceptronexampleFeatures - The example's array of feature indices.exampleValues - The example's array of feature values.rate - The learning rate at which the weights are updated.public void demote(int[] exampleFeatures,
double[] exampleValues,
double rate)
demote in class SparsePerceptronexampleFeatures - The example's array of feature indices.exampleValues - The example's array of feature values.rate - The learning rate at which the weights are updated.public double computeLearningRate(int[] exampleFeatures,
double[] exampleValues,
double s,
boolean label)
computeLearningRate in class LinearThresholdUnitexampleFeatures - The example's array of feature indices.exampleValues - The example's array of feature values.s - The score for the example object.label - The label.public double getLearningRate()
LinearThresholdUnit.learningRate variable.getLearningRate in class SparsePerceptronLinearThresholdUnit.learningRate variable.public void write(PrintStream out)
LinearThresholdUnit.learningRate, beta,
LinearThresholdUnit.initialWeight, LinearThresholdUnit.threshold,
LinearThresholdUnit.positiveThickness, LinearThresholdUnit.negativeThickness,
and finally LinearThresholdUnit.bias.write in class SparsePerceptronout - The output stream.public void write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
write in class LinearThresholdUnitout - The output stream.public void read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
read in class LinearThresholdUnitin - The input stream.Copyright © 2016. All rights reserved.