Support Vector Machines (SVM) - Implementation. More...
Go to the source code of this file.
Classes | |
struct | VlSvm_ |
Defines | |
#define | SETLOSS(x, y) |
Functions | |
void | _vl_svm_evaluate (VlSvm *self) |
void | _vl_svm_sdca_train (VlSvm *self) |
void | _vl_svm_sgd_train (VlSvm *self) |
void | _vl_svm_update_statistics (VlSvm *self) |
void | vl_svm_delete (VlSvm *self) |
Delete object. | |
double | vl_svm_get_bias (VlSvm const *self) |
Get the value of the bias. | |
double | vl_svm_get_bias_learning_rate (VlSvm const *self) |
Get the bias leraning rate. | |
double | vl_svm_get_bias_multiplier (VlSvm const *self) |
Get the bias multiplier. | |
vl_size | vl_svm_get_diagnostic_frequency (VlSvm const *self) |
Get the diagnostic frequency. | |
vl_size | vl_svm_get_dimension (VlSvm *self) |
Get the model dimenison. | |
double | vl_svm_get_epsilon (VlSvm const *self) |
Get the convergence threshold. | |
vl_size | vl_svm_get_iteration_number (VlSvm const *self) |
Get the current iteration number. | |
double | vl_svm_get_lambda (VlSvm const *self) |
Get the regularizer parameter lambda. | |
vl_size | vl_svm_get_max_num_iterations (VlSvm const *self) |
Get the maximum number of iterations. | |
double const * | vl_svm_get_model (VlSvm const *self) |
Get the SVM model. | |
vl_size | vl_svm_get_num_data (VlSvm *self) |
Get the number of data samples. | |
double const * | vl_svm_get_scores (VlSvm const *self) |
Get the scores of the data points. | |
VlSvmSolverType | vl_svm_get_solver (VlSvm const *self) |
Get the SVM solver type. | |
VlSvmStatistics const * | vl_svm_get_statistics (VlSvm const *self) |
Get the solver statistics. | |
double const * | vl_svm_get_weights (VlSvm const *self) |
Get the data weights. | |
double | vl_svm_hinge2_conjugate_loss (double u, double label) |
SVM square hinge loss conjugate. | |
double | vl_svm_hinge2_dca_update (double alpha, double inner, double norm2, double label) |
SVM square hinge loss DCA update. | |
double | vl_svm_hinge2_loss (double inner, double label) |
SVM square hinge loss. | |
double | vl_svm_hinge2_loss_derivative (double inner, double label) |
SVM square hinge loss derivative. | |
double | vl_svm_hinge_conjugate_loss (double u, double label) |
SVM hinge loss conjugate. | |
double | vl_svm_hinge_dca_update (double alpha, double inner, double norm2, double label) |
SVM hinge loss DCA update. | |
double | vl_svm_hinge_loss (double inner, double label) |
SVM hinge loss. | |
double | vl_svm_hinge_loss_derivative (double inner, double label) |
SVM hinge loss derivative. | |
double | vl_svm_l1_conjugate_loss (double u, double label) |
SVM l1 loss conjugate. | |
double | vl_svm_l1_dca_update (double alpha, double inner, double norm2, double label) |
SVM l1 loss DCA update. | |
double | vl_svm_l1_loss (double inner, double label) |
SVM l1 loss. | |
double | vl_svm_l1_loss_derivative (double inner, double label) |
SVM l1 loss derivative. | |
double | vl_svm_l2_conjugate_loss (double u, double label) |
SVM l2 loss conjugate. | |
double | vl_svm_l2_dca_update (double alpha, double inner, double norm2, double label) |
SVM l2 loss DCA update. | |
double | vl_svm_l2_loss (double inner, double label) |
SVM l2 loss. | |
double | vl_svm_l2_loss_derivative (double inner, double label) |
SVM l2 loss derivative. | |
double | vl_svm_logistic_conjugate_loss (double u, double label) |
SVM l2 loss conjugate. | |
double | vl_svm_logistic_dca_update (double alpha, double inner, double norm2, double label) |
SVM l2 loss DCA update. | |
double | vl_svm_logistic_loss (double inner, double label) |
SVM l2 loss. | |
double | vl_svm_logistic_loss_derivative (double inner, double label) |
SVM l2 loss derivative. | |
VlSvm * | vl_svm_new (VlSvmSolverType type, double const *data, vl_size dimension, vl_size numData, double const *labels, double lambda) |
Create a new object with plain data. | |
VlSvm * | vl_svm_new_with_abstract_data (VlSvmSolverType solver, void *data, vl_size dimension, vl_size numData, double const *labels, double lambda) |
Create a new object with abstract data. | |
VlSvm * | vl_svm_new_with_dataset (VlSvmSolverType solver, VlSvmDataset *dataset, double const *labels, double lambda) |
Create a new object with a dataset. | |
void | vl_svm_set_bias (VlSvm *self, double b) |
Set the SVM bias. | |
void | vl_svm_set_bias_learning_rate (VlSvm *self, double rate) |
Set the bias learning rate. | |
void | vl_svm_set_bias_multiplier (VlSvm *self, double b) |
Set the bias multiplier. | |
void | vl_svm_set_conjugate_loss_function (VlSvm *self, VlSvmLossFunction f) |
Set the conjugate loss function callback. | |
void | vl_svm_set_data_functions (VlSvm *self, VlSvmInnerProductFunction inner, VlSvmAccumulateFunction acc) |
Set the data functions. | |
void | vl_svm_set_dca_update_function (VlSvm *self, VlSvmDcaUpdateFunction f) |
Set the DCA update function callback. | |
void | vl_svm_set_diagnostic_frequency (VlSvm *self, vl_size f) |
Set the diagnostic frequency. | |
void | vl_svm_set_diagnostic_function (VlSvm *self, VlSvmDiagnosticFunction f, void *data) |
Set the diagnostic function callback. | |
void | vl_svm_set_epsilon (VlSvm *self, double epsilon) |
Set the convergence threshold. | |
void | vl_svm_set_iteration_number (VlSvm *self, vl_uindex n) |
Set the current iteratio number. | |
void | vl_svm_set_lambda (VlSvm *self, double lambda) |
Set the regularizer parameter lambda. | |
void | vl_svm_set_loss (VlSvm *self, VlSvmLossType loss) |
Set the loss function to one of the default types. | |
void | vl_svm_set_loss_derivative_function (VlSvm *self, VlSvmLossFunction f) |
Set the loss derivative function callback. | |
void | vl_svm_set_loss_function (VlSvm *self, VlSvmLossFunction f) |
Set the loss function callback. | |
void | vl_svm_set_max_num_iterations (VlSvm *self, vl_size n) |
Set the maximum number of iterations. | |
void | vl_svm_set_model (VlSvm *self, double const *model) |
Set the SVM model. | |
void | vl_svm_set_weights (VlSvm *self, double const *weights) |
Set the data weights. | |
void | vl_svm_train (VlSvm *self) |
Run the SVM solver. | |
VL_INLINE double | xlogx (double x) |
Support Vector Machines (SVM) - Implementation.
Definition in file svm.c.
#define SETLOSS | ( | x, | |
y | |||
) |
case VlSvmLoss ## x: \ vl_svm_set_loss_function(self, vl_svm_ ## y ## _loss) ; \ vl_svm_set_loss_derivative_function(self, vl_svm_ ## y ## _loss_derivative) ; \ vl_svm_set_conjugate_loss_function(self, vl_svm_ ## y ## _conjugate_loss) ; \ vl_svm_set_dca_update_function(self, vl_svm_ ## y ## _dca_update) ; \ break;
void _vl_svm_evaluate | ( | VlSvm * | self | ) |
void _vl_svm_sdca_train | ( | VlSvm * | self | ) |
void _vl_svm_sgd_train | ( | VlSvm * | self | ) |
void _vl_svm_update_statistics | ( | VlSvm * | self | ) |
void vl_svm_delete | ( | VlSvm * | self | ) |
double vl_svm_get_bias | ( | VlSvm const * | self | ) |
double vl_svm_get_bias_learning_rate | ( | VlSvm const * | self | ) |
double vl_svm_get_bias_multiplier | ( | VlSvm const * | self | ) |
vl_size vl_svm_get_diagnostic_frequency | ( | VlSvm const * | self | ) |
vl_size vl_svm_get_dimension | ( | VlSvm * | self | ) |
double vl_svm_get_epsilon | ( | VlSvm const * | self | ) |
vl_size vl_svm_get_iteration_number | ( | VlSvm const * | self | ) |
double vl_svm_get_lambda | ( | VlSvm const * | self | ) |
vl_size vl_svm_get_max_num_iterations | ( | VlSvm const * | self | ) |
double const* vl_svm_get_model | ( | VlSvm const * | self | ) |
vl_size vl_svm_get_num_data | ( | VlSvm * | self | ) |
double const* vl_svm_get_scores | ( | VlSvm const * | self | ) |
VlSvmSolverType vl_svm_get_solver | ( | VlSvm const * | self | ) |
VlSvmStatistics const* vl_svm_get_statistics | ( | VlSvm const * | self | ) |
double const* vl_svm_get_weights | ( | VlSvm const * | self | ) |
double vl_svm_hinge2_conjugate_loss | ( | double | u, |
double | label | ||
) |
double vl_svm_hinge2_dca_update | ( | double | alpha, |
double | inner, | ||
double | norm2, | ||
double | label | ||
) |
SVM square hinge loss DCA update.
alpha | current value of the dual variable. |
inner | inner product $^ $ of the sample with the SVM model. |
norm2 | normalization factor $\|\|^2/ n$. |
label | label $y$ of the sample. |
double vl_svm_hinge2_loss | ( | double | inner, |
double | label | ||
) |
SVM square hinge loss.
inner | inner product between sample and model $^ $. |
label | sample label $y$. |
The interface is the same for a loss function, its derivative, or the conjugate loss.
double vl_svm_hinge2_loss_derivative | ( | double | inner, |
double | label | ||
) |
SVM square hinge loss derivative.
inner | inner product between sample and model $^ $. |
label | sample label $y$. |
The interface is the same for a loss function, its derivative, or the conjugate loss.
double vl_svm_hinge_conjugate_loss | ( | double | u, |
double | label | ||
) |
double vl_svm_hinge_dca_update | ( | double | alpha, |
double | inner, | ||
double | norm2, | ||
double | label | ||
) |
SVM hinge loss DCA update.
alpha | current value of the dual variable. |
inner | inner product $^ $ of the sample with the SVM model. |
norm2 | normalization factor $\|\|^2/ n$. |
label | label $y$ of the sample. |
double vl_svm_hinge_loss | ( | double | inner, |
double | label | ||
) |
SVM hinge loss.
inner | inner product between sample and model $^ $. |
label | sample label $y$. |
The interface is the same for a loss function, its derivative, or the conjugate loss.
double vl_svm_hinge_loss_derivative | ( | double | inner, |
double | label | ||
) |
SVM hinge loss derivative.
inner | inner product between sample and model $^ $. |
label | sample label $y$. |
The interface is the same for a loss function, its derivative, or the conjugate loss.
double vl_svm_l1_conjugate_loss | ( | double | u, |
double | label | ||
) |
double vl_svm_l1_dca_update | ( | double | alpha, |
double | inner, | ||
double | norm2, | ||
double | label | ||
) |
SVM l1 loss DCA update.
alpha | current value of the dual variable. |
inner | inner product $^ $ of the sample with the SVM model. |
norm2 | normalization factor $\|\|^2/ n$. |
label | label $y$ of the sample. |
double vl_svm_l1_loss | ( | double | inner, |
double | label | ||
) |
SVM l1 loss.
inner | inner product between sample and model $^ $. |
label | sample label $y$. |
The interface is the same for a loss function, its derivative, or the conjugate loss.
double vl_svm_l1_loss_derivative | ( | double | inner, |
double | label | ||
) |
SVM l1 loss derivative.
inner | inner product between sample and model $^ $. |
label | sample label $y$. |
The interface is the same for a loss function, its derivative, or the conjugate loss.
double vl_svm_l2_conjugate_loss | ( | double | u, |
double | label | ||
) |
double vl_svm_l2_dca_update | ( | double | alpha, |
double | inner, | ||
double | norm2, | ||
double | label | ||
) |
SVM l2 loss DCA update.
alpha | current value of the dual variable. |
inner | inner product $^ $ of the sample with the SVM model. |
norm2 | normalization factor $\|\|^2/ n$. |
label | label $y$ of the sample. |
double vl_svm_l2_loss | ( | double | inner, |
double | label | ||
) |
SVM l2 loss.
inner | inner product between sample and model $^ $. |
label | sample label $y$. |
The interface is the same for a loss function, its derivative, or the conjugate loss.
double vl_svm_l2_loss_derivative | ( | double | inner, |
double | label | ||
) |
SVM l2 loss derivative.
inner | inner product between sample and model $^ $. |
label | sample label $y$. |
The interface is the same for a loss function, its derivative, or the conjugate loss.
double vl_svm_logistic_conjugate_loss | ( | double | u, |
double | label | ||
) |
double vl_svm_logistic_dca_update | ( | double | alpha, |
double | inner, | ||
double | norm2, | ||
double | label | ||
) |
SVM l2 loss DCA update.
alpha | current value of the dual variable. |
inner | inner product $^ $ of the sample with the SVM model. |
norm2 | normalization factor $\|\|^2/ n$. |
label | label $y$ of the sample. |
double vl_svm_logistic_loss | ( | double | inner, |
double | label | ||
) |
SVM l2 loss.
inner | inner product between sample and model $^ $. |
label | sample label $y$. |
The interface is the same for a loss function, its derivative, or the conjugate loss.
double vl_svm_logistic_loss_derivative | ( | double | inner, |
double | label | ||
) |
SVM l2 loss derivative.
inner | inner product between sample and model $^ $. |
label | sample label $y$. |
The interface is the same for a loss function, its derivative, or the conjugate loss.
VlSvm* vl_svm_new | ( | VlSvmSolverType | type, |
double const * | data, | ||
vl_size | dimension, | ||
vl_size | numData, | ||
double const * | labels, | ||
double | lambda | ||
) |
Create a new object with plain data.
type | type of SMV solver. |
data | a pointer to a matrix of data. |
dimension | dimension of the SVM model. |
numData | number of training samples. |
labels | training labels. |
lambda | regularizer parameter. |
data has one column per sample, in double
format. More advanced inputs can be used with vl_svm_new_with_dataset and vl_svm_new_with_abstract_data.
VlSvm* vl_svm_new_with_abstract_data | ( | VlSvmSolverType | solver, |
void * | data, | ||
vl_size | dimension, | ||
vl_size | numData, | ||
double const * | labels, | ||
double | lambda | ||
) |
Create a new object with abstract data.
solver | type of SMV solver. |
data | pointer to the data. |
dimension | dimension of the SVM model. |
numData | num training samples. |
labels | training samples labels. |
lambda | regularizer parameter. |
After calling this function, vl_svm_set_data_functions *must* be used to setup suitable callbacks for the inner product and accumulation operations (
VlSvm* vl_svm_new_with_dataset | ( | VlSvmSolverType | solver, |
VlSvmDataset * | dataset, | ||
double const * | labels, | ||
double | lambda | ||
) |
Create a new object with a dataset.
solver | type of SMV solver. |
dataset | SVM dataset object |
labels | training samples labels. |
lambda | regularizer parameter. |
void vl_svm_set_bias | ( | VlSvm * | self, |
double | b | ||
) |
Set the SVM bias.
self | object. |
b | bias. |
The function set the internal representation of the SVM bias to be equal to b (the bias multiplier is applied). The same remark that applies to vl_svm_set_model applies here too.
void vl_svm_set_bias_learning_rate | ( | VlSvm * | self, |
double | rate | ||
) |
void vl_svm_set_bias_multiplier | ( | VlSvm * | self, |
double | b | ||
) |
Set the bias multiplier.
self | object |
b | bias multiplier. |
The *bias multiplier* is the value of the constant feature appended to the data vectors to implement the bias (Adding a bias).
void vl_svm_set_conjugate_loss_function | ( | VlSvm * | self, |
VlSvmLossFunction | f | ||
) |
Set the conjugate loss function callback.
self | object. |
f | loss function callback. |
Note that setting up a loss requires specifying more than just one callback. See Loss functions for details.
.void vl_svm_set_data_functions | ( | VlSvm * | self, |
VlSvmInnerProductFunction | inner, | ||
VlSvmAccumulateFunction | acc | ||
) |
void vl_svm_set_dca_update_function | ( | VlSvm * | self, |
VlSvmDcaUpdateFunction | f | ||
) |
Set the DCA update function callback.
self | object. |
f | loss function callback. |
Note that setting up a loss requires specifying more than just one callback. See Loss functions for details.
.void vl_svm_set_diagnostic_frequency | ( | VlSvm * | self, |
vl_size | f | ||
) |
void vl_svm_set_diagnostic_function | ( | VlSvm * | self, |
VlSvmDiagnosticFunction | f, | ||
void * | data | ||
) |
void vl_svm_set_epsilon | ( | VlSvm * | self, |
double | epsilon | ||
) |
void vl_svm_set_iteration_number | ( | VlSvm * | self, |
vl_uindex | n | ||
) |
void vl_svm_set_lambda | ( | VlSvm * | self, |
double | lambda | ||
) |
Set the regularizer parameter lambda.
self | object. |
lambda | regularizer parameter. |
Note that lambda is usually set when calling a constructor for VlSvm as certain parameters, such as the maximum number of iterations, are tuned accordingly. This tuning is not performed when lambda is changed using this function.
void vl_svm_set_loss | ( | VlSvm * | self, |
VlSvmLossType | loss | ||
) |
Set the loss function to one of the default types.
self | object. |
loss | type of loss function. |
void vl_svm_set_loss_derivative_function | ( | VlSvm * | self, |
VlSvmLossFunction | f | ||
) |
Set the loss derivative function callback.
self | object. |
f | loss function callback. |
Note that setting up a loss requires specifying more than just one callback. See Loss functions for details.
.void vl_svm_set_loss_function | ( | VlSvm * | self, |
VlSvmLossFunction | f | ||
) |
Set the loss function callback.
self | object. |
f | loss function callback. |
Note that setting up a loss requires specifying more than just one callback. See Loss functions for details.
void vl_svm_set_max_num_iterations | ( | VlSvm * | self, |
vl_size | n | ||
) |
void vl_svm_set_model | ( | VlSvm * | self, |
double const * | model | ||
) |
void vl_svm_set_weights | ( | VlSvm * | self, |
double const * | weights | ||
) |
Set the data weights.
self | object. |
weights | data weights. |
weights must be an array of non-negative weights. The loss of each data point is multiplied by the corresponding weight.
Set weights to NULL
to weight the data uniformly by 1 (default).
Note that the weights array is *not* copied and must be valid througout the object lifetime (unless it is replaced).
void vl_svm_train | ( | VlSvm * | self | ) |
Run the SVM solver.
self | object. |
The data on which the SVM operates is passed upon the cration of the VlSvm object. This function runs a solver to learn a corresponding model. See Getting started.