E
- the class of the data objects used in the modelpublic class KernelPegasosEngine<E> extends java.lang.Object implements OnlineEngine<E>, java.io.Serializable
The pegasos algorithm is present in the paper Pegasos: Primal Estimated sub-GrAdient SOlver for SVM. by Shalev-Shwartz, Shai, Yoram Singer, and Nathan Srebro. This class is an implementation of an adaptation of Pegasos to be used with a kernel function.
Modifier and Type | Class and Description |
---|---|
static class |
KernelPegasosEngine.Conf<E1>
Defines the configuration parameters to create OnlineEngines of the
type
KernelPegasosEngine |
Constructor and Description |
---|
KernelPegasosEngine(double lambda,
double hingeParameter,
Kernel<E> k)
Creates a Pegasos Engine that use a Kernel
|
Modifier and Type | Method and Description |
---|---|
void |
compileModel()
Calls the finishing procedures after the training of this Online Engine.
|
DataObject<E> |
convertVector(DataObject<E> x)
Transforms a DataObject into another DataObject with modifications
to be in the right format for this engine
|
double |
getB()
Gets the bias term used in this model
|
Kernel<E> |
getKernel()
Gets the kernel used in this engine
|
long |
getKernelAccesses()
Gets the number of calls made to the kernels during the training
|
boolean |
getResult(DataObject<E> vector)
Uses this online model to predict the label for a data
instance of type E encapsulated by a DataObject
|
double |
getScore(DataObject<E> vector)
Gets the certainty score of this model prediction for a data instance of type E
|
java.util.Map<DataObject<E>,java.lang.Double> |
getWeights()
Gets the weights for each SV (Support Vector) in this model
SV is a data instance with non-zero weight, it is used to compose this model
|
int |
numSVs()
Gets the number of SVs (Support Vectors)
SVs are data instance with non-zero weights in this model
|
double |
objectiveValue(java.util.List<DataObject<E>> trainingData,
java.util.Map<java.lang.Integer,java.lang.Boolean> desiredLabels)
Computes the objective function value for the provided labelled data
samples
|
void |
setKernel(Kernel<E> kernel)
Sets a new kernel object.
|
void |
start()
Calls the initial procedures, before starting using the Online Engine for training.
|
boolean |
updateModel(DataObject<E>[] inputVectors,
boolean[] desiredOutputs)
Adds a new array of data instance to this online model.
|
boolean |
updateModel(DataObject<E> inputVector,
boolean desiredOutput)
Adds a new data instance to this online model.
|
public KernelPegasosEngine(double lambda, double hingeParameter, Kernel<E> k)
lambda
- a double containing the lambda parameter of the SVM
model to be createdhingeParameter
- parameter that forces more or less precision.
The recommended and the usual is to set this parameter to zerok
- the kernel used to compare pairs of data instancespublic boolean updateModel(DataObject<E> inputVector, boolean desiredOutput)
OnlineEngine
updateModel
in interface OnlineEngine<E>
inputVector
- the data instance of type E encapsulated by a DataObjectdesiredOutput
- a boolean indicating the true label for the data
instance at inputVectorpublic boolean updateModel(DataObject<E>[] inputVectors, boolean[] desiredOutputs)
This method is intended for batch processing
inputVectors
- the array of data instance of type E encapsulated by a DataObjectdesiredOutputs
- an array of booleans that indicate the true label for the data
instances at inputVectors
public boolean getResult(DataObject<E> vector)
OnlineEngine
getResult
in interface OnlineEngine<E>
vector
- an input DataObject to be predictedpublic double getScore(DataObject<E> vector)
OnlineEngine
getScore
in interface OnlineEngine<E>
vector
- the data instance that will it receive the scorepublic DataObject<E> convertVector(DataObject<E> x) throws InvalidVectorIndexException
OnlineEngine
convertVector
in interface OnlineEngine<E>
x
- a DataObject that encapsulates the data instance to be
transformedInvalidVectorIndexException
- when the DataObject to be transformed
has occupied reserved constantspublic Kernel<E> getKernel()
public void setKernel(Kernel<E> kernel)
kernel
- the new kernel that will be used in this modelpublic int numSVs()
public void compileModel()
OnlineEngine
compileModel is mainly intended to reduce the model size, that is compile the model
compileModel
in interface OnlineEngine<E>
public void start()
OnlineEngine
start
in interface OnlineEngine<E>
public long getKernelAccesses()
public java.util.Map<DataObject<E>,java.lang.Double> getWeights()
public double getB()
public double objectiveValue(java.util.List<DataObject<E>> trainingData, java.util.Map<java.lang.Integer,java.lang.Boolean> desiredLabels)
This method is manly used with all the training data samples to obtained a convergence value during the training iterations
trainingData
- the list of data samples used to compute the objective function valuedesiredLabels
- a map containing the labels for the trainingData