SubGradientLPM.h

Go to the documentation of this file.
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 
00069         inline void set_C(float64_t c1, float64_t c2) { C1=c1; C2=c2; }
00070 
00071         inline float64_t get_C1() { return C1; }
00072         inline float64_t get_C2() { return C2; }
00073 
00074         inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
00075         inline bool get_bias_enabled() { return use_bias; }
00076 
00077         inline void set_epsilon(float64_t eps) { epsilon=eps; }
00078         inline float64_t get_epsilon() { return epsilon; }
00079 
00080         inline void set_qpsize(int32_t q) { qpsize=q; }
00081         inline int32_t get_qpsize() { return qpsize; }
00082 
00083         inline void set_qpsize_max(int32_t q) { qpsize_max=q; }
00084         inline int32_t get_qpsize_max() { return qpsize_max; }
00085 
00086     protected:
00089         int32_t find_active(
00090             int32_t num_feat, int32_t num_vec, int32_t& num_active,
00091             int32_t& num_bound);
00092 
00095         void update_active(int32_t num_feat, int32_t num_vec);
00096 
00098         float64_t compute_objective(int32_t num_feat, int32_t num_vec);
00099 
00102         float64_t compute_min_subgradient(
00103             int32_t num_feat, int32_t num_vec, int32_t num_active,
00104             int32_t num_bound);
00105 
00107         float64_t line_search(int32_t num_feat, int32_t num_vec);
00108 
00110         void compute_projection(int32_t num_feat, int32_t num_vec);
00111 
00113         void update_projection(float64_t alpha, int32_t num_vec);
00114 
00116         void init(int32_t num_vec, int32_t num_feat);
00117         
00119         void cleanup();
00120 
00122         inline virtual const char* get_name() const { return "SubGradientLPM"; }
00123 
00124     protected:
00125         float64_t C1;
00126         float64_t C2;
00127         float64_t epsilon;
00128         float64_t work_epsilon;
00129         float64_t autoselected_epsilon;
00130         int32_t qpsize;
00131         int32_t qpsize_max;
00132         int32_t qpsize_limit;
00133         bool use_bias;
00134 
00135         int32_t last_it_noimprovement;
00136         int32_t num_it_noimprovement;
00137 
00138         //idx vectors of length num_vec
00139         uint8_t* active; // 0=not active, 1=active, 2=on boundary
00140         uint8_t* old_active;
00141         int32_t* idx_active;
00142         int32_t* idx_bound;
00143         int32_t delta_active;
00144         int32_t delta_bound;
00145         float64_t* proj;
00146         float64_t* tmp_proj;
00147         int32_t* tmp_proj_idx;
00148         
00149         //vector of length num_feat
00150         float64_t* sum_CXy_active;
00151         float64_t* v;
00152         float64_t* old_v;
00153         float64_t sum_Cy_active;
00154 
00155         //vector of length num_feat
00156         int32_t pos_idx;
00157         int32_t neg_idx;
00158         int32_t zero_idx;
00159         int32_t* w_pos;
00160         int32_t* w_zero;
00161         int32_t* w_neg;
00162         float64_t* grad_w;
00163         float64_t grad_b;
00164         float64_t* grad_proj;
00165         float64_t* hinge_point;
00166         int32_t* hinge_idx;
00167 
00168         //vectors/sym matrix of size qpsize_limit
00169         float64_t* beta;
00170 
00171         CCplex* solver;
00172         float64_t lpmtim;
00173 };
00174 }
00175 #endif //USE_CPLEX
00176 #endif //_SUBGRADIENTLPM_H___

SHOGUN Machine Learning Toolbox - Documentation