jsat.classifiers.linear.kernelized
Class KernelSGD
- java.lang.Object
-
- jsat.classifiers.linear.kernelized.KernelSGD
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, UpdateableClassifier, Parameterized, Regressor, UpdateableRegressor
public class KernelSGD extends java.lang.Object implements UpdateableClassifier, UpdateableRegressor, Parameterized
Kernel SGD is the kernelized counterpart toLinearSGD, and learns nonlinear functions via the kernel trick. The implementation is built uponKernelPointandKernelPointsto support budgeted learning. Following the LinearSGD implementation, whether or not this algorithm supports regression, binary-classification, or multi-class classification is controlled by theloss functionused.
The learning rate decay is not configurable for this implementation, and is decayed at a rate ofη/ (λ* (t + 2 / λ)) , wheretis the time step.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description KernelSGD()Creates a new Kernel SGD object for classification with the RBF kernelKernelSGD(KernelSGD toCopy)Copy constructorKernelSGD(LossFunc loss, KernelTrick kernel, double lambda, KernelPoint.BudgetStrategy budgetStrategy, int budgetSize)Creates a new Kernel SGD objectKernelSGD(LossFunc loss, KernelTrick kernel, double lambda, KernelPoint.BudgetStrategy budgetStrategy, int budgetSize, double eta, double errorTolerance)Creates a new Kernel SGD object
-
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.KernelSGDclone()intgetBudgetSize()Returns the budget size, or maximum number of allowed support vectors.KernelPoint.BudgetStrategygetBudgetStrategy()Returns the method of budget maintenanceintgetEpochs()Returns the number of epochs to usedoublegetErrorTolerance()Returns the error tolerance that would be useddoublegetEta()Returns the base learning rateKernelTrickgetKernel()Returns the kernel in usedoublegetLambda()Returns the L2 regularization parameterLossFuncgetLoss()Returns the loss function in usestatic DistributionguessLambda(DataSet d)Guess the distribution to use for the regularization termλ.doubleregress(DataPoint data)voidsetBudgetSize(int budgetSize)Sets the maximum budget size, or number of support vectors, to allow during training.voidsetBudgetStrategy(KernelPoint.BudgetStrategy budgetStrategy)Sets the budget maintenance strategy.voidsetEpochs(int epochs)Sets the number of iterations of the training set done during batch trainingvoidsetErrorTolerance(double errorTolerance)Sets the error tolerance used for certainbudget strategiesvoidsetEta(double eta)Sets the base learning rate to start from.voidsetKernel(KernelTrick kernel)Sets the kernel to usevoidsetLambda(double lambda)Sets the L2 regularization parameter used during learning.voidsetLoss(LossFunc loss)Sets the loss function to use.voidsetUp(CategoricalData[] categoricalAttributes, int numericAttributes)Prepares the classifier to begin learning from itsUpdateableRegressor.update(jsat.classifiers.DataPoint, double)method.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.voidtrain(ClassificationDataSet dataSet)Trains the classifier and constructs a model for classification using the given data set.voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.voidtrain(RegressionDataSet dataSet)voidtrain(RegressionDataSet dataSet, boolean parallel)voidupdate(DataPoint dataPoint, double targetValue)Updates the classifier by giving it a new data point to learn from.voidupdate(DataPoint dataPoint, int targetClass)Updates the classifier by giving it a new data point to learn from.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Constructor Detail
-
KernelSGD
public KernelSGD()
Creates a new Kernel SGD object for classification with the RBF kernel
-
KernelSGD
public KernelSGD(LossFunc loss, KernelTrick kernel, double lambda, KernelPoint.BudgetStrategy budgetStrategy, int budgetSize)
Creates a new Kernel SGD object- Parameters:
loss- the loss function to usekernel- the kernel trick to uselambda- the regularization penaltybudgetStrategy- the budget maintenance strategy to usebudgetSize- the maximum support vector budget
-
KernelSGD
public KernelSGD(LossFunc loss, KernelTrick kernel, double lambda, KernelPoint.BudgetStrategy budgetStrategy, int budgetSize, double eta, double errorTolerance)
Creates a new Kernel SGD object- Parameters:
loss- the loss function to usekernel- the kernel trick to uselambda- the regularization penaltyeta- the initial learning ratebudgetStrategy- the budget maintenance strategy to useerrorTolerance- the error tolerance used in certain budget maintenance stepsbudgetSize- the maximum support vector budget
-
KernelSGD
public KernelSGD(KernelSGD toCopy)
Copy constructor- Parameters:
toCopy- the object to copy
-
-
Method Detail
-
setEpochs
public void setEpochs(int epochs)
Sets the number of iterations of the training set done during batch training- Parameters:
epochs- the number of iterations in batch training
-
getEpochs
public int getEpochs()
Returns the number of epochs to use- Returns:
- the number of epochs to use
-
setLoss
public void setLoss(LossFunc loss)
Sets the loss function to use. The loss function controls whether or not classification or regression is supported.- Parameters:
loss-
-
getLoss
public LossFunc getLoss()
Returns the loss function in use- Returns:
- the loss function in use
-
setLambda
public void setLambda(double lambda)
Sets the L2 regularization parameter used during learning.- Parameters:
lambda- the positive regularization parameter
-
getLambda
public double getLambda()
Returns the L2 regularization parameter- Returns:
- the L2 regularization parameter
-
setErrorTolerance
public void setErrorTolerance(double errorTolerance)
Sets the error tolerance used for certainbudget strategies- Parameters:
errorTolerance- the error tolerance in [0, 1]
-
getErrorTolerance
public double getErrorTolerance()
Returns the error tolerance that would be used- Returns:
- the error tolerance that would be used
-
setBudgetSize
public void setBudgetSize(int budgetSize)
Sets the maximum budget size, or number of support vectors, to allow during training. Increasing the budget size will increase the accuracy of the model, but will also increase the computational cost- Parameters:
budgetSize- the maximum allowed number of support vectors
-
getBudgetSize
public int getBudgetSize()
Returns the budget size, or maximum number of allowed support vectors.- Returns:
- the maximum number of allowed support vectors
-
setBudgetStrategy
public void setBudgetStrategy(KernelPoint.BudgetStrategy budgetStrategy)
Sets the budget maintenance strategy.- Parameters:
budgetStrategy- the method to meet budget size requirements
-
getBudgetStrategy
public KernelPoint.BudgetStrategy getBudgetStrategy()
Returns the method of budget maintenance- Returns:
- the method of budget maintenance
-
setEta
public void setEta(double eta)
Sets the base learning rate to start from. Because of the decay rate in use a good value for η is 1.0.- Parameters:
eta- the starting learning rate to use
-
getEta
public double getEta()
Returns the base learning rate- Returns:
- the base learning rate
-
setKernel
public void setKernel(KernelTrick kernel)
Sets the kernel to use- Parameters:
kernel- the kernel to use
-
getKernel
public KernelTrick getKernel()
Returns the kernel in use- Returns:
- the kernel in use
-
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
-
setUp
public void setUp(CategoricalData[] categoricalAttributes, int numericAttributes)
Description copied from interface:UpdateableRegressorPrepares the classifier to begin learning from itsUpdateableRegressor.update(jsat.classifiers.DataPoint, double)method.- Specified by:
setUpin interfaceUpdateableRegressor- 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 point
-
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
-
update
public void update(DataPoint dataPoint, double targetValue)
Description copied from interface:UpdateableRegressorUpdates the classifier by giving it a new data point to learn from.- Specified by:
updatein interfaceUpdateableRegressor- Parameters:
dataPoint- the data point to learntargetValue- the target value 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.
-
train
public void train(ClassificationDataSet dataSet, boolean parallel)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set. If the training method knows how, it will used the threadPool to conduct training in parallel. This method will block until the training has completed.- Specified by:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used to train the model.falseif it should be done in a single threaded manner.
-
train
public void train(ClassificationDataSet dataSet)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set.- Specified by:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train on
-
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- Specified by:
supportsWeightedDatain interfaceRegressor- Returns:
- true if the model supports weighted data, false otherwise
-
train
public void train(RegressionDataSet dataSet, boolean parallel)
-
train
public void train(RegressionDataSet dataSet)
-
clone
public KernelSGD clone()
- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceUpdateableClassifier- Specified by:
clonein interfaceRegressor- Specified by:
clonein interfaceUpdateableRegressor- Overrides:
clonein classjava.lang.Object
-
guessLambda
public static Distribution guessLambda(DataSet d)
Guess the distribution to use for the regularization termλ.- Parameters:
d- the data set to get the guess for- Returns:
- the guess for the λ parameter
-
-
DataMelt 3.0 © DataMelt by jWork.ORG