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/LinearClassifier.h"
00017 #include "features/DotFeatures.h"
00018 #include "features/Labels.h"
00019
00021 class CSubGradientSVM : public CLinearClassifier
00022 {
00023 public:
00025 CSubGradientSVM();
00026
00033 CSubGradientSVM(
00034 float64_t C, CDotFeatures* 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
00153 inline virtual const char* get_name() const { return "SubGradientSVM"; }
00154
00155 protected:
00157 float64_t C1;
00159 float64_t C2;
00161 float64_t epsilon;
00163 float64_t work_epsilon;
00165 float64_t autoselected_epsilon;
00167 int32_t qpsize;
00169 int32_t qpsize_max;
00171 int32_t qpsize_limit;
00173 bool use_bias;
00174
00176 int32_t last_it_noimprovement;
00178 int32_t num_it_noimprovement;
00179
00180
00182 uint8_t* active;
00184 uint8_t* old_active;
00186 int32_t* idx_active;
00188 int32_t* idx_bound;
00190 int32_t delta_active;
00192 int32_t delta_bound;
00194 float64_t* proj;
00196 float64_t* tmp_proj;
00198 int32_t* tmp_proj_idx;
00199
00200
00202 float64_t* sum_CXy_active;
00204 float64_t* v;
00206 float64_t* old_v;
00208 float64_t sum_Cy_active;
00209
00210
00212 float64_t* grad_w;
00214 float64_t grad_b;
00216 float64_t* grad_proj;
00218 float64_t* hinge_point;
00220 int32_t* hinge_idx;
00221
00222
00224 float64_t* beta;
00226 float64_t* old_beta;
00228 float64_t* Zv;
00230 float64_t* old_Zv;
00232 float64_t* Z;
00234 float64_t* old_Z;
00235 };
00236 #endif
00237