SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SubGradientSVM.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 _SUBGRADIENTSVM_H___
13 #define _SUBGRADIENTSVM_H___
14 
15 #include <shogun/lib/common.h>
18 #include <shogun/labels/Labels.h>
19 
20 namespace shogun
21 {
24 {
25  public:
26 
29 
32 
40  float64_t C, CDotFeatures* traindat,
41  CLabels* trainlab);
42  virtual ~CSubGradientSVM();
43 
48  virtual inline EMachineType get_classifier_type() { return CT_SUBGRADIENTSVM; }
49 
55  inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
56 
57 
62  inline float64_t get_C1() { return C1; }
63 
68  inline float64_t get_C2() { return C2; }
69 
74  inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
75 
80  inline bool get_bias_enabled() { return use_bias; }
81 
86  inline void set_epsilon(float64_t eps) { epsilon=eps; }
87 
92  inline float64_t get_epsilon() { return epsilon; }
93 
98  inline void set_qpsize(int32_t q) { qpsize=q; }
99 
104  inline int32_t get_qpsize() { return qpsize; }
105 
110  inline void set_qpsize_max(int32_t q) { qpsize_max=q; }
111 
116  inline int32_t get_qpsize_max() { return qpsize_max; }
117 
118  protected:
121  int32_t find_active(
122  int32_t num_feat, int32_t num_vec, int32_t& num_active,
123  int32_t& num_bound);
124 
127  void update_active(int32_t num_feat, int32_t num_vec);
128 
130  float64_t compute_objective(int32_t num_feat, int32_t num_vec);
131 
135  int32_t num_feat, int32_t num_vec, int32_t num_active,
136  int32_t num_bound);
137 
139  float64_t line_search(int32_t num_feat, int32_t num_vec);
140 
142  void compute_projection(int32_t num_feat, int32_t num_vec);
143 
145  void update_projection(float64_t alpha, int32_t num_vec);
146 
148  void init(int32_t num_vec, int32_t num_feat);
149 
151  void cleanup();
152 
154  inline virtual const char* get_name() const { return "SubGradientSVM"; }
155 
156  protected:
165  virtual bool train_machine(CFeatures* data=NULL);
166 
167  protected:
179  int32_t qpsize;
181  int32_t qpsize_max;
183  int32_t qpsize_limit;
185  bool use_bias;
186 
191 
192  //idx vectors of length num_vec
194  uint8_t* active;
196  uint8_t* old_active;
198  int32_t* idx_active;
200  int32_t* idx_bound;
202  int32_t delta_active;
204  int32_t delta_bound;
210  int32_t* tmp_proj_idx;
211 
212  //vector of length num_feat
221 
222  //vector of length num_feat
232  int32_t* hinge_idx;
233 
234  //vectors/sym matrix of size qpsize_limit
247 
250 };
251 }
252 #endif

SHOGUN Machine Learning Toolbox - Documentation