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
mkl
MKL.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) 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
#ifdef USE_GLPK
15
#include <glpk.h>
16
#endif
17
18
#ifdef USE_CPLEX
19
extern
"C"
{
20
#include <ilcplex/cplex.h>
21
}
22
#endif
23
24
#include <
shogun/lib/common.h
>
25
#include <
shogun/lib/Time.h
>
26
#include <
shogun/features/Features.h
>
27
#include <
shogun/kernel/Kernel.h
>
28
#include <
shogun/classifier/svm/SVM.h
>
29
30
namespace
shogun
31
{
93
class
CMKL
:
public
CSVM
94
{
95
public
:
100
CMKL
(
CSVM
* s=NULL);
101
104
virtual
~CMKL
();
105
110
inline
void
set_constraint_generator
(
CSVM
* s)
111
{
112
set_svm
(s);
113
}
114
119
inline
void
set_svm
(
CSVM
* s)
120
{
121
SG_REF
(s);
122
SG_UNREF
(
svm
);
123
svm
=s;
124
}
125
130
inline
CSVM
*
get_svm
()
131
{
132
SG_REF
(
svm
);
133
return
svm
;
134
}
135
140
inline
void
set_C_mkl
(
float64_t
C) {
C_mkl
= C; }
141
146
void
set_mkl_norm
(
float64_t
norm
);
147
154
void
set_elasticnet_lambda
(
float64_t
elasticnet_lambda);
155
160
void
set_mkl_block_norm
(
float64_t
q);
161
167
inline
void
set_interleaved_optimization_enabled
(
bool
enable)
168
{
169
interleaved_optimization
=enable;
170
}
171
176
inline
bool
get_interleaved_optimization_enabled
()
177
{
178
return
interleaved_optimization
;
179
}
180
185
inline
float64_t
compute_mkl_primal_objective
()
186
{
187
return
compute_svm_primal_objective
();
188
}
189
194
virtual
float64_t
compute_mkl_dual_objective
();
195
196
201
float64_t
compute_elasticnet_dual_objective
();
202
207
inline
void
set_mkl_epsilon
(
float64_t
eps) {
mkl_epsilon
=eps; }
208
213
inline
float64_t
get_mkl_epsilon
() {
return
mkl_epsilon
; }
214
219
inline
int32_t
get_mkl_iterations
() {
return
mkl_iterations
; }
220
231
virtual
bool
perform_mkl_step
(
const
float64_t
* sumw,
float64_t
suma);
232
239
static
bool
perform_mkl_step_helper
(
CMKL
*
mkl
,
240
const
float64_t
* sumw,
const
float64_t
suma)
241
{
242
return
mkl->
perform_mkl_step
(sumw, suma);
243
}
244
245
249
virtual
float64_t
compute_sum_alpha
()=0;
250
255
virtual
void
compute_sum_beta
(
float64_t
* sumw);
256
258
inline
virtual
const
char
*
get_name
()
const
{
return
"MKL"
; }
259
260
protected
:
269
virtual
bool
train_machine
(
CFeatures
* data=NULL);
270
274
virtual
void
init_training
()=0;
275
291
void
perform_mkl_step
(
float64_t
* beta,
float64_t
* old_beta,
int
num_kernels,
292
int32_t* label, int32_t* active2dnum,
293
float64_t
* a,
float64_t
* lin,
float64_t
* sumw, int32_t& inner_iters);
294
295
309
float64_t
compute_optimal_betas_via_cplex
(
float64_t
* beta,
const
float64_t
* old_beta, int32_t num_kernels,
310
const
float64_t
* sumw,
float64_t
suma, int32_t& inner_iters);
311
324
float64_t
compute_optimal_betas_via_glpk
(
float64_t
* beta,
const
float64_t
* old_beta,
325
int
num_kernels,
const
float64_t
* sumw,
float64_t
suma, int32_t& inner_iters);
326
338
float64_t
compute_optimal_betas_elasticnet
(
339
float64_t
* beta,
const
float64_t
* old_beta,
const
int32_t num_kernels,
340
const
float64_t
* sumw,
const
float64_t
suma,
const
float64_t
mkl_objective);
341
343
inline
void
elasticnet_transform
(
float64_t
*beta,
float64_t
lmd, int32_t len)
344
{
345
for
(int32_t i=0;i <len;i++)
346
beta[i]=beta[i]/(1.0-lmd+lmd*beta[i]);
347
}
348
350
void
elasticnet_dual
(
float64_t
*ff,
float64_t
*gg,
float64_t
*
hh
,
351
const
float64_t
&del,
const
float64_t
* nm, int32_t len,
352
const
float64_t
&lambda);
353
365
float64_t
compute_optimal_betas_directly
(
366
float64_t
* beta,
const
float64_t
* old_beta,
const
int32_t num_kernels,
367
const
float64_t
* sumw,
const
float64_t
suma,
const
float64_t
mkl_objective);
368
380
float64_t
compute_optimal_betas_block_norm
(
381
float64_t
* beta,
const
float64_t
* old_beta,
const
int32_t num_kernels,
382
const
float64_t
* sumw,
const
float64_t
suma,
const
float64_t
mkl_objective);
383
395
float64_t
compute_optimal_betas_newton
(
float64_t
* beta,
const
float64_t
* old_beta,
396
int32_t num_kernels,
const
float64_t
* sumw,
float64_t
suma,
float64_t
mkl_objective);
397
402
virtual
bool
converged
()
403
{
404
return
w_gap
<
mkl_epsilon
;
405
}
406
408
void
init_solver
();
409
410
#ifdef USE_CPLEX
411
415
bool
init_cplex
();
416
418
void
set_qnorm_constraints
(
float64_t
* beta, int32_t num_kernels);
419
424
bool
cleanup_cplex
();
425
#endif
426
427
#ifdef USE_GLPK
428
432
bool
init_glpk
();
433
438
bool
cleanup_glpk
();
439
444
bool
check_lpx_status
(LPX *lp);
445
#endif
446
447
protected
:
449
CSVM
*
svm
;
451
float64_t
C_mkl
;
453
float64_t
mkl_norm
;
459
float64_t
ent_lambda
;
460
463
float64_t
mkl_block_norm
;
464
466
float64_t
*
beta_local
;
468
int32_t
mkl_iterations
;
470
float64_t
mkl_epsilon
;
472
bool
interleaved_optimization
;
473
475
float64_t
*
W
;
476
478
float64_t
w_gap
;
480
float64_t
rho
;
481
483
CTime
training_time_clock
;
484
485
#ifdef USE_CPLEX
486
487
CPXENVptr
env
;
489
CPXLPptr
lp_cplex
;
490
#endif
491
492
#ifdef USE_GLPK
493
494
LPX*
lp_glpk
;
495
#endif
496
497
bool
lp_initialized
;
498
};
499
}
500
#endif //__MKL_H__
SHOGUN
Machine Learning Toolbox - Documentation