public class PassiveAggressive extends LinearThresholdUnit
SparsePerceptron
with a thick separator, except the learning rate is a function of
each training example's margin. LinearThresholdUnit.learningRate
is defined for each
example as the following value.
(1 - 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. If this expression turns out to be non-positive (i.e., if y(w*x) >= 1), 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. Note that this learner will not actually use
any user-supplied value for LinearThresholdUnit.Parameters.learningRate
as this is
computed automatically.
Modifier and Type | Class and Description |
---|---|
static class |
PassiveAggressive.Parameters
Simply a container for all of
PassiveAggressive 's configurable parameters. |
allowableValues, bias, defaultInitialWeight, defaultLearningRate, defaultThickness, defaultThreshold, defaultWeightVector, initialWeight, learningRate, negativeThickness, positiveThickness, threshold, weightVector
candidates, encoding, extractor, labeler, labelLexicon, lcFilePath, lexFilePath, lexicon, lossFlag, predictions, readLexiconOnDemand
containingPackage, name
Constructor and Description |
---|
PassiveAggressive()
The learning rate and threshold take default values, while the name of the classifier gets
the empty string.
|
PassiveAggressive(double t)
Sets the learning rate and threshold to the specified values, while the name of the
classifier gets the empty string.
|
PassiveAggressive(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.
|
PassiveAggressive(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.
|
PassiveAggressive(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. |
PassiveAggressive(PassiveAggressive.Parameters p)
Initializing constructor.
|
PassiveAggressive(String n)
Sets the learning rate to the specified value, and the threshold takes the default.
|
PassiveAggressive(String n,
double t)
Sets the learning rate and threshold to the specified values.
|
PassiveAggressive(String n,
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.
|
PassiveAggressive(String n,
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.
|
PassiveAggressive(String n,
double t,
double pt,
double nt,
SparseWeightVector v)
Use this constructor to specify an alternative subclass of
SparseWeightVector . |
PassiveAggressive(String n,
PassiveAggressive.Parameters p)
Initializing constructor.
|
Modifier and Type | Method and Description |
---|---|
double |
computeLearningRate(int[] exampleFeatures,
double[] exampleValues,
double s,
boolean label)
Computes the value of 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.
|
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 |
write(PrintStream out)
Writes the algorithm's internal representation as text.
|
allowableValues, classify, clone, discreteValue, featureValue, forget, getAllowableValues, getBias, getInitialWeight, getNegativeThickness, getPositiveThickness, getThreshold, getWeightVector, initialize, learn, read, score, score, scores, setInitialWeight, setLabeler, setNegativeThickness, setParameters, setPositiveThickness, setThickness, setThreshold, shouldDemote, shouldPromote, write
classify, 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, writeParameters
classify, discreteValueArray, getCompositeChildren, getInputType, getOutputType, realValueArray, test, toString, valueIndexOf
public PassiveAggressive()
public PassiveAggressive(double t)
t
- The desired threshold value.public PassiveAggressive(double t, double pt)
t
- The desired threshold value.pt
- The desired thickness.public PassiveAggressive(double t, double pt, double nt)
t
- The desired threshold value.pt
- The desired positive thickness.nt
- The desired negative thickness.public PassiveAggressive(double t, double pt, double nt, SparseWeightVector v)
SparseWeightVector
, while
the name of the classifier gets the empty string.t
- The desired threshold value.pt
- The desired positive thickness.nt
- The desired negative thickness.v
- An empty sparse weight vector.public PassiveAggressive(PassiveAggressive.Parameters p)
SparsePerceptron.Parameters
object.p
- The settings of all parameters.public PassiveAggressive(String n)
n
- The name of the classifier.public PassiveAggressive(String n, double t)
n
- The name of the classifier.t
- The desired threshold value.public PassiveAggressive(String n, double t, double pt)
n
- The name of the classifier.t
- The desired threshold value.pt
- The desired thickness.public PassiveAggressive(String n, double t, double pt, double nt)
n
- The name of the classifier.t
- The desired threshold value.pt
- The desired positive thickness.nt
- The desired negative thickness.public PassiveAggressive(String n, double t, double pt, double nt, SparseWeightVector v)
SparseWeightVector
.n
- The name of the classifier.t
- The desired threshold value.pt
- The desired positive thickness.nt
- The desired negative thickness.v
- An empty sparse weight vector.public PassiveAggressive(String n, PassiveAggressive.Parameters p)
SparsePerceptron.Parameters
object.n
- The name of the classifier.p
- The settings of all parameters.public Learner.Parameters getParameters()
getParameters
in class LinearThresholdUnit
public void promote(int[] exampleFeatures, double[] exampleValues, double rate)
promote
in class LinearThresholdUnit
exampleFeatures
- The example's array of feature indicesexampleValues
- The example's array of feature valuesrate
- The learning rate at which the weights are updated.public void demote(int[] exampleFeatures, double[] exampleValues, double rate)
demote
in class LinearThresholdUnit
exampleFeatures
- The example's array of feature indicesexampleValues
- The example's array of feature valuesrate
- The learning rate at which the weights are updated.public double computeLearningRate(int[] exampleFeatures, double[] exampleValues, double s, boolean label)
computeLearningRate
in class LinearThresholdUnit
exampleFeatures
- The example's array of feature indicesexampleValues
- The example's array of feature valuess
- The score for the example objectlabel
- The labelLinearThresholdUnit.learningRate
variablepublic void write(PrintStream out)
LinearThresholdUnit.learningRate
,
LinearThresholdUnit.initialWeight
, LinearThresholdUnit.threshold
,
LinearThresholdUnit.positiveThickness
, LinearThresholdUnit.negativeThickness
,
and finally LinearThresholdUnit.bias
.Copyright © 2016. All rights reserved.