SHOGUN
v2.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
classifier
svm
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
>
19
#include <
shogun/machine/LinearMachine.h
>
20
#include <
shogun/optimization/liblinear/shogun_liblinear.h
>
21
22
namespace
shogun
23
{
25
enum
LIBLINEAR_SOLVER_TYPE
26
{
28
L2R_LR
,
30
L2R_L2LOSS_SVC_DUAL
,
32
L2R_L2LOSS_SVC
,
34
// (default since this is the standard SVM)
35
L2R_L1LOSS_SVC_DUAL
,
37
L1R_L2LOSS_SVC
,
39
L1R_LR
,
41
L2R_LR_DUAL
42
};
43
44
#ifdef HAVE_LAPACK
45
47
class
CLibLinear
:
public
CLinearMachine
48
{
49
public
:
50
MACHINE_PROBLEM_TYPE
(
PT_BINARY
);
51
53
CLibLinear
();
54
59
CLibLinear
(
LIBLINEAR_SOLVER_TYPE
liblinear_solver_type
);
60
67
CLibLinear
(
68
float64_t
C,
CDotFeatures
* traindat,
69
CLabels
* trainlab);
70
72
virtual
~CLibLinear
();
73
74
inline
LIBLINEAR_SOLVER_TYPE
get_liblinear_solver_type
()
75
{
76
return
liblinear_solver_type
;
77
}
78
79
inline
void
set_liblinear_solver_type
(
LIBLINEAR_SOLVER_TYPE
st)
80
{
81
liblinear_solver_type=st;
82
}
83
88
virtual
inline
EMachineType
get_classifier_type
() {
return
CT_LIBLINEAR
; }
89
95
inline
void
set_C
(
float64_t
c_neg,
float64_t
c_pos) {
C1
=c_neg;
C2
=c_pos; }
96
101
inline
float64_t
get_C1
() {
return
C1
; }
102
107
inline
float64_t
get_C2
() {
return
C2
; }
108
113
inline
void
set_epsilon
(
float64_t
eps) {
epsilon
=eps; }
114
119
inline
float64_t
get_epsilon
() {
return
epsilon
; }
120
125
inline
void
set_bias_enabled
(
bool
enable_bias) {
use_bias
=enable_bias; }
126
131
inline
bool
get_bias_enabled
() {
return
use_bias
; }
132
134
inline
virtual
const
char
*
get_name
()
const
{
return
"LibLinear"
; }
135
137
inline
int32_t
get_max_iterations
()
138
{
139
return
max_iterations
;
140
}
141
143
inline
void
set_max_iterations
(int32_t max_iter=1000)
144
{
145
max_iterations
=max_iter;
146
}
147
149
void
set_linear_term
(
const
SGVector<float64_t>
linear_term);
150
152
SGVector<float64_t>
get_linear_term
();
153
155
void
init_linear_term
();
156
157
protected
:
166
virtual
bool
train_machine
(
CFeatures
* data=NULL);
167
168
private
:
170
void
init();
171
172
void
train_one(
const
problem *prob,
const
parameter *param,
double
Cp,
double
Cn);
173
void
solve_l2r_l1l2_svc(
174
const
problem *prob,
double
eps,
double
Cp,
double
Cn,
LIBLINEAR_SOLVER_TYPE
st);
175
176
void
solve_l1r_l2_svc(problem *prob_col,
double
eps,
double
Cp,
double
Cn);
177
void
solve_l1r_lr(
const
problem *prob_col,
double
eps,
double
Cp,
double
Cn);
178
void
solve_l2r_lr_dual(
const
problem *prob,
double
eps,
double
Cp,
double
Cn);
179
180
181
protected
:
183
float64_t
C1
;
185
float64_t
C2
;
187
bool
use_bias
;
189
float64_t
epsilon
;
191
int32_t
max_iterations
;
192
194
SGVector<float64_t>
m_linear_term
;
195
197
LIBLINEAR_SOLVER_TYPE
liblinear_solver_type
;
198
};
199
200
#endif //HAVE_LAPACK
201
202
}
/* namespace shogun */
203
204
#endif //_LIBLINEAR_H___
SHOGUN
Machine Learning Toolbox - Documentation