SHOGUN
v1.1.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
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/classifier/svm/SVM_linear.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
MCSVM_CS
,
39
L1R_L2LOSS_SVC
,
41
L1R_LR
42
};
43
44
#ifdef HAVE_LAPACK
45
47
class
CLibLinear
:
public
CLinearMachine
48
{
49
public
:
51
CLibLinear
();
52
57
CLibLinear
(
LIBLINEAR_SOLVER_TYPE
liblinear_solver_type
);
58
65
CLibLinear
(
66
float64_t
C,
CDotFeatures
* traindat,
67
CLabels
* trainlab);
68
70
virtual
~CLibLinear
();
71
72
inline
LIBLINEAR_SOLVER_TYPE
get_liblinear_solver_type
()
73
{
74
return
liblinear_solver_type
;
75
}
76
77
inline
void
set_liblinear_solver_type
(
LIBLINEAR_SOLVER_TYPE
st)
78
{
79
liblinear_solver_type=st;
80
}
81
86
virtual
inline
EClassifierType
get_classifier_type
() {
return
CT_LIBLINEAR
; }
87
93
inline
void
set_C
(
float64_t
c_neg,
float64_t
c_pos) {
C1
=c_neg;
C2
=c_pos; }
94
99
inline
float64_t
get_C1
() {
return
C1
; }
100
105
inline
float64_t
get_C2
() {
return
C2
; }
106
111
inline
void
set_epsilon
(
float64_t
eps) {
epsilon
=eps; }
112
117
inline
float64_t
get_epsilon
() {
return
epsilon
; }
118
123
inline
void
set_bias_enabled
(
bool
enable_bias) {
use_bias
=enable_bias; }
124
129
inline
bool
get_bias_enabled
() {
return
use_bias
; }
130
132
inline
virtual
const
char
*
get_name
()
const
{
return
"LibLinear"
; }
133
135
inline
int32_t
get_max_iterations
()
136
{
137
return
max_iterations
;
138
}
139
141
inline
void
set_max_iterations
(int32_t max_iter=1000)
142
{
143
max_iterations
=max_iter;
144
}
145
147
inline
void
set_linear_term
(
SGVector<float64_t>
linear_term)
148
{
149
if
(!
labels
)
150
SG_ERROR
(
"Please assign labels first!\n"
);
151
152
int32_t num_labels=
labels
->
get_num_labels
();
153
154
if
(num_labels!=linear_term.
vlen
)
155
{
156
SG_ERROR
(
"Number of labels (%d) does not match number"
157
" of entries (%d) in linear term \n"
, num_labels,
158
linear_term.
vlen
);
159
}
160
161
m_linear_term
.
destroy_vector
();
162
m_linear_term
.
vector
=
CMath::clone_vector
(linear_term.
vector
,
163
linear_term.
vlen
);
164
m_linear_term
.
vlen
=linear_term.
vlen
;
165
}
166
168
SGVector<float64_t>
get_linear_term
();
169
171
void
init_linear_term
();
172
173
protected
:
182
virtual
bool
train_machine
(
CFeatures
* data=NULL);
183
184
private
:
186
void
init();
187
188
void
train_one(
const
problem *prob,
const
parameter *param,
double
Cp,
double
Cn);
189
void
solve_l2r_l1l2_svc(
190
const
problem *prob,
double
eps,
double
Cp,
double
Cn,
LIBLINEAR_SOLVER_TYPE
st);
191
192
void
solve_l1r_l2_svc(problem *prob_col,
double
eps,
double
Cp,
double
Cn);
193
void
solve_l1r_lr(
const
problem *prob_col,
double
eps,
double
Cp,
double
Cn);
194
195
196
protected
:
198
float64_t
C1
;
200
float64_t
C2
;
202
bool
use_bias
;
204
float64_t
epsilon
;
206
int32_t
max_iterations
;
207
209
SGVector<float64_t>
m_linear_term
;
210
212
LIBLINEAR_SOLVER_TYPE
liblinear_solver_type
;
213
};
214
215
#endif //HAVE_LAPACK
216
217
}
/* namespace shogun */
218
219
#endif //_LIBLINEAR_H___
SHOGUN
Machine Learning Toolbox - Documentation