Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _SUBGRADIENTLPM_H___
00013 #define _SUBGRADIENTLPM_H___
00014
00015 #include "lib/config.h"
00016
00017 #ifdef USE_CPLEX
00018 #include "lib/common.h"
00019
00020 #include "lib/Cplex.h"
00021
00022 #include "classifier/LinearClassifier.h"
00023 #include "features/Features.h"
00024 #include "features/Labels.h"
00025
00026 namespace shogun
00027 {
00048 #define IGNORE_IN_CLASSLIST
00049 IGNORE_IN_CLASSLIST class CSubGradientLPM : public CLinearClassifier
00050 {
00051 public:
00052 CSubGradientLPM();
00053 CSubGradientLPM(
00054 float64_t C, CDotFeatures* traindat,
00055 CLabels* trainlab);
00056 virtual ~CSubGradientLPM();
00057
00058 virtual inline EClassifierType get_classifier_type() { return CT_SUBGRADIENTLPM; }
00059
00068 virtual bool train(CFeatures* data=NULL);
00069
00076 inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
00077
00078 inline float64_t get_C1() { return C1; }
00079 inline float64_t get_C2() { return C2; }
00080
00081 inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
00082 inline bool get_bias_enabled() { return use_bias; }
00083
00084 inline void set_epsilon(float64_t eps) { epsilon=eps; }
00085 inline float64_t get_epsilon() { return epsilon; }
00086
00087 inline void set_qpsize(int32_t q) { qpsize=q; }
00088 inline int32_t get_qpsize() { return qpsize; }
00089
00090 inline void set_qpsize_max(int32_t q) { qpsize_max=q; }
00091 inline int32_t get_qpsize_max() { return qpsize_max; }
00092
00093 protected:
00096 int32_t find_active(
00097 int32_t num_feat, int32_t num_vec, int32_t& num_active,
00098 int32_t& num_bound);
00099
00102 void update_active(int32_t num_feat, int32_t num_vec);
00103
00105 float64_t compute_objective(int32_t num_feat, int32_t num_vec);
00106
00109 float64_t compute_min_subgradient(
00110 int32_t num_feat, int32_t num_vec, int32_t num_active,
00111 int32_t num_bound);
00112
00114 float64_t line_search(int32_t num_feat, int32_t num_vec);
00115
00117 void compute_projection(int32_t num_feat, int32_t num_vec);
00118
00120 void update_projection(float64_t alpha, int32_t num_vec);
00121
00123 void init(int32_t num_vec, int32_t num_feat);
00124
00126 void cleanup();
00127
00129 inline virtual const char* get_name() const { return "SubGradientLPM"; }
00130
00131 protected:
00132 float64_t C1;
00133 float64_t C2;
00134 float64_t epsilon;
00135 float64_t work_epsilon;
00136 float64_t autoselected_epsilon;
00137 int32_t qpsize;
00138 int32_t qpsize_max;
00139 int32_t qpsize_limit;
00140 bool use_bias;
00141
00142 int32_t last_it_noimprovement;
00143 int32_t num_it_noimprovement;
00144
00145
00146 uint8_t* active;
00147 uint8_t* old_active;
00148 int32_t* idx_active;
00149 int32_t* idx_bound;
00150 int32_t delta_active;
00151 int32_t delta_bound;
00152 float64_t* proj;
00153 float64_t* tmp_proj;
00154 int32_t* tmp_proj_idx;
00155
00156
00157 float64_t* sum_CXy_active;
00158 float64_t* v;
00159 float64_t* old_v;
00160 float64_t sum_Cy_active;
00161
00162
00163 int32_t pos_idx;
00164 int32_t neg_idx;
00165 int32_t zero_idx;
00166 int32_t* w_pos;
00167 int32_t* w_zero;
00168 int32_t* w_neg;
00169 float64_t* grad_w;
00170 float64_t grad_b;
00171 float64_t* grad_proj;
00172 float64_t* hinge_point;
00173 int32_t* hinge_idx;
00174
00175
00176 float64_t* beta;
00177
00178 CCplex* solver;
00179 float64_t lpmtim;
00180 };
00181 }
00182 #endif //USE_CPLEX
00183 #endif //_SUBGRADIENTLPM_H___