jsat.classifiers.linear.kernelized
Class OSKL
- java.lang.Object
-
- jsat.classifiers.BaseUpdateableClassifier
-
- jsat.classifiers.linear.kernelized.OSKL
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, BinaryScoreClassifier, Classifier, UpdateableClassifier, Parameterized
public class OSKL extends BaseUpdateableClassifier implements BinaryScoreClassifier, Parameterized
Online Sparse Kernel Learning by Sampling and Smooth Losses (OSKL) is an online algorithm for learning sparse kernelized solutions to binary classification problems. The number of support vectors is controlled by a a sparsity parameterGand a specifiedloss function. The number of support vectors is bounded by the cumulative loss of the loss function used.
The OSKL algorithm is designed for use with smooth loss functions such as thelogistic loss. However, it can work with non-smooth loss functions such as thehinge loss.
See: Zhang, L., Yi, J., Jin, R., Lin, M.,&He, X. (2013). Online Kernel Learning with a Near Optimal Sparsity Bound. In S. Dasgupta&D. Mcallester (Eds.), Proceedings of the 30th International Conference on Machine Learning (ICML-13) (Vol. 28, pp. 621–629). JMLR Workshop and Conference Proceedings.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description OSKL(KernelTrick k, double R)Creates a new OSKL learner using theLogisticLoss.OSKL(KernelTrick k, double eta, double G, double R)Creates a new OSKL learner using theLogisticLossOSKL(KernelTrick k, double eta, double G, double R, LossC lossC)Creates a new OSKL learnerOSKL(OSKL toCopy)Copy constructor
-
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.OSKLclone()intgetBurnIn()Returns the number of burn in roundsdoublegetEta()Returns the learning rate in usedoublegetG()Returns the sparsification parameterKernelTrickgetKernel()Returns the kernel to usedoublegetR()Returns the maximum allowed norm for the model learneddoublegetScore(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.intgetSupportVectorCount()Returns the number of data points accepted as support vectorsstatic DistributionguessR(DataSet d)Guesses the distribution to use for the R parameterbooleanisUseAverageModel()Returnstrueif the average of all models is being used, orfalseif the last model is usedvoidsetBurnIn(int burnIn)Sets the number of update calls to consider as part of the "burn in" phase.voidsetEta(double eta)Sets the learning rate to use for training.voidsetG(double G)Sets the sparsification parameter G.voidsetKernel(KernelTrick k)Sets the kernel to usevoidsetR(double R)Sets the maximum allowed norm of the model.voidsetUp(CategoricalData[] categoricalAttributes, int numericAttributes, CategoricalData predicting)Prepares the classifier to begin learning from itsUpdateableClassifier.update(jsat.classifiers.DataPoint, int)method.voidsetUseAverageModel(boolean useAverageModel)Sets whether or not the average of all intermediate models is used or if the most recent model is used when performing classificationbooleansupportsWeightedData()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
-
OSKL
public OSKL(KernelTrick k, double R)
Creates a new OSKL learner using theLogisticLoss. The parameterssetG(double)andsetEta(double)are set based on the original papers suggestions to produced a less sparse model that should be more accurate- Parameters:
k- the kernel to useR- the maximum allowed norm for the model
-
OSKL
public OSKL(KernelTrick k, double eta, double G, double R)
Creates a new OSKL learner using theLogisticLoss- Parameters:
k- the kernel to useeta- the learning rate to useG- the sparsification parameterR- the maximum allowed norm for the model
-
OSKL
public OSKL(KernelTrick k, double eta, double G, double R, LossC lossC)
Creates a new OSKL learner- Parameters:
k- the kernel to useeta- the learning rate to useG- the sparsification parameterR- the maximum allowed norm for the modellossC- the loss function to use
-
OSKL
public OSKL(OSKL toCopy)
Copy constructor- Parameters:
toCopy- the object to copy
-
-
Method Detail
-
setKernel
public void setKernel(KernelTrick k)
Sets the kernel to use- Parameters:
k- the kernel to use
-
getKernel
public KernelTrick getKernel()
Returns the kernel to use- Returns:
- the kernel to use
-
setEta
public void setEta(double eta)
Sets the learning rate to use for training. The original paper suggests setting η = 0.9/G- Parameters:
eta- the positive learning rate to use
-
getEta
public double getEta()
Returns the learning rate in use- Returns:
- the learning rate in use
-
setG
public void setG(double G)
Sets the sparsification parameter G. Increasing G reduces the number of updates to the model, which increases sparsity but may reduce accuracy. Decreasing G increases the update rate reducing sparsity. The original paper tests values of G ∈ {1, 2, 4, 10}- Parameters:
G- the sparsification parameter in [1, ∞)
-
getG
public double getG()
Returns the sparsification parameter- Returns:
- the sparsification parameter
-
guessR
public static Distribution guessR(DataSet d)
Guesses the distribution to use for the R parameter- Parameters:
d- the dataset to get the guess for- Returns:
- the guess for the R parameter
- See Also:
setR(double)
-
setR
public void setR(double R)
Sets the maximum allowed norm of the model. The original paper suggests values in the range 10x for x ∈ {0, 1, 2, 3, 4, 5}.- Parameters:
R- the maximum allowed norm for the model
-
getR
public double getR()
Returns the maximum allowed norm for the model learned- Returns:
- the maximum allowed norm for the model learned
-
setUseAverageModel
public void setUseAverageModel(boolean useAverageModel)
Sets whether or not the average of all intermediate models is used or if the most recent model is used when performing classification- Parameters:
useAverageModel-trueto use the average model,falseto use the last model update
-
isUseAverageModel
public boolean isUseAverageModel()
Returnstrueif the average of all models is being used, orfalseif the last model is used- Returns:
trueif the average of all models is being used, orfalseif the last model is used
-
setBurnIn
public void setBurnIn(int burnIn)
Sets the number of update calls to consider as part of the "burn in" phase. The averaging of the model will not start until after the burn in phase.
If the classification or score is requested before the burn in phase is completed, the latest model will be used as is.- Parameters:
burnIn- the number of updates to ignore before averaging. Must be non negative.
-
getBurnIn
public int getBurnIn()
Returns the number of burn in rounds- Returns:
- the number of burn in rounds
-
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
-
getSupportVectorCount
public int getSupportVectorCount()
Returns the number of data points accepted as support vectors- Returns:
- the number of support vectors in the model
-
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.
-
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
-
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
-
clone
public OSKL clone()
- Specified by:
clonein interfaceBinaryScoreClassifier- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceUpdateableClassifier- Specified by:
clonein classBaseUpdateableClassifier
-
-
DataMelt 3.0 © DataMelt by jWork.ORG