Documentation - C API
pegasos.h File Reference

PEGASOS (PEGASOS SVM solver) More...

#include "svmdataset.h"

Data Structures

struct  VlSvmObjective
 Binary Svm Objective Function. More...
struct  VlSvmPegasos
 Pegasos Svm Solver. More...

Typedefs

typedef void(* VlSvmDiagnostics )(void *svm)
 Pointer to a function called at each iteration for diagnostics purpose.

Functions

vl_size vl_svmpegasos_get_permutationsize (VlSvmPegasos const *self)
 Get permutation size.
Create and destroy
VlSvmPegasosvl_svmpegasos_new (vl_size dimension, double lambda)
 Create a new VlSvmPegasos structure.
void vl_svmpegasos_delete (VlSvmPegasos *svm, vl_bool freeModel)
 Delete a VlSvmPegasos structure.
Training Fuctions
void vl_svmpegasos_train (VlSvmPegasos *svm, void *data, vl_size numSamples, VlSvmDatasetInnerProduct innerProduct, VlSvmDatasetAccumulator accumulator, vl_int8 const *labels)
void vl_svmpegasos_train_validation_data (VlSvmPegasos *svm, void *data, vl_size numSamples, VlSvmDatasetInnerProduct innerProduct, VlSvmDatasetAccumulator accumulator, vl_int8 const *labels, void *validation, vl_size validationNumSamples, vl_int8 const *validationLabels)
Retrieve data and parameters
double * vl_svmpegasos_get_model (VlSvmPegasos const *self)
 Get svm model.
double vl_svmpegasos_get_bias (VlSvmPegasos const *self)
 Get bias.
vl_size vl_svmpegasos_get_dimension (VlSvmPegasos const *self)
 Get model dimension.
vl_size vl_svmpegasos_get_iterations (VlSvmPegasos const *self)
 Get number of Iterations performed so far.
vl_size vl_svmpegasos_get_maxiterations (VlSvmPegasos const *self)
 Get maximum number of iterations.
double vl_svmpegasos_get_epsilon (VlSvmPegasos const *self)
 Get stopping criterion threshold.
double vl_svmpegasos_get_lambda (VlSvmPegasos const *self)
 Get regularization parameter lambda.
double vl_svmpegasos_get_bias_multiplier (VlSvmPegasos const *self)
 Get bias multiplier.
double vl_svmpegasos_get_elapsed_time (VlSvmPegasos const *self)
 Get the execution time in seconds.
vl_size vl_svmpegasos_get_energy_frequency (VlSvmPegasos const *self)
 Get how frequent the full energy is computed.
double vl_svmpegasos_get_bias_learningrate (VlSvmPegasos const *self)
 Get bias learning rate.
VlSvmObjectivevl_svmpegasos_get_objective (VlSvmPegasos const *self)
 Get svm objective energy.
VlRandvl_svmpegasos_get_random_generator (VlSvmPegasos const *self)
 Get random generator.
vl_uint32vl_svmpegasos_get_permutation (VlSvmPegasos const *self)
 Get permutation.
vl_size vl_svmpegasos_get_permutation_size (VlSvmPegasos const *self)
VlSvmDiagnostics vl_svmpegasos_get_diagnostic (VlSvmPegasos const *self)
 Get Diagnostic Function.
void * vl_svmpegasos_get_diagnostic_caller_ref (VlSvmPegasos const *self)
 Get Diagnostic Function Caller Reference Object.
Set parameters
void vl_svmpegasos_set_model (VlSvmPegasos *self, double *m)
 Set pegasos model.
void vl_svmpegasos_set_bias (VlSvmPegasos *self, double b)
 Set pegasos bias.
void vl_svmpegasos_set_maxiterations (VlSvmPegasos *self, vl_size i)
 Set pegasos max iterations.
void vl_svmpegasos_set_iterations (VlSvmPegasos *self, vl_size i)
 Set pegasos performed iterations.
void vl_svmpegasos_set_epsilon (VlSvmPegasos *self, double e)
 Set pegasos stopping criterion threshold.
void vl_svmpegasos_set_lambda (VlSvmPegasos *self, double l)
 Set lambda.
void vl_svmpegasos_set_bias_multiplier (VlSvmPegasos *self, double b)
 Set bias multiplier.
void vl_svmpegasos_set_energy_frequency (VlSvmPegasos *self, vl_size e)
 Set how frequent the full energy is computed.
void vl_svmpegasos_set_bias_learningrate (VlSvmPegasos *self, double blr)
 Set bias learning rate.
void vl_svmpegasos_set_random_generator (VlSvmPegasos *self, VlRand *r)
 Set random generator.
void vl_svmpegasos_set_permutation (VlSvmPegasos *self, vl_uint32 *p, vl_size psize)
 Set permutation.
void vl_svmpegasos_set_diagnostic (VlSvmPegasos *self, VlSvmDiagnostics d, void *cr)
 Set Diagnostic Function.

Detailed Description

Author:
Daniele Perrone
Andrea Vedaldi

Typedef Documentation

VlSvmDiagnostics

This type defines a function will be called at each iteration of the algorithm. The parameter svm is an instance of the Svm Status VlSvmPegasos.


Function Documentation

void vl_svmpegasos_delete ( VlSvmPegasos svm,
vl_bool  freeModel 
)
Parameters:
@refVlSvmPegasos structure.

The function frees the resources allocated by vl_svmpegasos_new().

double vl_svmpegasos_get_bias ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
bias value.
double vl_svmpegasos_get_bias_learningrate ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
bias learning rate.
double vl_svmpegasos_get_bias_multiplier ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
bias multiplier.
VlSvmDiagnostics vl_svmpegasos_get_diagnostic ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
pointer to diagnostic function.
void * vl_svmpegasos_get_diagnostic_caller_ref ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
pointer to diagnostic function caller reference object.
vl_size vl_svmpegasos_get_dimension ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
model dimension without considering the bias value.
double vl_svmpegasos_get_elapsed_time ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
elapsed time.
vl_size vl_svmpegasos_get_energy_frequency ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
energy computation frequency.
double vl_svmpegasos_get_epsilon ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
stopping criterion threshold.
vl_size vl_svmpegasos_get_iterations ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
number of iterations performed so far.
double vl_svmpegasos_get_lambda ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
lambda.
vl_size vl_svmpegasos_get_maxiterations ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
maximum number of iterations.
double * vl_svmpegasos_get_model ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
pointer to model.
VlSvmObjective * vl_svmpegasos_get_objective ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
objective energy.
vl_uint32 * vl_svmpegasos_get_permutation ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
permutation.
vl_size vl_svmpegasos_get_permutationsize ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
permutation size.
VlRand * vl_svmpegasos_get_random_generator ( VlSvmPegasos const *  self)
inline
Parameters:
selfPegasos Svm Solver.
Returns:
random generator.
VlSvmPegasos* vl_svmpegasos_new ( vl_size  dimension,
double  lambda 
)
Parameters:
dimensionsvm model dimension.
lambdapegasos regularization parameter.

This function allocates and returns a new VlSvmPegasos structure.

Returns:
the new VlSvmPegasos structure.
See also:
vl_svmpegasos_delete
void vl_svmpegasos_set_bias ( VlSvmPegasos self,
double  b 
)
inline
Parameters:
selfPegasos Svm Solver.
bbias.
void vl_svmpegasos_set_bias_learningrate ( VlSvmPegasos self,
double  blr 
)
inline
Parameters:
selfPegasos Svm Solver.
blrbias learning rate.
void vl_svmpegasos_set_bias_multiplier ( VlSvmPegasos self,
double  b 
)
inline
Parameters:
selfPegasos Svm Solver.
bbias multiplier.
void vl_svmpegasos_set_diagnostic ( VlSvmPegasos self,
VlSvmDiagnostics  d,
void *  cr 
)
inline
Parameters:
selfPegasos Svm Solver.
dDiagnostic Function.
crDiagnostic Function Caller Reference.
void vl_svmpegasos_set_energy_frequency ( VlSvmPegasos self,
vl_size  e 
)
inline
Parameters:
selfPegasos Svm Solver.
eenergy compuation frequency.
void vl_svmpegasos_set_epsilon ( VlSvmPegasos self,
double  e 
)
inline
Parameters:
selfPegasos Svm Solver.
estopping criterion threshold.
void vl_svmpegasos_set_iterations ( VlSvmPegasos self,
vl_size  i 
)
inline
Parameters:
selfPegasos Svm Solver.
ipegasos performed iterations.
void vl_svmpegasos_set_lambda ( VlSvmPegasos self,
double  l 
)
inline
Parameters:
selfPegasos Svm Solver.
llambda.
void vl_svmpegasos_set_maxiterations ( VlSvmPegasos self,
vl_size  i 
)
inline
Parameters:
selfPegasos Svm Solver.
ipegasos max iterations.
void vl_svmpegasos_set_model ( VlSvmPegasos self,
double *  m 
)
inline
Parameters:
selfPegasos Svm Solver.
msvm model.

If there is a model already allocated, this method frees it before substituting it with the new one.

void vl_svmpegasos_set_permutation ( VlSvmPegasos self,
vl_uint32 p,
vl_size  psize 
)
inline
Parameters:
selfPegasos Svm Solver.
ppermutation.
psizepermutation size.
void vl_svmpegasos_set_random_generator ( VlSvmPegasos self,
VlRand r 
)
inline
Parameters:
selfPegasos Svm Solver.
rrandom generator.
vl_svmpegasos_train ( VlSvmPegasos svm,
void *  data,
vl_size  numSamples,
VlSvmDatasetInnerProduct  innerProduct,
VlSvmDatasetAccumulator  accumulator,
vl_int8 const *  labels 
)
Parameters:
svm(in & out) svm status.
datatraining vectors.
numSamplesnumber of training data vectors.
innerProductfunction defining the innerProduct between the model and a data point.
accumulatorfunction definint the sum between the model and a data point.
labelslabels of the training vectors.

The function runs PEGASOS on the specified data. The structure svm should be initialized using vl_svmpegasos_new. The vector svm->model must have the dimension equal to svm->dimension. if a bias is used, svm->biasMultiplier must be non-zero, and the output value will be saved in svm->bias.

The function runs PEGASOS for iterations t in the interval [svm->iterations, svm->maxIterations]. If the intial status is initializied using vl_svmpegasos_new svm->iterations is equal to zero.

PEGASOS select the next point for computing the gradient at random. If svm->randomGenerator is NULL, the default random generator (as returned by vl_get_rand()) is used.

Alternatively, if svm->permutation is not NULL, then points are sampled in the order specified by this vector of indexes (this is cycled through). In this way It is an error to set both svm->randomGenerator and svm->permutation to non-null values.

See the Overview overview for details.

vl_svmpegasos_train_validation_data ( VlSvmPegasos svm,
void *  data,
vl_size  numSamples,
VlSvmDatasetInnerProduct  innerProduct,
VlSvmDatasetAccumulator  accumulator,
vl_int8 const *  labels,
void *  validation,
vl_size  validationNumSamples,
vl_int8 const *  validationLabels 
)
Parameters:
svm(in & out) svm status.
datatraining vectors.
numSamplesnumber of training data vectors.
innerProductfunction defining the innerProduct between the model and a data point.
accumulatorfunction definint the sum between the model and a data point.
labelslabels of the training vectors.
validationvalidation data.
validationNumSamplesnumber of validation data vectors.
validationLabelslabels of the validation data.

The function is the same algorithm of vl_svmpegasos_train, but computes the objective function statistics on a validation dataset, instead of using the training dataset also for this purpose.

See also:
vl_svmpegasos_train