00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef VL_SVM_H
00020 #define VL_SVM_H
00021
00022 #include "generic.h"
00023 #include "svmdataset.h"
00024
00030 #ifndef __DOXYGEN__
00031 struct VlSvm_ ;
00032 typedef struct VlSvm_ VlSvm ;
00033 #else
00034 typedef OPAQUE VlSvm ;
00035 #endif
00036
00038 typedef enum
00039 {
00040 VlSvmSolverNone = 0,
00041 VlSvmSolverSgd = 1,
00042 VlSvmSolverSdca
00043 } VlSvmSolverType ;
00044
00053 typedef enum
00054 {
00055 VlSvmLossHinge = 0,
00056 VlSvmLossHinge2 = 1,
00057 VlSvmLossL1,
00058 VlSvmLossL2,
00059 VlSvmLossLogistic
00060 } VlSvmLossType ;
00061
00063 typedef enum
00064 {
00065 VlSvmStatusTraining = 1,
00066 VlSvmStatusConverged,
00067 VlSvmStatusMaxNumIterationsReached
00068 } VlSvmSolverStatus ;
00069
00076 typedef struct VlSvmStatistics_ {
00077 VlSvmSolverStatus status ;
00078 vl_size iteration ;
00079 vl_size epoch ;
00080 double objective ;
00081 double regularizer ;
00082 double loss ;
00083 double dualObjective ;
00084 double dualLoss ;
00085 double dualityGap ;
00086 double scoresVariation ;
00087 double elapsedTime ;
00088 } VlSvmStatistics ;
00089
00092 VL_EXPORT VlSvm * vl_svm_new (VlSvmSolverType type,
00093 double const * data,
00094 vl_size dimension,
00095 vl_size numData,
00096 double const * labels,
00097 double lambda) ;
00098
00099 VL_EXPORT VlSvm * vl_svm_new_with_dataset (VlSvmSolverType type,
00100 VlSvmDataset * dataset,
00101 double const * labels,
00102 double lambda) ;
00103
00104 VL_EXPORT VlSvm * vl_svm_new_with_abstract_data (VlSvmSolverType type,
00105 void * data,
00106 vl_size dimension,
00107 vl_size numData,
00108 double const * labels,
00109 double lambda) ;
00110
00111 VL_EXPORT void vl_svm_delete (VlSvm * self) ;
00116 VL_EXPORT VlSvmStatistics const * vl_svm_get_statistics (VlSvm const *self) ;
00117 VL_EXPORT double const * vl_svm_get_model (VlSvm const *self) ;
00118 VL_EXPORT double vl_svm_get_bias (VlSvm const *self) ;
00119 VL_EXPORT vl_size vl_svm_get_dimension (VlSvm *self) ;
00120 VL_EXPORT vl_size vl_svm_get_num_data (VlSvm *self) ;
00121 VL_EXPORT double vl_svm_get_epsilon (VlSvm const *self) ;
00122 VL_EXPORT double vl_svm_get_bias_learning_rate (VlSvm const *self) ;
00123 VL_EXPORT vl_size vl_svm_get_max_num_iterations (VlSvm const *self) ;
00124 VL_EXPORT vl_size vl_svm_get_diagnostic_frequency (VlSvm const *self) ;
00125 VL_EXPORT VlSvmSolverType vl_svm_get_solver (VlSvm const *self) ;
00126 VL_EXPORT double vl_svm_get_bias_multiplier (VlSvm const *self) ;
00127 VL_EXPORT double vl_svm_get_lambda (VlSvm const *self) ;
00128 VL_EXPORT vl_size vl_svm_get_iteration_number (VlSvm const *self) ;
00129 VL_EXPORT double const * vl_svm_get_scores (VlSvm const *self) ;
00130 VL_EXPORT double const * vl_svm_get_weights (VlSvm const *self) ;
00135 VL_EXPORT void vl_svm_set_epsilon (VlSvm *self, double epsilon) ;
00136 VL_EXPORT void vl_svm_set_bias_learning_rate (VlSvm *self, double rate) ;
00137 VL_EXPORT void vl_svm_set_max_num_iterations (VlSvm *self, vl_size maxNumIterations) ;
00138 VL_EXPORT void vl_svm_set_diagnostic_frequency (VlSvm *self, vl_size f) ;
00139 VL_EXPORT void vl_svm_set_bias_multiplier (VlSvm *self, double b) ;
00140 VL_EXPORT void vl_svm_set_model (VlSvm *self, double const *model) ;
00141 VL_EXPORT void vl_svm_set_bias (VlSvm *self, double b) ;
00142 VL_EXPORT void vl_svm_set_iteration_number (VlSvm *self, vl_uindex n) ;
00143 VL_EXPORT void vl_svm_set_weights (VlSvm *self, double const *weights) ;
00144
00145 VL_EXPORT void vl_svm_set_diagnostic_function (VlSvm *self, VlSvmDiagnosticFunction f, void *data) ;
00146 VL_EXPORT void vl_svm_set_loss_function (VlSvm *self, VlSvmLossFunction f) ;
00147 VL_EXPORT void vl_svm_set_loss_derivative_function (VlSvm *self, VlSvmLossFunction f) ;
00148 VL_EXPORT void vl_svm_set_conjugate_loss_function (VlSvm *self, VlSvmLossFunction f) ;
00149 VL_EXPORT void vl_svm_set_dca_update_function (VlSvm *self, VlSvmDcaUpdateFunction f) ;
00150 VL_EXPORT void vl_svm_set_data_functions (VlSvm *self, VlSvmInnerProductFunction inner, VlSvmAccumulateFunction acc) ;
00151 VL_EXPORT void vl_svm_set_loss (VlSvm *self, VlSvmLossType loss) ;
00156 VL_EXPORT void vl_svm_train (VlSvm * self) ;
00163
00164 VL_EXPORT double vl_svm_hinge_loss (double label, double inner) ;
00165 VL_EXPORT double vl_svm_hinge_loss_derivative (double label, double inner) ;
00166 VL_EXPORT double vl_svm_hinge_conjugate_loss (double label, double u) ;
00167 VL_EXPORT double vl_svm_hinge_dca_update (double alpha, double inner, double norm2, double label) ;
00168
00169
00170 VL_EXPORT double vl_svm_hinge2_loss (double label, double inner) ;
00171 VL_EXPORT double vl_svm_hinge2_loss_derivative (double label, double inner) ;
00172 VL_EXPORT double vl_svm_hinge2_conjugate_loss (double label, double u) ;
00173 VL_EXPORT double vl_svm_hinge2_dca_update (double alpha, double inner, double norm2, double label) ;
00174
00175
00176 VL_EXPORT double vl_svm_l1_loss (double label, double inner) ;
00177 VL_EXPORT double vl_svm_l1_loss_derivative (double label, double inner) ;
00178 VL_EXPORT double vl_svm_l1_conjugate_loss (double label, double u) ;
00179 VL_EXPORT double vl_svm_l1_dca_update (double alpha, double inner, double norm2, double label) ;
00180
00181
00182 VL_EXPORT double vl_svm_l2_loss (double label, double inner) ;
00183 VL_EXPORT double vl_svm_l2_loss_derivative (double label, double inner) ;
00184 VL_EXPORT double vl_svm_l2_conjugate_loss (double label, double u) ;
00185 VL_EXPORT double vl_svm_l2_dca_update (double alpha, double inner, double norm2, double label) ;
00186
00187
00188 VL_EXPORT double vl_svm_logistic_loss (double label, double inner) ;
00189 VL_EXPORT double vl_svm_logistic_loss_derivative (double label, double inner) ;
00190 VL_EXPORT double vl_svm_logistic_conjugate_loss (double label, double u) ;
00191 VL_EXPORT double vl_svm_logistic_dca_update (double alpha, double inner, double norm2, double label) ;
00194
00195 #endif