SubGradientSVM.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _SUBGRADIENTSVM_H___
00013 #define _SUBGRADIENTSVM_H___
00014
00015 #include "lib/common.h"
00016 #include "classifier/SparseLinearClassifier.h"
00017 #include "features/SparseFeatures.h"
00018 #include "features/Labels.h"
00019
00021 class CSubGradientSVM : public CSparseLinearClassifier
00022 {
00023 public:
00025 CSubGradientSVM();
00026
00033 CSubGradientSVM(
00034 float64_t C, CSparseFeatures<float64_t>* traindat,
00035 CLabels* trainlab);
00036 virtual ~CSubGradientSVM();
00037
00042 virtual inline EClassifierType get_classifier_type() { return CT_SUBGRADIENTSVM; }
00043
00048 virtual bool train();
00049
00055 inline void set_C(float64_t c1, float64_t c2) { C1=c1; C2=c2; }
00056
00061 inline float64_t get_C1() { return C1; }
00062
00067 inline float64_t get_C2() { return C2; }
00068
00073 inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
00074
00079 inline bool get_bias_enabled() { return use_bias; }
00080
00085 inline void set_epsilon(float64_t eps) { epsilon=eps; }
00086
00091 inline float64_t get_epsilon() { return epsilon; }
00092
00097 inline void set_qpsize(int32_t q) { qpsize=q; }
00098
00103 inline int32_t get_qpsize() { return qpsize; }
00104
00109 inline void set_qpsize_max(int32_t q) { qpsize_max=q; }
00110
00115 inline int32_t get_qpsize_max() { return qpsize_max; }
00116
00117 protected:
00120 int32_t find_active(
00121 int32_t num_feat, int32_t num_vec, int32_t& num_active,
00122 int32_t& num_bound);
00123
00126 void update_active(int32_t num_feat, int32_t num_vec);
00127
00129 float64_t compute_objective(int32_t num_feat, int32_t num_vec);
00130
00133 float64_t compute_min_subgradient(
00134 int32_t num_feat, int32_t num_vec, int32_t num_active,
00135 int32_t num_bound);
00136
00138 float64_t line_search(int32_t num_feat, int32_t num_vec);
00139
00141 void compute_projection(int32_t num_feat, int32_t num_vec);
00142
00144 void update_projection(float64_t alpha, int32_t num_vec);
00145
00147 void init(int32_t num_vec, int32_t num_feat);
00148
00150 void cleanup();
00151
00152 protected:
00154 float64_t C1;
00156 float64_t C2;
00158 float64_t epsilon;
00160 float64_t work_epsilon;
00162 float64_t autoselected_epsilon;
00164 int32_t qpsize;
00166 int32_t qpsize_max;
00168 int32_t qpsize_limit;
00170 bool use_bias;
00171
00173 int32_t last_it_noimprovement;
00175 int32_t num_it_noimprovement;
00176
00177
00179 uint8_t* active;
00181 uint8_t* old_active;
00183 int32_t* idx_active;
00185 int32_t* idx_bound;
00187 int32_t delta_active;
00189 int32_t delta_bound;
00191 float64_t* proj;
00193 float64_t* tmp_proj;
00195 int32_t* tmp_proj_idx;
00196
00197
00199 float64_t* sum_CXy_active;
00201 float64_t* v;
00203 float64_t* old_v;
00205 float64_t sum_Cy_active;
00206
00207
00209 float64_t* grad_w;
00211 float64_t grad_b;
00213 float64_t* grad_proj;
00215 float64_t* hinge_point;
00217 int32_t* hinge_idx;
00218
00219
00221 float64_t* beta;
00223 float64_t* old_beta;
00225 float64_t* Zv;
00227 float64_t* old_Zv;
00229 float64_t* Z;
00231 float64_t* old_Z;
00232 };
00233 #endif
00234