|
SHOGUN v0.9.3
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2007-2009 Soeren Sonnenburg 00008 * Written (W) 2007-2008 Vojtech Franc 00009 * Copyright (C) 2007-2009 Fraunhofer Institute FIRST and Max-Planck-Society 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 class CSubGradientLPM : public CLinearClassifier 00049 { 00050 public: 00051 CSubGradientLPM(); 00052 CSubGradientLPM( 00053 float64_t C, CDotFeatures* traindat, 00054 CLabels* trainlab); 00055 virtual ~CSubGradientLPM(); 00056 00057 virtual inline EClassifierType get_classifier_type() { return CT_SUBGRADIENTLPM; } 00058 00067 virtual bool train(CFeatures* data=NULL); 00068 00075 inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; } 00076 00077 inline float64_t get_C1() { return C1; } 00078 inline float64_t get_C2() { return C2; } 00079 00080 inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; } 00081 inline bool get_bias_enabled() { return use_bias; } 00082 00083 inline void set_epsilon(float64_t eps) { epsilon=eps; } 00084 inline float64_t get_epsilon() { return epsilon; } 00085 00086 inline void set_qpsize(int32_t q) { qpsize=q; } 00087 inline int32_t get_qpsize() { return qpsize; } 00088 00089 inline void set_qpsize_max(int32_t q) { qpsize_max=q; } 00090 inline int32_t get_qpsize_max() { return qpsize_max; } 00091 00092 protected: 00095 int32_t find_active( 00096 int32_t num_feat, int32_t num_vec, int32_t& num_active, 00097 int32_t& num_bound); 00098 00101 void update_active(int32_t num_feat, int32_t num_vec); 00102 00104 float64_t compute_objective(int32_t num_feat, int32_t num_vec); 00105 00108 float64_t compute_min_subgradient( 00109 int32_t num_feat, int32_t num_vec, int32_t num_active, 00110 int32_t num_bound); 00111 00113 float64_t line_search(int32_t num_feat, int32_t num_vec); 00114 00116 void compute_projection(int32_t num_feat, int32_t num_vec); 00117 00119 void update_projection(float64_t alpha, int32_t num_vec); 00120 00122 void init(int32_t num_vec, int32_t num_feat); 00123 00125 void cleanup(); 00126 00128 inline virtual const char* get_name() const { return "SubGradientLPM"; } 00129 00130 protected: 00131 float64_t C1; 00132 float64_t C2; 00133 float64_t epsilon; 00134 float64_t work_epsilon; 00135 float64_t autoselected_epsilon; 00136 int32_t qpsize; 00137 int32_t qpsize_max; 00138 int32_t qpsize_limit; 00139 bool use_bias; 00140 00141 int32_t last_it_noimprovement; 00142 int32_t num_it_noimprovement; 00143 00144 //idx vectors of length num_vec 00145 uint8_t* active; // 0=not active, 1=active, 2=on boundary 00146 uint8_t* old_active; 00147 int32_t* idx_active; 00148 int32_t* idx_bound; 00149 int32_t delta_active; 00150 int32_t delta_bound; 00151 float64_t* proj; 00152 float64_t* tmp_proj; 00153 int32_t* tmp_proj_idx; 00154 00155 //vector of length num_feat 00156 float64_t* sum_CXy_active; 00157 float64_t* v; 00158 float64_t* old_v; 00159 float64_t sum_Cy_active; 00160 00161 //vector of length num_feat 00162 int32_t pos_idx; 00163 int32_t neg_idx; 00164 int32_t zero_idx; 00165 int32_t* w_pos; 00166 int32_t* w_zero; 00167 int32_t* w_neg; 00168 float64_t* grad_w; 00169 float64_t grad_b; 00170 float64_t* grad_proj; 00171 float64_t* hinge_point; 00172 int32_t* hinge_idx; 00173 00174 //vectors/sym matrix of size qpsize_limit 00175 float64_t* beta; 00176 00177 CCplex* solver; 00178 float64_t lpmtim; 00179 }; 00180 } 00181 #endif //USE_CPLEX 00182 #endif //_SUBGRADIENTLPM_H___