SHOGUN  v2.0.0
 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 #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>
27 #include <shogun/kernel/Kernel.h>
29 
30 namespace shogun
31 {
93 class CMKL : public CSVM
94 {
95  public:
100  CMKL(CSVM* s=NULL);
101 
104  virtual ~CMKL();
105 
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 
147 
154  void set_elasticnet_lambda(float64_t elasticnet_lambda);
155 
161 
167  inline void set_interleaved_optimization_enabled(bool enable)
168  {
170  }
171 
177  {
179  }
180 
186  {
188  }
189 
195 
196 
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 
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 
325  int num_kernels, const float64_t* sumw, float64_t suma, int32_t& inner_iters);
326 
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 
351  const float64_t &del, const float64_t* nm, int32_t len,
352  const float64_t &lambda);
353 
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 
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 
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:
460 
464 
468  int32_t mkl_iterations;
473 
476 
481 
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 
498 };
499 }
500 #endif //__MKL_H__

SHOGUN Machine Learning Toolbox - Documentation