SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
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__

SHOGUN Machine Learning Toolbox - Documentation