SVM Dataset. More...
Go to the source code of this file.
Typedefs | |
typedef struct VlSvmDataset_ | VlSvmDataset |
SVM dataset object. | |
SVM callbacks | |
typedef void(* | VlSvmDiagnosticFunction )(struct VlSvm_ *svm, void *data) |
SVM diagnostic function pointer. | |
typedef double(* | VlSvmLossFunction )(double inner, double label) |
SVM loss function pointer. | |
typedef double(* | VlSvmDcaUpdateFunction )(double alpha, double inner, double norm2, double label) |
SVM SDCA update function pointer. | |
typedef double(* | VlSvmInnerProductFunction )(const void *data, vl_uindex element, double *model) |
Pointer to a function that defines the inner product between the data point at position element and the SVM model. | |
typedef void(* | VlSvmAccumulateFunction )(const void *data, vl_uindex element, double *model, double multiplier) |
Pointer to a function that adds to model the data point at position element multiplied by the constant multiplier. | |
Functions | |
Create and destroy | |
VL_EXPORT VlSvmDataset * | vl_svmdataset_new (vl_type dataType, void *data, vl_size dimension, vl_size numData) |
Create a new object wrapping a dataset. | |
VL_EXPORT void | vl_svmdataset_delete (VlSvmDataset *dataset) |
Delete the object. | |
Set parameters | |
VL_EXPORT void | vl_svmdataset_set_homogeneous_kernel_map (VlSvmDataset *self, VlHomogeneousKernelMap *hom) |
Set the homogeneous kernel map object. | |
Get data and parameters | |
VL_EXPORT void * | vl_svmdataset_get_data (VlSvmDataset const *self) |
Get the wrapped data. | |
VL_EXPORT vl_size | vl_svmdataset_get_num_data (VlSvmDataset const *self) |
Get the number of wrapped data elements. | |
VL_EXPORT vl_size | vl_svmdataset_get_dimension (VlSvmDataset const *self) |
Get the dimension of the wrapped data. | |
VL_EXPORT void * | vl_svmdataset_get_map (VlSvmDataset const *self) |
VL_EXPORT vl_size | vl_svmdataset_get_mapDim (VlSvmDataset const *self) |
VL_EXPORT VlSvmAccumulateFunction | vl_svmdataset_get_accumulate_function (VlSvmDataset const *self) |
Get the accumulate function. | |
VL_EXPORT VlSvmInnerProductFunction | vl_svmdataset_get_inner_product_function (VlSvmDataset const *self) |
Get the inner product function. | |
VL_EXPORT VlHomogeneousKernelMap * | vl_svmdataset_get_homogeneous_kernel_map (VlSvmDataset const *self) |
Get the homogeneous kernel map object. |
SVM Dataset.
The SVM solver object VlSvm, supporting SVM learning in VLFeat, uses an abstraction mechanism to work on arbitrary data types. This module provides an helper object, VlSvmDataset, that simplify taking advantage of this functionality, supporting for example different data types and the computation of feature maps out of the box.
As discussed in Advanced SVM topics, most linear SVM solvers, such as the ones implemented in VLFeat in Support Vector Machines (SVM), require only two operations to be defined on the data:
The SVM solver needs to know nothing about the data once these two operations are defined. These functions can do any number of things, such as supporting different formats for the data (dense or sparse, float or double), computing feature maps, or expanding compressed representations such as Product Quantization.
VLFeat provides the helper object VlSvmDataset to support some of these functionalities out of the box (it is important to remark that its use with the SVM solver VlSvm is entirely optional).
Presently, VlSvmDataset supports:
float
and double
dense arrays.For example, to learn a linear SVM on SINGLE data:
int main() { vl_size const numData = 4 ; vl_size const dimension = 2 ; single x [dimension * numData] = { 0.0, -0.5, 0.6, -0.3, 0.0, 0.5, 0.6, 0.0} ; double y [numData] = {1, 1, -1, 1} ; double lambda = 0.01; double * const model ; double bias ; VlSvmDataset * dataset = vl_svmdataset_new (VL_TYPE_SINGLE, x, dimension, numData) ; VlSvm * svm = vl_svm_new_with_dataset (VlSvmSolverSgd, dataset, y, lambda) ; vl_svm_train(svm) ; model = vl_svm_get_model(svm) ; bias = vl_svm_get_bias(svm) ; printf("model w = [ %f , %f ] , bias b = %f \n", model[0], model[1], bias); vl_svm_delete(svm) ; vl_svmdataset_delete(dataset) ; return 0; }
Definition in file svmdataset.h.
Pointer to a function that adds to model the data point at position element multiplied by the constant multiplier.
Definition at line 48 of file svmdataset.h.
SVM dataset object.
This objects contain a training set to be used in combination with the SVM solver object VlSvm. Its main purpose is to implement the two basic operations inner product (VlSvmInnerProductFunction) and accumulation (VlSvmAccumulateFunction).
See Support Vector Machines (SVM) and Advanced SVM topics for further information.
Definition at line 37 of file svmdataset.h.
SVM SDCA update function pointer.
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. |
Definition at line 46 of file svmdataset.h.
SVM diagnostic function pointer.
svm | is an instance of VlSvm . |
Definition at line 44 of file svmdataset.h.
Pointer to a function that defines the inner product between the data point at position element and the SVM model.
Definition at line 47 of file svmdataset.h.
SVM loss function pointer.
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.
Definition at line 45 of file svmdataset.h.
VL_EXPORT void vl_svmdataset_delete | ( | VlSvmDataset * | self | ) |
Delete the object.
self | object to delete. |
The function frees the resources allocated by vl_svmdataset_new(). Notice that the wrapped data will *not* be freed as it is not owned by the object.
Definition at line 164 of file svmdataset.c.
VL_EXPORT VlSvmAccumulateFunction vl_svmdataset_get_accumulate_function | ( | VlSvmDataset const * | self | ) |
Get the accumulate function.
self | object. |
Definition at line 260 of file svmdataset.c.
VL_EXPORT void* vl_svmdataset_get_data | ( | VlSvmDataset const * | self | ) |
Get the wrapped data.
self | object. |
Definition at line 179 of file svmdataset.c.
VL_EXPORT vl_size vl_svmdataset_get_dimension | ( | VlSvmDataset const * | self | ) |
Get the dimension of the wrapped data.
self | object. |
Definition at line 201 of file svmdataset.c.
VL_EXPORT VlHomogeneousKernelMap* vl_svmdataset_get_homogeneous_kernel_map | ( | VlSvmDataset const * | self | ) |
Get the homogeneous kernel map object.
self | object. |
NULL
if any). Definition at line 215 of file svmdataset.c.
VL_EXPORT VlSvmInnerProductFunction vl_svmdataset_get_inner_product_function | ( | VlSvmDataset const * | self | ) |
Get the inner product function.
self | object. |
Definition at line 291 of file svmdataset.c.
VL_EXPORT void* vl_svmdataset_get_map | ( | VlSvmDataset const * | self | ) |
VL_EXPORT vl_size vl_svmdataset_get_mapDim | ( | VlSvmDataset const * | self | ) |
VL_EXPORT vl_size vl_svmdataset_get_num_data | ( | VlSvmDataset const * | self | ) |
Get the number of wrapped data elements.
self | object. |
Definition at line 190 of file svmdataset.c.
VL_EXPORT VlSvmDataset* vl_svmdataset_new | ( | vl_type | dataType, |
void * | data, | ||
vl_size | dimension, | ||
vl_size | numData | ||
) |
Create a new object wrapping a dataset.
dataType | of data (float and double supported). |
data | pointer to the data. |
dimension | the dimension of a data vector. |
numData | number of wrapped data vectors. |
The function allocates and returns a new SVM dataset object wrapping the data pointed by data. Note that no copy is made of data, so the caller should keep the data allocated as the object exists.
Definition at line 138 of file svmdataset.c.
VL_EXPORT void vl_svmdataset_set_homogeneous_kernel_map | ( | VlSvmDataset * | self, |
VlHomogeneousKernelMap * | hom | ||
) |
Set the homogeneous kernel map object.
self | object. |
hom | homogeneous kernel map object to use. |
After changing the kernel map, the inner product and accumulator function should be queried again (vl_svmdataset_get_inner_product_function adn vl_svmdataset_get_accumulate_function).
Set this to NULL
to avoid using a kernel map.
Note that this does *not* transfer the ownership of the object to the function. Furthermore, VlSvmDataset holds to the object until it is destroyed or the object is replaced or removed by calling this function again.
Definition at line 238 of file svmdataset.c.