SHOGUN  5.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
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___
EMachineType
Definition: Machine.h:33
L2 regularized linear logistic regression via dual.
Definition: LibLinear.h:41
virtual ~CLibLinear()
Definition: LibLinear.cpp:74
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
void set_C(float64_t c_neg, float64_t c_pos)
Definition: LibLinear.h:116
L2 regularized SVM with L2-loss using newton in the primal.
Definition: LibLinear.h:32
float64_t get_C1()
Definition: LibLinear.h:122
L1 regularized logistic regression.
Definition: LibLinear.h:39
L1 regularized SVM with L2-loss using dual coordinate descent.
Definition: LibLinear.h:37
Features that support dot products among other operations.
Definition: DotFeatures.h:44
SGVector< float64_t > get_linear_term()
Definition: LibLinear.cpp:1351
void set_bias_enabled(bool enable_bias)
Definition: LibLinear.h:146
LIBLINEAR_SOLVER_TYPE
Definition: LibLinear.h:25
void set_linear_term(const SGVector< float64_t > linear_term)
Definition: LibLinear.cpp:1334
#define MACHINE_PROBLEM_TYPE(PT)
Definition: Machine.h:120
void set_max_iterations(int32_t max_iter=1000)
Definition: LibLinear.h:164
L2 regularized linear logistic regression.
Definition: LibLinear.h:28
float64_t get_C2()
Definition: LibLinear.h:128
double float64_t
Definition: common.h:50
This class provides an interface to the LibLinear library for large- scale linear learning focusing o...
Definition: LibLinear.h:61
L2 regularized SVM with L2-loss using dual coordinate descent.
Definition: LibLinear.h:30
Class LinearMachine is a generic interface for all kinds of linear machines like classifiers.
Definition: LinearMachine.h:63
LIBLINEAR_SOLVER_TYPE liblinear_solver_type
Definition: LibLinear.h:218
float64_t epsilon
Definition: LibLinear.h:210
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
float64_t get_epsilon()
Definition: LibLinear.h:140
LIBLINEAR_SOLVER_TYPE get_liblinear_solver_type()
Definition: LibLinear.h:91
The class Features is the base class of all feature objects.
Definition: Features.h:68
virtual bool train_machine(CFeatures *data=NULL)
Definition: LibLinear.cpp:78
virtual const char * get_name() const
Definition: LibLinear.h:155
virtual EMachineType get_classifier_type()
Definition: LibLinear.h:109
int32_t get_max_iterations()
Definition: LibLinear.h:158
L2 regularized linear SVM with L1-loss using dual coordinate descent.
Definition: LibLinear.h:35
void set_epsilon(float64_t eps)
Definition: LibLinear.h:134
int32_t max_iterations
Definition: LibLinear.h:212
void set_liblinear_solver_type(LIBLINEAR_SOLVER_TYPE st)
Definition: LibLinear.h:100
SGVector< float64_t > m_linear_term
Definition: LibLinear.h:215
bool get_bias_enabled()
Definition: LibLinear.h:152

SHOGUN Machine Learning Toolbox - Documentation