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 
45 class CLibLinear : public CLinearMachine
46 {
47  public:
49 
50 
51  CLibLinear();
52 
58 
65  CLibLinear(
66  float64_t C, CDotFeatures* traindat,
67  CLabels* trainlab);
68 
70  virtual ~CLibLinear();
71 
76  {
77  return liblinear_solver_type;
78  }
79 
85  {
86  liblinear_solver_type=st;
87  }
88 
94 
100  inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
101 
106  inline float64_t get_C1() { return C1; }
107 
112  inline float64_t get_C2() { return C2; }
113 
118  inline void set_epsilon(float64_t eps) { epsilon=eps; }
119 
124  inline float64_t get_epsilon() { return epsilon; }
125 
130  inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
131 
136  inline bool get_bias_enabled() { return use_bias; }
137 
139  virtual const char* get_name() const { return "LibLinear"; }
140 
142  inline int32_t get_max_iterations()
143  {
144  return max_iterations;
145  }
146 
148  inline void set_max_iterations(int32_t max_iter=1000)
149  {
150  max_iterations=max_iter;
151  }
152 
154  void set_linear_term(const SGVector<float64_t> linear_term);
155 
158 
160  void init_linear_term();
161 
162  protected:
171  virtual bool train_machine(CFeatures* data=NULL);
172 
173  private:
175  void init();
176 
177  void train_one(const liblinear_problem *prob, const liblinear_parameter *param, double Cp, double Cn);
178  void solve_l2r_l1l2_svc(
179  const liblinear_problem *prob, double eps, double Cp, double Cn, LIBLINEAR_SOLVER_TYPE st);
180 
181  void solve_l1r_l2_svc(liblinear_problem *prob_col, double eps, double Cp, double Cn);
182  void solve_l1r_lr(const liblinear_problem *prob_col, double eps, double Cp, double Cn);
183  void solve_l2r_lr_dual(const liblinear_problem *prob, double eps, double Cp, double Cn);
184 
185 
186  protected:
192  bool use_bias;
196  int32_t max_iterations;
197 
200 
203 };
204 
205 } /* namespace shogun */
206 
207 #endif //_LIBLINEAR_H___

SHOGUN Machine Learning Toolbox - Documentation