SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
classifier
mkl
MKL.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) 2009 Soeren Sonnenburg
8
* Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
* Copyright (C) 2010 Ryota Tomioka (University of Tokyo)
10
*/
11
#ifndef __MKL_H__
12
#define __MKL_H__
13
14
#include <
shogun/lib/config.h
>
15
16
#ifdef USE_GLPK
17
#include <glpk.h>
18
#endif
19
20
#ifdef USE_CPLEX
21
extern
"C"
{
22
#include <ilcplex/cplex.h>
23
}
24
#endif
25
26
#include <
shogun/lib/common.h
>
27
#include <
shogun/lib/Time.h
>
28
#include <
shogun/features/Features.h
>
29
#include <
shogun/kernel/Kernel.h
>
30
#include <
shogun/classifier/svm/SVM.h
>
31
32
namespace
shogun
33
{
95
class
CMKL
:
public
CSVM
96
{
97
public
:
102
CMKL
(
CSVM
* s=NULL);
103
106
virtual
~CMKL
();
107
112
inline
void
set_constraint_generator
(
CSVM
* s)
113
{
114
set_svm
(s);
115
}
116
121
inline
void
set_svm
(
CSVM
* s)
122
{
123
SG_REF
(s);
124
SG_UNREF
(
svm
);
125
svm
=s;
126
}
127
132
inline
CSVM
*
get_svm
()
133
{
134
SG_REF
(
svm
);
135
return
svm
;
136
}
137
142
inline
void
set_C_mkl
(
float64_t
C) {
C_mkl
= C; }
143
148
void
set_mkl_norm
(
float64_t
norm
);
149
156
void
set_elasticnet_lambda
(
float64_t
elasticnet_lambda);
157
162
void
set_mkl_block_norm
(
float64_t
q);
163
169
inline
void
set_interleaved_optimization_enabled
(
bool
enable)
170
{
171
interleaved_optimization
=enable;
172
}
173
178
inline
bool
get_interleaved_optimization_enabled
()
179
{
180
return
interleaved_optimization
;
181
}
182
187
inline
float64_t
compute_mkl_primal_objective
()
188
{
189
return
compute_svm_primal_objective
();
190
}
191
196
virtual
float64_t
compute_mkl_dual_objective
();
197
198
203
float64_t
compute_elasticnet_dual_objective
();
204
209
inline
void
set_mkl_epsilon
(
float64_t
eps) {
mkl_epsilon
=eps; }
210
215
inline
float64_t
get_mkl_epsilon
() {
return
mkl_epsilon
; }
216
221
inline
int32_t
get_mkl_iterations
() {
return
mkl_iterations
; }
222
233
virtual
bool
perform_mkl_step
(
const
float64_t
* sumw,
float64_t
suma);
234
241
static
bool
perform_mkl_step_helper
(
CMKL
*
mkl
,
242
const
float64_t
* sumw,
const
float64_t
suma)
243
{
244
return
mkl->
perform_mkl_step
(sumw, suma);
245
}
246
247
251
virtual
float64_t
compute_sum_alpha
()=0;
252
257
virtual
void
compute_sum_beta
(
float64_t
* sumw);
258
260
virtual
const
char
*
get_name
()
const
{
return
"MKL"
; }
261
262
protected
:
271
virtual
bool
train_machine
(
CFeatures
* data=NULL);
272
276
virtual
void
init_training
()=0;
277
293
void
perform_mkl_step
(
float64_t
* beta,
float64_t
* old_beta,
int
num_kernels,
294
int32_t* label, int32_t* active2dnum,
295
float64_t
* a,
float64_t
* lin,
float64_t
* sumw, int32_t& inner_iters);
296
297
311
float64_t
compute_optimal_betas_via_cplex
(
float64_t
* beta,
const
float64_t
* old_beta, int32_t num_kernels,
312
const
float64_t
* sumw,
float64_t
suma, int32_t& inner_iters);
313
326
float64_t
compute_optimal_betas_via_glpk
(
float64_t
* beta,
const
float64_t
* old_beta,
327
int
num_kernels,
const
float64_t
* sumw,
float64_t
suma, int32_t& inner_iters);
328
340
float64_t
compute_optimal_betas_elasticnet
(
341
float64_t
* beta,
const
float64_t
* old_beta,
const
int32_t num_kernels,
342
const
float64_t
* sumw,
const
float64_t
suma,
const
float64_t
mkl_objective);
343
345
inline
void
elasticnet_transform
(
float64_t
*beta,
float64_t
lmd, int32_t len)
346
{
347
for
(int32_t i=0;i <len;i++)
348
beta[i]=beta[i]/(1.0-lmd+lmd*beta[i]);
349
}
350
352
void
elasticnet_dual
(
float64_t
*ff,
float64_t
*gg,
float64_t
*hh,
353
const
float64_t
&del,
const
float64_t
* nm, int32_t len,
354
const
float64_t
&lambda);
355
367
float64_t
compute_optimal_betas_directly
(
368
float64_t
* beta,
const
float64_t
* old_beta,
const
int32_t num_kernels,
369
const
float64_t
* sumw,
const
float64_t
suma,
const
float64_t
mkl_objective);
370
382
float64_t
compute_optimal_betas_block_norm
(
383
float64_t
* beta,
const
float64_t
* old_beta,
const
int32_t num_kernels,
384
const
float64_t
* sumw,
const
float64_t
suma,
const
float64_t
mkl_objective);
385
397
float64_t
compute_optimal_betas_newton
(
float64_t
* beta,
const
float64_t
* old_beta,
398
int32_t num_kernels,
const
float64_t
* sumw,
float64_t
suma,
float64_t
mkl_objective);
399
404
virtual
bool
converged
()
405
{
406
return
w_gap
<
mkl_epsilon
;
407
}
408
410
void
init_solver
();
411
412
#ifdef USE_CPLEX
413
417
bool
init_cplex
();
418
420
void
set_qnorm_constraints
(
float64_t
* beta, int32_t num_kernels);
421
426
bool
cleanup_cplex
();
427
#endif
428
429
#ifdef USE_GLPK
430
434
bool
init_glpk
();
435
440
bool
cleanup_glpk
();
441
446
bool
check_glp_status
(glp_prob *lp);
447
#endif
448
449
protected
:
451
CSVM
*
svm
;
453
float64_t
C_mkl
;
455
float64_t
mkl_norm
;
461
float64_t
ent_lambda
;
462
465
float64_t
mkl_block_norm
;
466
468
float64_t
*
beta_local
;
470
int32_t
mkl_iterations
;
472
float64_t
mkl_epsilon
;
474
bool
interleaved_optimization
;
475
477
float64_t
*
W
;
478
480
float64_t
w_gap
;
482
float64_t
rho
;
483
485
CTime
training_time_clock
;
486
487
#ifdef USE_CPLEX
488
489
CPXENVptr
env
;
491
CPXLPptr
lp_cplex
;
492
#endif
493
494
#ifdef USE_GLPK
495
496
glp_prob*
lp_glpk
;
497
499
glp_smcp*
lp_glpk_parm
;
500
#endif
501
502
bool
lp_initialized
;
503
};
504
}
505
#endif //__MKL_H__
SHOGUN
机器学习工具包 - 项目文档