jsat.classifiers.linear
Class ALMA2
- java.lang.Object
-
- jsat.classifiers.BaseUpdateableClassifier
-
- jsat.classifiers.linear.ALMA2
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, BinaryScoreClassifier, Classifier, UpdateableClassifier, SimpleWeightVectorModel, SingleWeightVectorModel
public class ALMA2 extends BaseUpdateableClassifier implements BinaryScoreClassifier, SingleWeightVectorModel
Provides a linear implementation of the ALMAp algorithm for p = 2, which is considerably more efficient to compute. It is a binary classifier for numeric features.
ALMA requires one major parameteralphato be set, the other two have default behavior / values that have provable convergence.
See: Gentile, C. (2002). A New Approximate Maximal Margin Classification Algorithm. The Journal of Machine Learning Research, 2, 213–242. Retrieved from here- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description ALMA2()Creates a new ALMA learner using an alpha of 0.8ALMA2(double alpha)Creates a new ALMA learner using the given alpha
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.ALMA2clone()doublegetAlpha()Returns the approximation coefficient useddoublegetB()Returns the B value of the ALMA algorithmdoublegetBias()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.doublegetC()VecgetRawWeight()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.booleanisUseBias()Returns whether or not an implicit bias term is in useintnumWeightsVecs()Returns the number of weight vectors that can be returned.voidsetAlpha(double alpha)Alpha controls the approximation of the large margin formed by ALMA, with larger values causing more updates.voidsetB(double B)Sets the B variable of the ALMA algorithm, this is set automatically bysetAlpha(double).voidsetC(double C)Sets the C value of the ALMA algorithm.voidsetUp(CategoricalData[] categoricalAttributes, int numericAttributes, CategoricalData predicting)Prepares the classifier to begin learning from itsUpdateableClassifier.update(jsat.classifiers.DataPoint, int)method.voidsetUseBias(boolean useBias)Sets whether or not an implicit bias term will be added to the data setbooleansupportsWeightedData()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
-
-
-
-
Constructor Detail
-
ALMA2
public ALMA2()
Creates a new ALMA learner using an alpha of 0.8
-
ALMA2
public ALMA2(double alpha)
Creates a new ALMA learner using the given alpha- Parameters:
alpha- the alpha value to use- See Also:
setAlpha(double)
-
-
Method Detail
-
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
-
setAlpha
public void setAlpha(double alpha)
Alpha controls the approximation of the large margin formed by ALMA, with larger values causing more updates. A value of 1.0 will update only on mistakes, while smaller values update if the error was not far enough away from the margin.
NOTE: Whenever alpha is set, the value ofBwill also be set to an appropriate value. This is not the only possible value that will lead to convergence, and can be set manually after alpha is set to another value.- Parameters:
alpha- the approximation scale in (0.0, 1.0]
-
getAlpha
public double getAlpha()
Returns the approximation coefficient used- Returns:
- the approximation coefficient used
-
setB
public void setB(double B)
Sets the B variable of the ALMA algorithm, this is set automatically bysetAlpha(double).- Parameters:
B- the value for B
-
getB
public double getB()
Returns the B value of the ALMA algorithm- Returns:
- the B value of the ALMA algorithm
-
setC
public void setC(double C)
Sets the C value of the ALMA algorithm. The default value is the one suggested in the paper.- Parameters:
C- the C value of ALMA
-
getC
public double getC()
-
setUseBias
public void setUseBias(boolean useBias)
Sets whether or not an implicit bias term will be added to the data set- Parameters:
useBias-trueto add an implicit bias term
-
isUseBias
public boolean isUseBias()
Returns whether or not an implicit bias term is in use- Returns:
trueif a bias term is in use
-
clone
public ALMA2 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.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG