Package moa.classifiers.functions
Class SPegasos
- java.lang.Object
-
- moa.AbstractMOAObject
-
- moa.options.AbstractOptionHandler
-
- moa.classifiers.AbstractClassifier
-
- moa.classifiers.functions.SPegasos
-
- All Implemented Interfaces:
Configurable
,Serializable
,CapabilitiesHandler
,Classifier
,MultiClassClassifier
,AWTRenderable
,Learner<Example<Instance>>
,MOAObject
,OptionHandler
public class SPegasos extends AbstractClassifier implements MultiClassClassifier
Implements the stochastic variant of the Pegasos (Primal Estimated sub-GrAdient SOlver for SVM) method of Shalev-Shwartz et al. (2007). For more information, see
S. Shalev-Shwartz, Y. Singer, N. Srebro: Pegasos: Primal Estimated sub-GrAdient SOlver for SVM. In: 24th International Conference on MachineLearning, 807-814, 2007. * BibTeX:@inproceedings{Shalev-Shwartz2007, author = {S. Shalev-Shwartz and Y. Singer and N. Srebro}, booktitle = {24th International Conference on MachineLearning}, pages = {807-814}, title = {Pegasos: Primal Estimated sub-GrAdient SOlver for SVM}, year = {2007} }
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
HINGE
FloatOption
lambdaRegularizationOption
protected static int
LOGLOSS
MultiChoiceOption
lossFunctionOption
protected double
m_lambda
The regularization parameterprotected int
m_loss
The current loss function to minimizeprotected double
m_t
Holds the current iteration numberprotected double[]
m_weights
Stores the weights (+ bias in the last element)-
Fields inherited from class moa.classifiers.AbstractClassifier
classifierRandom, modelContext, randomSeed, randomSeedOption, trainingWeightSeenByModel
-
Fields inherited from class moa.options.AbstractOptionHandler
config
-
-
Constructor Summary
Constructors Constructor Description SPegasos()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected double
dloss(double z)
protected static double
dotProd(Instance inst1, double[] weights, int classIndex)
double
getLambda()
Get the current value of lambdaint
getLossFunction()
Get the current loss function.void
getModelDescription(StringBuilder result, int indent)
Returns a string representation of the model.protected Measurement[]
getModelMeasurementsImpl()
Gets the current measurements of this classifier.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods.String
getPurposeString()
Dictionary with option texts and objectsdouble[]
getVotesForInstance(Instance inst)
Calculates the class membership probabilities for the given test instance.boolean
isRandomizable()
Gets whether this learner needs a random seed.void
reset()
Reset the classifier.void
resetLearningImpl()
Resets this classifier.void
setLambda(double lambda)
Set the value of lambda to usevoid
setLossFunction(int function)
Set the loss function to use.String
toString()
Prints out the classifier.void
trainOnInstanceImpl(Instance instance)
Trains the classifier with the given instance.-
Methods inherited from class moa.classifiers.AbstractClassifier
contextIsCompatible, copy, correctlyClassifies, defineImmutableCapabilities, getAttributeNameString, getAWTRenderer, getClassLabelString, getClassNameString, getDescription, getModel, getModelContext, getModelMeasurements, getNominalValueString, getPredictionForInstance, getPredictionForInstance, getSubClassifiers, getSublearners, getVotesForInstance, modelAttIndexToInstanceAttIndex, modelAttIndexToInstanceAttIndex, prepareForUseImpl, resetLearning, setModelContext, setRandomSeed, trainingHasStarted, trainingWeightSeenByModel, trainOnInstance, trainOnInstance
-
Methods inherited from class moa.options.AbstractOptionHandler
getCLICreationString, getOptions, getPreparedClassOption, prepareClassOptions, prepareForUse, prepareForUse
-
Methods inherited from class moa.AbstractMOAObject
copy, measureByteSize, measureByteSize
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface moa.capabilities.CapabilitiesHandler
getCapabilities
-
Methods inherited from interface moa.MOAObject
measureByteSize
-
Methods inherited from interface moa.options.OptionHandler
getCLICreationString, getOptions, prepareForUse, prepareForUse
-
-
-
-
Field Detail
-
m_lambda
protected double m_lambda
The regularization parameter
-
lambdaRegularizationOption
public FloatOption lambdaRegularizationOption
-
HINGE
protected static final int HINGE
- See Also:
- Constant Field Values
-
LOGLOSS
protected static final int LOGLOSS
- See Also:
- Constant Field Values
-
m_loss
protected int m_loss
The current loss function to minimize
-
lossFunctionOption
public MultiChoiceOption lossFunctionOption
-
m_weights
protected double[] m_weights
Stores the weights (+ bias in the last element)
-
m_t
protected double m_t
Holds the current iteration number
-
-
Method Detail
-
getPurposeString
public String getPurposeString()
Description copied from class:AbstractOptionHandler
Dictionary with option texts and objects- Specified by:
getPurposeString
in interfaceOptionHandler
- Overrides:
getPurposeString
in classAbstractClassifier
- Returns:
- the string with the purpose of this object
-
setLambda
public void setLambda(double lambda)
Set the value of lambda to use- Parameters:
lambda
- the value of lambda to use
-
getLambda
public double getLambda()
Get the current value of lambda- Returns:
- the current value of lambda
-
setLossFunction
public void setLossFunction(int function)
Set the loss function to use.- Parameters:
function
- the loss function to use.
-
getLossFunction
public int getLossFunction()
Get the current loss function.- Returns:
- the current loss function.
-
reset
public void reset()
Reset the classifier.
-
dotProd
protected static double dotProd(Instance inst1, double[] weights, int classIndex)
-
dloss
protected double dloss(double z)
-
resetLearningImpl
public void resetLearningImpl()
Description copied from class:AbstractClassifier
Resets this classifier. It must be similar to starting a new classifier from scratch.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods. Note that this will produce compiler errors if not overridden.- Specified by:
resetLearningImpl
in classAbstractClassifier
-
trainOnInstanceImpl
public void trainOnInstanceImpl(Instance instance)
Trains the classifier with the given instance.- Specified by:
trainOnInstanceImpl
in classAbstractClassifier
- Parameters:
instance
- the new training instance to include in the model
-
getVotesForInstance
public double[] getVotesForInstance(Instance inst)
Calculates the class membership probabilities for the given test instance.- Specified by:
getVotesForInstance
in interfaceClassifier
- Specified by:
getVotesForInstance
in classAbstractClassifier
- Parameters:
inst
- the instance to be classified- Returns:
- predicted class probability distribution
-
getModelDescription
public void getModelDescription(StringBuilder result, int indent)
Description copied from class:AbstractClassifier
Returns a string representation of the model.- Specified by:
getModelDescription
in classAbstractClassifier
- Parameters:
result
- the stringbuilder to add the descriptionindent
- the number of characters to indent
-
toString
public String toString()
Prints out the classifier.- Overrides:
toString
in classAbstractMOAObject
- Returns:
- a description of the classifier as a string
-
getModelMeasurementsImpl
protected Measurement[] getModelMeasurementsImpl()
Description copied from class:AbstractClassifier
Gets the current measurements of this classifier.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods. Note that this will produce compiler errors if not overridden.- Specified by:
getModelMeasurementsImpl
in classAbstractClassifier
- Returns:
- an array of measurements to be used in evaluation tasks
-
isRandomizable
public boolean isRandomizable()
Description copied from interface:Learner
Gets whether this learner needs a random seed. Examples of methods that needs a random seed are bagging and boosting.- Specified by:
isRandomizable
in interfaceLearner<Example<Instance>>
- Returns:
- true if the learner needs a random seed.
-
-