SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
classifier
svm
LibLinear.h
浏览该文件的文档.
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
45
class
CLibLinear
:
public
CLinearMachine
46
{
47
public
:
48
MACHINE_PROBLEM_TYPE
(
PT_BINARY
)
49
50
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
75
inline
LIBLINEAR_SOLVER_TYPE
get_liblinear_solver_type
()
76
{
77
return
liblinear_solver_type
;
78
}
79
84
inline
void
set_liblinear_solver_type
(
LIBLINEAR_SOLVER_TYPE
st)
85
{
86
liblinear_solver_type=st;
87
}
88
93
virtual
EMachineType
get_classifier_type
() {
return
CT_LIBLINEAR
; }
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
157
SGVector<float64_t>
get_linear_term
();
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
:
188
float64_t
C1
;
190
float64_t
C2
;
192
bool
use_bias
;
194
float64_t
epsilon
;
196
int32_t
max_iterations
;
197
199
SGVector<float64_t>
m_linear_term
;
200
202
LIBLINEAR_SOLVER_TYPE
liblinear_solver_type
;
203
};
204
205
}
/* namespace shogun */
206
207
#endif //_LIBLINEAR_H___
SHOGUN
机器学习工具包 - 项目文档