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
00020 namespace shogun
00021 {
00023 class CSubGradientSVM : public CLinearClassifier
00024 {
00025 public:
00027 CSubGradientSVM();
00028
00035 CSubGradientSVM(
00036 float64_t C, CDotFeatures* traindat,
00037 CLabels* trainlab);
00038 virtual ~CSubGradientSVM();
00039
00044 virtual inline EClassifierType get_classifier_type() { return CT_SUBGRADIENTSVM; }
00045
00054 virtual bool train(CFeatures* data=NULL);
00055
00061 inline void set_C(float64_t c1, float64_t c2) { C1=c1; C2=c2; }
00062
00067 inline float64_t get_C1() { return C1; }
00068
00073 inline float64_t get_C2() { return C2; }
00074
00079 inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
00080
00085 inline bool get_bias_enabled() { return use_bias; }
00086
00091 inline void set_epsilon(float64_t eps) { epsilon=eps; }
00092
00097 inline float64_t get_epsilon() { return epsilon; }
00098
00103 inline void set_qpsize(int32_t q) { qpsize=q; }
00104
00109 inline int32_t get_qpsize() { return qpsize; }
00110
00115 inline void set_qpsize_max(int32_t q) { qpsize_max=q; }
00116
00121 inline int32_t get_qpsize_max() { return qpsize_max; }
00122
00123 protected:
00126 int32_t find_active(
00127 int32_t num_feat, int32_t num_vec, int32_t& num_active,
00128 int32_t& num_bound);
00129
00132 void update_active(int32_t num_feat, int32_t num_vec);
00133
00135 float64_t compute_objective(int32_t num_feat, int32_t num_vec);
00136
00139 float64_t compute_min_subgradient(
00140 int32_t num_feat, int32_t num_vec, int32_t num_active,
00141 int32_t num_bound);
00142
00144 float64_t line_search(int32_t num_feat, int32_t num_vec);
00145
00147 void compute_projection(int32_t num_feat, int32_t num_vec);
00148
00150 void update_projection(float64_t alpha, int32_t num_vec);
00151
00153 void init(int32_t num_vec, int32_t num_feat);
00154
00156 void cleanup();
00157
00159 inline virtual const char* get_name() const { return "SubGradientSVM"; }
00160
00161 protected:
00163 float64_t C1;
00165 float64_t C2;
00167 float64_t epsilon;
00169 float64_t work_epsilon;
00171 float64_t autoselected_epsilon;
00173 int32_t qpsize;
00175 int32_t qpsize_max;
00177 int32_t qpsize_limit;
00179 bool use_bias;
00180
00182 int32_t last_it_noimprovement;
00184 int32_t num_it_noimprovement;
00185
00186
00188 uint8_t* active;
00190 uint8_t* old_active;
00192 int32_t* idx_active;
00194 int32_t* idx_bound;
00196 int32_t delta_active;
00198 int32_t delta_bound;
00200 float64_t* proj;
00202 float64_t* tmp_proj;
00204 int32_t* tmp_proj_idx;
00205
00206
00208 float64_t* sum_CXy_active;
00210 float64_t* v;
00212 float64_t* old_v;
00214 float64_t sum_Cy_active;
00215
00216
00218 float64_t* grad_w;
00220 float64_t grad_b;
00222 float64_t* grad_proj;
00224 float64_t* hinge_point;
00226 int32_t* hinge_idx;
00227
00228
00230 float64_t* beta;
00232 float64_t* old_beta;
00234 float64_t* Zv;
00236 float64_t* old_Zv;
00238 float64_t* Z;
00240 float64_t* old_Z;
00241
00243 float64_t tim;
00244 };
00245 }
00246 #endif