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 <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/labels/Labels.h>
00025 
00026 namespace shogun
00027 {
00048 class CSubGradientLPM : public CLinearMachine
00049 {
00050     public:
00051         MACHINE_PROBLEM_TYPE(PT_BINARY);
00052 
00053         CSubGradientLPM();
00054         CSubGradientLPM(
00055             float64_t C, CDotFeatures* traindat,
00056             CLabels* trainlab);
00057         virtual ~CSubGradientLPM();
00058 
00059         virtual EMachineType get_classifier_type() { return CT_SUBGRADIENTLPM; }
00060 
00067         inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
00068 
00069         inline float64_t get_C1() { return C1; }
00070         inline float64_t get_C2() { return C2; }
00071 
00072         inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
00073         inline bool get_bias_enabled() { return use_bias; }
00074 
00075         inline void set_epsilon(float64_t eps) { epsilon=eps; }
00076         inline float64_t get_epsilon() { return epsilon; }
00077 
00078         inline void set_qpsize(int32_t q) { qpsize=q; }
00079         inline int32_t get_qpsize() { return qpsize; }
00080 
00081         inline void set_qpsize_max(int32_t q) { qpsize_max=q; }
00082         inline int32_t get_qpsize_max() { return qpsize_max; }
00083 
00084     protected:
00087         int32_t find_active(
00088             int32_t num_feat, int32_t num_vec, int32_t& num_active,
00089             int32_t& num_bound);
00090 
00093         void update_active(int32_t num_feat, int32_t num_vec);
00094 
00096         float64_t compute_objective(int32_t num_feat, int32_t num_vec);
00097 
00100         float64_t compute_min_subgradient(
00101             int32_t num_feat, int32_t num_vec, int32_t num_active,
00102             int32_t num_bound);
00103 
00105         float64_t line_search(int32_t num_feat, int32_t num_vec);
00106 
00108         void compute_projection(int32_t num_feat, int32_t num_vec);
00109 
00111         void update_projection(float64_t alpha, int32_t num_vec);
00112 
00114         void init(int32_t num_vec, int32_t num_feat);
00115 
00117         void cleanup();
00118 
00120         virtual const char* get_name() const { return "SubGradientLPM"; }
00121 
00122     protected:
00131         virtual bool train_machine(CFeatures* data=NULL);
00132 
00133     protected:
00134         float64_t C1;
00135         float64_t C2;
00136         float64_t epsilon;
00137         float64_t work_epsilon;
00138         float64_t autoselected_epsilon;
00139         int32_t qpsize;
00140         int32_t qpsize_max;
00141         int32_t qpsize_limit;
00142         bool use_bias;
00143 
00144         int32_t last_it_noimprovement;
00145         int32_t num_it_noimprovement;
00146 
00147         //idx vectors of length num_vec
00148         uint8_t* active; // 0=not active, 1=active, 2=on boundary
00149         uint8_t* old_active;
00150         int32_t* idx_active;
00151         int32_t* idx_bound;
00152         int32_t delta_active;
00153         int32_t delta_bound;
00154         float64_t* proj;
00155         float64_t* tmp_proj;
00156         int32_t* tmp_proj_idx;
00157 
00158         //vector of length num_feat
00159         float64_t* sum_CXy_active;
00160         float64_t* v;
00161         float64_t* old_v;
00162         float64_t sum_Cy_active;
00163 
00164         //vector of length num_feat
00165         int32_t pos_idx;
00166         int32_t neg_idx;
00167         int32_t zero_idx;
00168         int32_t* w_pos;
00169         int32_t* w_zero;
00170         int32_t* w_neg;
00171         float64_t* grad_w;
00172         float64_t grad_b;
00173         float64_t* grad_proj;
00174         float64_t* hinge_point;
00175         int32_t* hinge_idx;
00176 
00177         //vectors/sym matrix of size qpsize_limit
00178         float64_t* beta;
00179 
00180         CCplex* solver;
00181         float64_t lpmtim;
00182 };
00183 }
00184 #endif //USE_CPLEX
00185 #endif //_SUBGRADIENTLPM_H___
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation