SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LibLinear.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-2010 Soeren Sonnenburg
8  * Copyright (c) 2007-2009 The LIBLINEAR Project.
9  * Copyright (C) 2007-2010 Fraunhofer Institute FIRST and Max-Planck-Society
10  */
11 
12 #ifndef _LIBLINEAR_H___
13 #define _LIBLINEAR_H___
14 
15 #include <shogun/lib/config.h>
16 
17 #include <shogun/lib/common.h>
18 #include <shogun/base/Parameter.h>
21 
22 namespace shogun
23 {
26  {
34  // (default since this is the standard SVM)
42  };
43 
61 class CLibLinear : public CLinearMachine
62 {
63  public:
65 
66 
67  CLibLinear();
68 
74 
81  CLibLinear(
82  float64_t C, CDotFeatures* traindat,
83  CLabels* trainlab);
84 
86  virtual ~CLibLinear();
87 
92  {
93  return liblinear_solver_type;
94  }
95 
101  {
102  liblinear_solver_type=st;
103  }
104 
110 
116  inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
117 
122  inline float64_t get_C1() { return C1; }
123 
128  inline float64_t get_C2() { return C2; }
129 
134  inline void set_epsilon(float64_t eps) { epsilon=eps; }
135 
140  inline float64_t get_epsilon() { return epsilon; }
141 
146  inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
147 
152  inline bool get_bias_enabled() { return use_bias; }
153 
155  virtual const char* get_name() const { return "LibLinear"; }
156 
158  inline int32_t get_max_iterations()
159  {
160  return max_iterations;
161  }
162 
164  inline void set_max_iterations(int32_t max_iter=1000)
165  {
166  max_iterations=max_iter;
167  }
168 
170  void set_linear_term(const SGVector<float64_t> linear_term);
171 
174 
176  void init_linear_term();
177 
178  protected:
187  virtual bool train_machine(CFeatures* data=NULL);
188 
189  private:
191  void init();
192 
193  void train_one(const liblinear_problem *prob, const liblinear_parameter *param, double Cp, double Cn);
194  void solve_l2r_l1l2_svc(
195  const liblinear_problem *prob, double eps, double Cp, double Cn, LIBLINEAR_SOLVER_TYPE st);
196 
197  void solve_l1r_l2_svc(liblinear_problem *prob_col, double eps, double Cp, double Cn);
198  void solve_l1r_lr(const liblinear_problem *prob_col, double eps, double Cp, double Cn);
199  void solve_l2r_lr_dual(const liblinear_problem *prob, double eps, double Cp, double Cn);
200 
201 
202  protected:
208  bool use_bias;
212  int32_t max_iterations;
213 
216 
219 };
220 
221 } /* namespace shogun */
222 
223 #endif //_LIBLINEAR_H___

SHOGUN Machine Learning Toolbox - Documentation