SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SubGradientLPM.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2007-2009 Soeren Sonnenburg
8  * Written (W) 2007-2008 Vojtech Franc
9  * Copyright (C) 2007-2009 Fraunhofer Institute FIRST and Max-Planck-Society
10  */
11 
12 #ifndef _SUBGRADIENTLPM_H___
13 #define _SUBGRADIENTLPM_H___
14 
15 #include <shogun/lib/config.h>
16 
17 #ifdef USE_CPLEX
18 #include <shogun/lib/common.h>
19 
21 
24 #include <shogun/features/Labels.h>
25 
26 namespace shogun
27 {
48 class CSubGradientLPM : public CLinearClassifier
49 {
50  public:
53  float64_t C, CDotFeatures* traindat,
54  CLabels* trainlab);
55  virtual ~CSubGradientLPM();
56 
58 
65  inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
66 
67  inline float64_t get_C1() { return C1; }
68  inline float64_t get_C2() { return C2; }
69 
70  inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
71  inline bool get_bias_enabled() { return use_bias; }
72 
73  inline void set_epsilon(float64_t eps) { epsilon=eps; }
74  inline float64_t get_epsilon() { return epsilon; }
75 
76  inline void set_qpsize(int32_t q) { qpsize=q; }
77  inline int32_t get_qpsize() { return qpsize; }
78 
79  inline void set_qpsize_max(int32_t q) { qpsize_max=q; }
80  inline int32_t get_qpsize_max() { return qpsize_max; }
81 
82  protected:
85  int32_t find_active(
86  int32_t num_feat, int32_t num_vec, int32_t& num_active,
87  int32_t& num_bound);
88 
91  void update_active(int32_t num_feat, int32_t num_vec);
92 
94  float64_t compute_objective(int32_t num_feat, int32_t num_vec);
95 
99  int32_t num_feat, int32_t num_vec, int32_t num_active,
100  int32_t num_bound);
101 
103  float64_t line_search(int32_t num_feat, int32_t num_vec);
104 
106  void compute_projection(int32_t num_feat, int32_t num_vec);
107 
109  void update_projection(float64_t alpha, int32_t num_vec);
110 
112  void init(int32_t num_vec, int32_t num_feat);
113 
115  void cleanup();
116 
118  inline virtual const char* get_name() const { return "SubGradientLPM"; }
119 
120  protected:
129  virtual bool train_machine(CFeatures* data=NULL);
130 
131  protected:
137  int32_t qpsize;
138  int32_t qpsize_max;
139  int32_t qpsize_limit;
140  bool use_bias;
141 
144 
145  //idx vectors of length num_vec
146  uint8_t* active; // 0=not active, 1=active, 2=on boundary
147  uint8_t* old_active;
148  int32_t* idx_active;
149  int32_t* idx_bound;
150  int32_t delta_active;
151  int32_t delta_bound;
154  int32_t* tmp_proj_idx;
155 
156  //vector of length num_feat
161 
162  //vector of length num_feat
163  int32_t pos_idx;
164  int32_t neg_idx;
165  int32_t zero_idx;
166  int32_t* w_pos;
167  int32_t* w_zero;
168  int32_t* w_neg;
173  int32_t* hinge_idx;
174 
175  //vectors/sym matrix of size qpsize_limit
177 
180 };
181 }
182 #endif //USE_CPLEX
183 #endif //_SUBGRADIENTLPM_H___

SHOGUN Machine Learning Toolbox - Documentation