SHOGUN
v1.1.0
|
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 <shogun/lib/config.h> 00016 00017 #ifdef USE_CPLEX 00018 #include <shogun/lib/common.h> 00019 00020 #include <shogun/mathematics/Cplex.h> 00021 00022 #include <shogun/machine/LinearMachine.h> 00023 #include <shogun/features/Features.h> 00024 #include <shogun/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 00065 inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; } 00066 00067 inline float64_t get_C1() { return C1; } 00068 inline float64_t get_C2() { return C2; } 00069 00070 inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; } 00071 inline bool get_bias_enabled() { return use_bias; } 00072 00073 inline void set_epsilon(float64_t eps) { epsilon=eps; } 00074 inline float64_t get_epsilon() { return epsilon; } 00075 00076 inline void set_qpsize(int32_t q) { qpsize=q; } 00077 inline int32_t get_qpsize() { return qpsize; } 00078 00079 inline void set_qpsize_max(int32_t q) { qpsize_max=q; } 00080 inline int32_t get_qpsize_max() { return qpsize_max; } 00081 00082 protected: 00085 int32_t find_active( 00086 int32_t num_feat, int32_t num_vec, int32_t& num_active, 00087 int32_t& num_bound); 00088 00091 void update_active(int32_t num_feat, int32_t num_vec); 00092 00094 float64_t compute_objective(int32_t num_feat, int32_t num_vec); 00095 00098 float64_t compute_min_subgradient( 00099 int32_t num_feat, int32_t num_vec, int32_t num_active, 00100 int32_t num_bound); 00101 00103 float64_t line_search(int32_t num_feat, int32_t num_vec); 00104 00106 void compute_projection(int32_t num_feat, int32_t num_vec); 00107 00109 void update_projection(float64_t alpha, int32_t num_vec); 00110 00112 void init(int32_t num_vec, int32_t num_feat); 00113 00115 void cleanup(); 00116 00118 inline virtual const char* get_name() const { return "SubGradientLPM"; } 00119 00120 protected: 00129 virtual bool train_machine(CFeatures* data=NULL); 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 //idx vectors of length num_vec 00146 uint8_t* active; // 0=not active, 1=active, 2=on boundary 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 //vector of length num_feat 00157 float64_t* sum_CXy_active; 00158 float64_t* v; 00159 float64_t* old_v; 00160 float64_t sum_Cy_active; 00161 00162 //vector of length num_feat 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 //vectors/sym matrix of size qpsize_limit 00176 float64_t* beta; 00177 00178 CCplex* solver; 00179 float64_t lpmtim; 00180 }; 00181 } 00182 #endif //USE_CPLEX 00183 #endif //_SUBGRADIENTLPM_H___