VLFeat includes a fast SVM solver, called
vl_svmpegasos. The function implements the Pegasos SVM
algorithm [1], with a few adds such online
Homogeneous kernel map expansion and SVM online statistics.
A simple example on how to use vl_svmpegasos is presented below. Let's first build the training data
Plotting X and y we have
Learning a linear classifier can be easily done with the following 2 lines of code:
where we first create a struct containing the training data
using vl_maketraining data and then we call the the SVM
solver. The output model w is plotted over the training
data in the following figure.
The output b is equal to 0 since the
training data admits an SVM model passing from the origins.
The output info is a struct containing some
statistic on the learned SVM:
It is also possible to use under some assumptions[2] an homogeneous kernel map expanded online inside the solver. This can be done with the following command:
The above code creates a training set without applying any homogeneous kernel map to the data. When the solver is called it will expand each data point with a Chi Squared kernel of period 2.
VLFeat allows to get statistics during the training process. It is
sufficient to pass a function handle to the solver. The function
will be then called every energyFrequency time.
The following function simply plots the SVM energy values for all the past iterations:
The energy value for the past iterations are kept in the
row vector energy. The following code produces a plot of the energy value in real-time during the learning process.