jsat.classifiers.linear
Class AROW
- java.lang.Object
-
- jsat.classifiers.BaseUpdateableClassifier
-
- jsat.classifiers.linear.AROW
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, BinaryScoreClassifier, Classifier, UpdateableClassifier, Parameterized, SimpleWeightVectorModel, SingleWeightVectorModel
public class AROW extends BaseUpdateableClassifier implements BinaryScoreClassifier, Parameterized, SingleWeightVectorModel
An implementation of Adaptive Regularization of Weight Vectors (AROW), which uses second order information to learn a large margin binary classifier. As such, updates can occur on correctly classified instances if they are not far enough from the margin. Unlike many margin algorithms, it handles noise well.
NOTE: This implementation does not add an implicit bias term, so the solution goes through the origin
See: Crammer, K., Kulesza, A.,&Dredze, M. (2013). Adaptive regularization of weight vectors. Machine Learning, 91(2), 155–187. doi:10.1007/s10994-013-5327-x- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description AROW()Creates a new AROW learnerAROW(double r, boolean diagonalOnly)Creates a new AROW learner
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.AROWclone()doublegetBias()Returns the bias term used for the model, or 0 of the model does not support or was not trained with a bias term.doublegetBias(int index)Returns the bias term used with the weight vector for the given class index.doublegetR()Returns the regularization parameterVecgetRawWeight()Returns the only weight vector used for the modelVecgetRawWeight(int index)Returns the raw weight vector associated with the given class index.doublegetScore(DataPoint dp)Returns the numeric score for predicting a class of a given data point, where the sign of the value indicates which class the data point is predicted to belong to.VecgetWeightVec()Returns the weight vector used to compute results via a dot product.static DistributionguessR(DataSet d)Guess the distribution to use for the regularization termr.booleanisDiagonalOnly()Returnstrueif the covariance matrix is restricted to its diagonal entriesintnumWeightsVecs()Returns the number of weight vectors that can be returned.voidsetDiagonalOnly(boolean diagonalOnly)Using the full covariance matrix requires O(d2) work on mistakes, where d is the dimension of the data.voidsetR(double r)Sets the r parameter of AROW, which controls the regularization.voidsetUp(CategoricalData[] categoricalAttributes, int numericAttributes, CategoricalData predicting)Prepares the classifier to begin learning from itsUpdateableClassifier.update(jsat.classifiers.DataPoint, int)method.booleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidupdate(DataPoint dataPoint, int targetClass)Updates the classifier by giving it a new data point to learn from.-
Methods inherited from class jsat.classifiers.BaseUpdateableClassifier
getEpochs, setEpochs, train, train, trainEpochs
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.classifiers.Classifier
train, train
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Constructor Detail
-
AROW
public AROW()
Creates a new AROW learner
-
AROW
public AROW(double r, boolean diagonalOnly)Creates a new AROW learner- Parameters:
r- the regularization parameterdiagonalOnly- whether or not to use only the diagonal of the covariance- See Also:
setR(double),setDiagonalOnly(boolean)
-
-
Method Detail
-
setDiagonalOnly
public void setDiagonalOnly(boolean diagonalOnly)
Using the full covariance matrix requires O(d2) work on mistakes, where d is the dimension of the data. Runtime can be reduced by using only the diagonal of the matrix to perform updates in O(s) time, where s ≤ d is the number of non-zero values in the input- Parameters:
diagonalOnly-trueto use only the diagonal of the covariance
-
isDiagonalOnly
public boolean isDiagonalOnly()
Returnstrueif the covariance matrix is restricted to its diagonal entries- Returns:
trueif the covariance matrix is restricted to its diagonal entries
-
setR
public void setR(double r)
Sets the r parameter of AROW, which controls the regularization. Larger values reduce the change in the model on each update.- Parameters:
r- the regularization parameter in (0, Inf)
-
getR
public double getR()
Returns the regularization parameter- Returns:
- the regularization parameter
-
getWeightVec
public Vec getWeightVec()
Returns the weight vector used to compute results via a dot product.
Do not modify this value, or you will alter the results returned.- Returns:
- the learned weight vector for prediction
-
clone
public AROW clone()
- Specified by:
clonein interfaceBinaryScoreClassifier- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceUpdateableClassifier- Specified by:
clonein classBaseUpdateableClassifier
-
setUp
public void setUp(CategoricalData[] categoricalAttributes, int numericAttributes, CategoricalData predicting)
Description copied from interface:UpdateableClassifierPrepares the classifier to begin learning from itsUpdateableClassifier.update(jsat.classifiers.DataPoint, int)method.- Specified by:
setUpin interfaceUpdateableClassifier- Parameters:
categoricalAttributes- an array containing the categorical attributes that will be in each data pointnumericAttributes- the number of numeric attributes that will be in each data pointpredicting- the information for the target class that will be predicted
-
update
public void update(DataPoint dataPoint, int targetClass)
Description copied from interface:UpdateableClassifierUpdates the classifier by giving it a new data point to learn from.- Specified by:
updatein interfaceUpdateableClassifier- Parameters:
dataPoint- the data point to learntargetClass- the target class of the data point
-
classify
public CategoricalResults classify(DataPoint data)
Description copied from interface:ClassifierPerforms classification on the given data point.- Specified by:
classifyin interfaceClassifier- Parameters:
data- the data point to classify- Returns:
- the results of the classification.
-
getScore
public double getScore(DataPoint dp)
Description copied from interface:BinaryScoreClassifierReturns the numeric score for predicting a class of a given data point, where the sign of the value indicates which class the data point is predicted to belong to.- Specified by:
getScorein interfaceBinaryScoreClassifier- Parameters:
dp- the data point to predict the class label of- Returns:
- the score for the given data point
-
supportsWeightedData
public boolean supportsWeightedData()
Description copied from interface:ClassifierIndicates whether the model knows how to train using weighted data points. If it does, the model will train assuming the weights. The values returned by this method may change depending on the parameters set for the model.- Specified by:
supportsWeightedDatain interfaceClassifier- Returns:
- true if the model supports weighted data, false otherwise
-
getRawWeight
public Vec getRawWeight()
Description copied from interface:SingleWeightVectorModelReturns the only weight vector used for the model- Specified by:
getRawWeightin interfaceSingleWeightVectorModel- Returns:
- the only weight vector used for the model
-
getBias
public double getBias()
Description copied from interface:SingleWeightVectorModelReturns the bias term used for the model, or 0 of the model does not support or was not trained with a bias term.- Specified by:
getBiasin interfaceSingleWeightVectorModel- Returns:
- the bias term for the model
-
getRawWeight
public Vec getRawWeight(int index)
Description copied from interface:SimpleWeightVectorModelReturns the raw weight vector associated with the given class index. If the given class is an implicit zero vector, aConstantVectorobject may be returned.
Do not alter the returned weight vector, as it will change the model's values.
If a regression problem, onlyindex = 0should be used- Specified by:
getRawWeightin interfaceSimpleWeightVectorModel- Parameters:
index- the class index to get the weight vector for- Returns:
- the weight vector used for the specified class
-
getBias
public double getBias(int index)
Description copied from interface:SimpleWeightVectorModelReturns the bias term used with the weight vector for the given class index. If the model does not support or was not trained with bias weights,0will be returned.
If a regression problem, onlyindex = 0should be used- Specified by:
getBiasin interfaceSimpleWeightVectorModel- Parameters:
index- the class index to get the weight vector for- Returns:
- the bias term for the specified class
-
numWeightsVecs
public int numWeightsVecs()
Description copied from interface:SimpleWeightVectorModelReturns the number of weight vectors that can be returned. For binary classification problems the value may be 1 if only a single weight vector's sign is used to determine the class. For multi-class problems, the weight vector count includes the implicit zero vector (if one is being used).- Specified by:
numWeightsVecsin interfaceSimpleWeightVectorModel- Returns:
- the number of weight vectors for which
SimpleWeightVectorModel.getRawWeight(int)can be called.
-
guessR
public static Distribution guessR(DataSet d)
Guess the distribution to use for the regularization termr.- Parameters:
d- the data set to get the guess for- Returns:
- the guess for the r parameter
-
-
DataMelt 3.0 © DataMelt by jWork.ORG