Feat C++ API
A feature engineering automation tool
MyMulticlassLibLinear.h
Go to the documentation of this file.
1 /*
2  * This software is distributed under BSD 3-clause license (see LICENSE file).
3  *
4  * Authors: Sergey Lisitsyn, Fernando Iglesias, Yuyu Zhang, Evan Shelhamer,
5  * Bjoern Esser, Soeren Sonnenburg
6  */
7 
8 #ifndef _MULTICLASSLIBLINEAR_H___
9 #define _MULTICLASSLIBLINEAR_H___
10 
11 #include <shogun/lib/config.h>
12 #include <shogun/lib/common.h>
13 #include <shogun/features/DotFeatures.h>
14 #include <shogun/machine/LinearMulticlassMachine.h>
15 #include <shogun/optimization/liblinear/shogun_liblinear.h>
16 #include <shogun/lib/config.h>
17 #include <shogun/multiclass/MulticlassOneVsRestStrategy.h>
18 #include <shogun/mathematics/Math.h>
19 #include <shogun/lib/v_array.h>
20 #include <shogun/lib/Signal.h>
21 #include <shogun/labels/MulticlassLabels.h>
22 #include <vector>
23 #include <Eigen/Dense>
24 using std::vector;
25 
26 
27 namespace shogun
28 {
29 
44  class CMyMulticlassLibLinear : public CLinearMulticlassMachine
45  {
46  public:
47 
48  MACHINE_PROBLEM_TYPE(PT_MULTICLASS);
49 
51 
57  CMyMulticlassLibLinear(float64_t C, CDotFeatures* features, CLabels* labs);
58 
61 
63  virtual const char* get_name() const;
64 
68  inline void set_C(float64_t C);
69 
73  inline float64_t get_C() const;
74 
78  inline void set_epsilon(float64_t epsilon);
79 
83  inline float64_t get_epsilon() const;
84 
88  inline void set_use_bias(bool use_bias);
89 
93  inline bool get_use_bias() const;
94 
98  inline void set_save_train_state(bool save_train_state);
99 
103  inline bool get_save_train_state() const;
104 
108  inline void set_max_iter(int32_t max_iter);
109 
113  inline int32_t get_max_iter() const;
114 
116  void reset_train_state();
117 
121  SGVector<int32_t> get_support_vectors() const;
122 
123  /* get the weights for each SVM Subclass
124  * @return the vector of weights for each subclass
125  */
126  vector<SGVector<float64_t>> get_w() const;
127  void set_w(vector<Eigen::VectorXd> wnew);
128 
129  protected:
130 
132  bool train_machine(CFeatures* data);
133 
135  SGMatrix<float64_t> obtain_regularizer_matrix() const;
136 
137  private:
138 
139  void init_defaults();
140 
141  void register_parameters();
142 
143 
144  protected:
145 
147  float64_t m_C;
148 
150  float64_t m_epsilon;
151 
153  int32_t m_max_iter;
154 
157 
160 
162  mcsvm_state* m_train_state;
163  };
164 }
165 #endif
166 
multiclass LibLinear wrapper. Uses Crammer-Singer formulation and gradient descent optimization algor...
vector< SGVector< float64_t > > get_w() const
MACHINE_PROBLEM_TYPE(PT_MULTICLASS)
void set_epsilon(float64_t epsilon)
virtual const char * get_name() const
void set_w(vector< Eigen::VectorXd > wnew)
SGVector< int32_t > get_support_vectors() const
SGMatrix< float64_t > obtain_regularizer_matrix() const
void set_save_train_state(bool save_train_state)