SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 #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>
29 #include <shogun/kernel/Kernel.h>
31 
32 namespace shogun
33 {
95 class CMKL : public CSVM
96 {
97  public:
102  CMKL(CSVM* s=NULL);
103 
106  virtual ~CMKL();
107 
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 
163 
169  inline void set_interleaved_optimization_enabled(bool enable)
170  {
172  }
173 
179  {
181  }
182 
188  {
190  }
191 
197 
198 
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 
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 
327  int num_kernels, const float64_t* sumw, float64_t suma, int32_t& inner_iters);
328 
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 
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 
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 
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:
462 
466 
470  int32_t mkl_iterations;
475 
478 
483 
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 
503 };
504 }
505 #endif //__MKL_H__
Class Time that implements a stopwatch based on either cpu time or wall clock time.
Definition: Time.h:47
float64_t get_mkl_epsilon()
Definition: MKL.h:215
void set_mkl_block_norm(float64_t q)
Definition: MKL.cpp:395
virtual bool converged()
Definition: MKL.h:404
bool cleanup_cplex()
Definition: MKL.cpp:119
bool check_glp_status(glp_prob *lp)
Definition: MKL.cpp:179
bool init_cplex()
Definition: MKL.cpp:70
float64_t * W
Definition: MKL.h:477
float64_t compute_svm_primal_objective()
Definition: SVM.cpp:267
float64_t mkl_epsilon
Definition: MKL.h:472
float64_t ent_lambda
Definition: MKL.h:461
virtual void init_training()=0
void elasticnet_transform(float64_t *beta, float64_t lmd, int32_t len)
Definition: MKL.h:345
float64_t compute_optimal_betas_block_norm(float64_t *beta, const float64_t *old_beta, const int32_t num_kernels, const float64_t *sumw, const float64_t suma, const float64_t mkl_objective)
Definition: MKL.cpp:666
CPXENVptr env
Definition: MKL.h:489
bool get_interleaved_optimization_enabled()
Definition: MKL.h:178
CSVM * svm
Definition: MKL.h:451
virtual void compute_sum_beta(float64_t *sumw)
Definition: MKL.cpp:1480
float64_t compute_optimal_betas_directly(float64_t *beta, const float64_t *old_beta, const int32_t num_kernels, const float64_t *sumw, const float64_t suma, const float64_t mkl_objective)
Definition: MKL.cpp:702
CMKL * mkl
Definition: SVM.h:272
void set_mkl_norm(float64_t norm)
Definition: MKL.cpp:373
int32_t get_mkl_iterations()
Definition: MKL.h:221
CSVM * get_svm()
Definition: MKL.h:132
CPXLPptr lp_cplex
Definition: MKL.h:491
#define SG_REF(x)
Definition: SGObject.h:51
float64_t mkl_norm
Definition: MKL.h:455
virtual ~CMKL()
Definition: MKL.cpp:41
float64_t compute_elasticnet_dual_objective()
Definition: MKL.cpp:591
virtual bool perform_mkl_step(const float64_t *sumw, float64_t suma)
Definition: MKL.cpp:403
virtual float64_t compute_mkl_dual_objective()
Definition: MKL.cpp:1525
void set_mkl_epsilon(float64_t eps)
Definition: MKL.h:209
void set_interleaved_optimization_enabled(bool enable)
Definition: MKL.h:169
CMKL(CSVM *s=NULL)
Definition: MKL.cpp:22
int32_t mkl_iterations
Definition: MKL.h:470
float64_t w_gap
Definition: MKL.h:480
float64_t C_mkl
Definition: MKL.h:453
CTime training_time_clock
Definition: MKL.h:485
float64_t compute_optimal_betas_newton(float64_t *beta, const float64_t *old_beta, int32_t num_kernels, const float64_t *sumw, float64_t suma, float64_t mkl_objective)
Definition: MKL.cpp:791
void set_constraint_generator(CSVM *s)
Definition: MKL.h:112
bool lp_initialized
Definition: MKL.h:502
void elasticnet_dual(float64_t *ff, float64_t *gg, float64_t *hh, const float64_t &del, const float64_t *nm, int32_t len, const float64_t &lambda)
Definition: MKL.cpp:564
double float64_t
Definition: common.h:50
glp_prob * lp_glpk
Definition: MKL.h:496
Multiple Kernel Learning.
Definition: MKL.h:95
void set_qnorm_constraints(float64_t *beta, int32_t num_kernels)
Definition: MKL.cpp:1575
bool interleaved_optimization
Definition: MKL.h:474
float64_t * beta_local
Definition: MKL.h:468
void set_svm(CSVM *s)
Definition: MKL.h:121
void init_solver()
Definition: MKL.cpp:52
float64_t compute_optimal_betas_elasticnet(float64_t *beta, const float64_t *old_beta, const int32_t num_kernels, const float64_t *sumw, const float64_t suma, const float64_t mkl_objective)
Definition: MKL.cpp:472
#define SG_UNREF(x)
Definition: SGObject.h:52
float64_t compute_optimal_betas_via_cplex(float64_t *beta, const float64_t *old_beta, int32_t num_kernels, const float64_t *sumw, float64_t suma, int32_t &inner_iters)
Definition: MKL.cpp:983
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
bool cleanup_glpk()
Definition: MKL.cpp:169
virtual float64_t compute_sum_alpha()=0
virtual bool train_machine(CFeatures *data=NULL)
Definition: MKL.cpp:197
virtual const char * get_name() const
Definition: MKL.h:260
The class Features is the base class of all feature objects.
Definition: Features.h:68
bool init_glpk()
Definition: MKL.cpp:155
A generic Support Vector Machine Interface.
Definition: SVM.h:49
void set_elasticnet_lambda(float64_t elasticnet_lambda)
Definition: MKL.cpp:382
float64_t compute_mkl_primal_objective()
Definition: MKL.h:187
float64_t mkl_block_norm
Definition: MKL.h:465
float64_t rho
Definition: MKL.h:482
glp_smcp * lp_glpk_parm
Definition: MKL.h:499
static bool perform_mkl_step_helper(CMKL *mkl, const float64_t *sumw, const float64_t suma)
Definition: MKL.h:241
void set_C_mkl(float64_t C)
Definition: MKL.h:142
float64_t compute_optimal_betas_via_glpk(float64_t *beta, const float64_t *old_beta, int num_kernels, const float64_t *sumw, float64_t suma, int32_t &inner_iters)
Definition: MKL.cpp:1326

SHOGUN Machine Learning Toolbox - Documentation