SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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/labels/Labels.h>
25 
26 namespace shogun
27 {
49 {
50  public:
52 
55  float64_t C, CDotFeatures* traindat,
56  CLabels* trainlab);
57  virtual ~CSubGradientLPM();
58 
59  virtual inline EMachineType get_classifier_type() { return CT_SUBGRADIENTLPM; }
60 
67  inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
68 
69  inline float64_t get_C1() { return C1; }
70  inline float64_t get_C2() { return C2; }
71 
72  inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
73  inline bool get_bias_enabled() { return use_bias; }
74 
75  inline void set_epsilon(float64_t eps) { epsilon=eps; }
76  inline float64_t get_epsilon() { return epsilon; }
77 
78  inline void set_qpsize(int32_t q) { qpsize=q; }
79  inline int32_t get_qpsize() { return qpsize; }
80 
81  inline void set_qpsize_max(int32_t q) { qpsize_max=q; }
82  inline int32_t get_qpsize_max() { return qpsize_max; }
83 
84  protected:
87  int32_t find_active(
88  int32_t num_feat, int32_t num_vec, int32_t& num_active,
89  int32_t& num_bound);
90 
93  void update_active(int32_t num_feat, int32_t num_vec);
94 
96  float64_t compute_objective(int32_t num_feat, int32_t num_vec);
97 
101  int32_t num_feat, int32_t num_vec, int32_t num_active,
102  int32_t num_bound);
103 
105  float64_t line_search(int32_t num_feat, int32_t num_vec);
106 
108  void compute_projection(int32_t num_feat, int32_t num_vec);
109 
111  void update_projection(float64_t alpha, int32_t num_vec);
112 
114  void init(int32_t num_vec, int32_t num_feat);
115 
117  void cleanup();
118 
120  inline virtual const char* get_name() const { return "SubGradientLPM"; }
121 
122  protected:
131  virtual bool train_machine(CFeatures* data=NULL);
132 
133  protected:
139  int32_t qpsize;
140  int32_t qpsize_max;
141  int32_t qpsize_limit;
142  bool use_bias;
143 
146 
147  //idx vectors of length num_vec
148  uint8_t* active; // 0=not active, 1=active, 2=on boundary
149  uint8_t* old_active;
150  int32_t* idx_active;
151  int32_t* idx_bound;
152  int32_t delta_active;
153  int32_t delta_bound;
156  int32_t* tmp_proj_idx;
157 
158  //vector of length num_feat
163 
164  //vector of length num_feat
165  int32_t pos_idx;
166  int32_t neg_idx;
167  int32_t zero_idx;
168  int32_t* w_pos;
169  int32_t* w_zero;
170  int32_t* w_neg;
175  int32_t* hinge_idx;
176 
177  //vectors/sym matrix of size qpsize_limit
179 
182 };
183 }
184 #endif //USE_CPLEX
185 #endif //_SUBGRADIENTLPM_H___

SHOGUN Machine Learning Toolbox - Documentation