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 
00046 class CSubGradientLPM : public CLinearClassifier
00047 {
00048     public:
00049         CSubGradientLPM();
00050         CSubGradientLPM(
00051             float64_t C, CDotFeatures* traindat,
00052             CLabels* trainlab);
00053         virtual ~CSubGradientLPM();
00054 
00055         virtual inline EClassifierType get_classifier_type() { return CT_SUBGRADIENTLPM; }
00056         virtual bool train();
00057 
00058         inline void set_C(float64_t c1, float64_t c2) { C1=c1; C2=c2; }
00059 
00060         inline float64_t get_C1() { return C1; }
00061         inline float64_t get_C2() { return C2; }
00062 
00063         inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
00064         inline bool get_bias_enabled() { return use_bias; }
00065 
00066         inline void set_epsilon(float64_t eps) { epsilon=eps; }
00067         inline float64_t get_epsilon() { return epsilon; }
00068 
00069         inline void set_qpsize(int32_t q) { qpsize=q; }
00070         inline int32_t get_qpsize() { return qpsize; }
00071 
00072         inline void set_qpsize_max(int32_t q) { qpsize_max=q; }
00073         inline int32_t get_qpsize_max() { return qpsize_max; }
00074 
00075     protected:
00078         int32_t find_active(
00079             int32_t num_feat, int32_t num_vec, int32_t& num_active,
00080             int32_t& num_bound);
00081 
00084         void update_active(int32_t num_feat, int32_t num_vec);
00085 
00087         float64_t compute_objective(int32_t num_feat, int32_t num_vec);
00088 
00091         float64_t compute_min_subgradient(
00092             int32_t num_feat, int32_t num_vec, int32_t num_active,
00093             int32_t num_bound);
00094 
00096         float64_t line_search(int32_t num_feat, int32_t num_vec);
00097 
00099         void compute_projection(int32_t num_feat, int32_t num_vec);
00100 
00102         void update_projection(float64_t alpha, int32_t num_vec);
00103 
00105         void init(int32_t num_vec, int32_t num_feat);
00106         
00108         void cleanup();
00109 
00111         inline virtual const char* get_name() const { return "SubGradientLPM"; }
00112 
00113     protected:
00114         float64_t C1;
00115         float64_t C2;
00116         float64_t epsilon;
00117         float64_t work_epsilon;
00118         float64_t autoselected_epsilon;
00119         int32_t qpsize;
00120         int32_t qpsize_max;
00121         int32_t qpsize_limit;
00122         bool use_bias;
00123 
00124         int32_t last_it_noimprovement;
00125         int32_t num_it_noimprovement;
00126 
00127         //idx vectors of length num_vec
00128         uint8_t* active; // 0=not active, 1=active, 2=on boundary
00129         uint8_t* old_active;
00130         int32_t* idx_active;
00131         int32_t* idx_bound;
00132         int32_t delta_active;
00133         int32_t delta_bound;
00134         float64_t* proj;
00135         float64_t* tmp_proj;
00136         int32_t* tmp_proj_idx;
00137         
00138         //vector of length num_feat
00139         float64_t* sum_CXy_active;
00140         float64_t* v;
00141         float64_t* old_v;
00142         float64_t sum_Cy_active;
00143 
00144         //vector of length num_feat
00145         int32_t pos_idx;
00146         int32_t neg_idx;
00147         int32_t zero_idx;
00148         int32_t* w_pos;
00149         int32_t* w_zero;
00150         int32_t* w_neg;
00151         float64_t* grad_w;
00152         float64_t grad_b;
00153         float64_t* grad_proj;
00154         float64_t* hinge_point;
00155         int32_t* hinge_idx;
00156 
00157         //vectors/sym matrix of size qpsize_limit
00158         float64_t* beta;
00159 
00160         CCplex* solver;
00161 };
00162 #endif //USE_CPLEX
00163 #endif //_SUBGRADIENTLPM_H___

SHOGUN Machine Learning Toolbox - Documentation