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-2008 Soeren Sonnenburg
00008  * Written (W) 2007-2008 Vojtech Franc
00009  * Copyright (C) 2007-2008 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/SparseLinearClassifier.h"
00023 #include "features/SparseFeatures.h"
00024 #include "features/Labels.h"
00025 
00026 class CSubGradientLPM : public CSparseLinearClassifier
00027 {
00028     public:
00029         CSubGradientLPM();
00030         CSubGradientLPM(DREAL C, CSparseFeatures<DREAL>* traindat, CLabels* trainlab);
00031         virtual ~CSubGradientLPM();
00032 
00033         virtual inline EClassifierType get_classifier_type() { return CT_SUBGRADIENTLPM; }
00034         virtual bool train();
00035 
00036         inline void set_C(DREAL c1, DREAL c2) { C1=c1; C2=c2; }
00037 
00038         inline DREAL get_C1() { return C1; }
00039         inline DREAL get_C2() { return C2; }
00040 
00041         inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
00042         inline bool get_bias_enabled() { return use_bias; }
00043 
00044         inline void set_epsilon(DREAL eps) { epsilon=eps; }
00045         inline DREAL get_epsilon() { return epsilon; }
00046 
00047         inline void set_qpsize(INT q) { qpsize=q; }
00048         inline INT get_qpsize() { return qpsize; }
00049 
00050         inline void set_qpsize_max(INT q) { qpsize_max=q; }
00051         inline INT get_qpsize_max() { return qpsize_max; }
00052 
00053     protected:
00056         INT find_active(INT num_feat, INT num_vec, INT& num_active, INT& num_bound);
00057 
00060         void update_active(INT num_feat, INT num_vec);
00061 
00063         DREAL compute_objective(INT num_feat, INT num_vec);
00064 
00067         DREAL compute_min_subgradient(INT num_feat, INT num_vec, INT num_active, INT num_bound);
00068 
00070         DREAL line_search(INT num_feat, INT num_vec);
00071 
00073         void compute_projection(INT num_feat, INT num_vec);
00074 
00076         void update_projection(DREAL alpha, INT num_vec);
00077 
00079         void init(INT num_vec, INT num_feat);
00080         
00082         void cleanup();
00083 
00084     protected:
00085         DREAL C1;
00086         DREAL C2;
00087         DREAL epsilon;
00088         DREAL work_epsilon;
00089         DREAL autoselected_epsilon;
00090         INT qpsize;
00091         INT qpsize_max;
00092         INT qpsize_limit;
00093         bool use_bias;
00094 
00095         INT last_it_noimprovement;
00096         INT num_it_noimprovement;
00097 
00098         //idx vectors of length num_vec
00099         BYTE* active; // 0=not active, 1=active, 2=on boundary
00100         BYTE* old_active;
00101         INT* idx_active;
00102         INT* idx_bound;
00103         INT delta_active;
00104         INT delta_bound;
00105         DREAL* proj;
00106         DREAL* tmp_proj;
00107         INT* tmp_proj_idx;
00108         
00109         //vector of length num_feat
00110         DREAL* sum_CXy_active;
00111         DREAL* v;
00112         DREAL* old_v;
00113         DREAL sum_Cy_active;
00114 
00115         //vector of length num_feat
00116         INT pos_idx;
00117         INT neg_idx;
00118         INT zero_idx;
00119         INT* w_pos;
00120         INT* w_zero;
00121         INT* w_neg;
00122         DREAL* grad_w;
00123         DREAL grad_b;
00124         DREAL* grad_proj;
00125         DREAL* hinge_point;
00126         INT* hinge_idx;
00127 
00128         //vectors/sym matrix of size qpsize_limit
00129         DREAL* beta;
00130 
00131         CCplex* solver;
00132 };
00133 #endif //USE_CPLEX
00134 #endif //_SUBGRADIENTLPM_H___

SHOGUN Machine Learning Toolbox - Documentation