SubGradientLPM.h
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/SparseLinearClassifier.h"
00023 #include "features/SparseFeatures.h"
00024 #include "features/Labels.h"
00025
00026 class CSubGradientLPM : public CSparseLinearClassifier
00027 {
00028 public:
00029 CSubGradientLPM();
00030 CSubGradientLPM(
00031 float64_t C, CSparseFeatures<float64_t>* traindat,
00032 CLabels* trainlab);
00033 virtual ~CSubGradientLPM();
00034
00035 virtual inline EClassifierType get_classifier_type() { return CT_SUBGRADIENTLPM; }
00036 virtual bool train();
00037
00038 inline void set_C(float64_t c1, float64_t c2) { C1=c1; C2=c2; }
00039
00040 inline float64_t get_C1() { return C1; }
00041 inline float64_t get_C2() { return C2; }
00042
00043 inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
00044 inline bool get_bias_enabled() { return use_bias; }
00045
00046 inline void set_epsilon(float64_t eps) { epsilon=eps; }
00047 inline float64_t get_epsilon() { return epsilon; }
00048
00049 inline void set_qpsize(int32_t q) { qpsize=q; }
00050 inline int32_t get_qpsize() { return qpsize; }
00051
00052 inline void set_qpsize_max(int32_t q) { qpsize_max=q; }
00053 inline int32_t get_qpsize_max() { return qpsize_max; }
00054
00055 protected:
00058 int32_t find_active(
00059 int32_t num_feat, int32_t num_vec, int32_t& num_active,
00060 int32_t& num_bound);
00061
00064 void update_active(int32_t num_feat, int32_t num_vec);
00065
00067 float64_t compute_objective(int32_t num_feat, int32_t num_vec);
00068
00071 float64_t compute_min_subgradient(
00072 int32_t num_feat, int32_t num_vec, int32_t num_active,
00073 int32_t num_bound);
00074
00076 float64_t line_search(int32_t num_feat, int32_t num_vec);
00077
00079 void compute_projection(int32_t num_feat, int32_t num_vec);
00080
00082 void update_projection(float64_t alpha, int32_t num_vec);
00083
00085 void init(int32_t num_vec, int32_t num_feat);
00086
00088 void cleanup();
00089
00090 protected:
00091 float64_t C1;
00092 float64_t C2;
00093 float64_t epsilon;
00094 float64_t work_epsilon;
00095 float64_t autoselected_epsilon;
00096 int32_t qpsize;
00097 int32_t qpsize_max;
00098 int32_t qpsize_limit;
00099 bool use_bias;
00100
00101 int32_t last_it_noimprovement;
00102 int32_t num_it_noimprovement;
00103
00104
00105 uint8_t* active;
00106 uint8_t* old_active;
00107 int32_t* idx_active;
00108 int32_t* idx_bound;
00109 int32_t delta_active;
00110 int32_t delta_bound;
00111 float64_t* proj;
00112 float64_t* tmp_proj;
00113 int32_t* tmp_proj_idx;
00114
00115
00116 float64_t* sum_CXy_active;
00117 float64_t* v;
00118 float64_t* old_v;
00119 float64_t sum_Cy_active;
00120
00121
00122 int32_t pos_idx;
00123 int32_t neg_idx;
00124 int32_t zero_idx;
00125 int32_t* w_pos;
00126 int32_t* w_zero;
00127 int32_t* w_neg;
00128 float64_t* grad_w;
00129 float64_t grad_b;
00130 float64_t* grad_proj;
00131 float64_t* hinge_point;
00132 int32_t* hinge_idx;
00133
00134
00135 float64_t* beta;
00136
00137 CCplex* solver;
00138 };
00139 #endif //USE_CPLEX
00140 #endif //_SUBGRADIENTLPM_H___