SHOGUN  5.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
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 #include <shogun/lib/common.h>
17 #include <shogun/lib/Time.h>
19 #include <shogun/kernel/Kernel.h>
21 
22 namespace shogun
23 {
85 class CMKL : public CSVM
86 {
87  public:
92  CMKL(CSVM* s=NULL);
93 
96  virtual ~CMKL();
97 
103  {
104  set_svm(s);
105  }
106 
111  inline void set_svm(CSVM* s)
112  {
113  SG_REF(s);
114  SG_UNREF(svm);
115  svm=s;
116  }
117 
122  inline CSVM* get_svm()
123  {
124  SG_REF(svm);
125  return svm;
126  }
127 
132  inline void set_C_mkl(float64_t C) { C_mkl = C; }
133 
138  void set_mkl_norm(float64_t norm);
139 
146  void set_elasticnet_lambda(float64_t elasticnet_lambda);
147 
153 
159  inline void set_interleaved_optimization_enabled(bool enable)
160  {
162  }
163 
169  {
171  }
172 
178  {
180  }
181 
187 
188 
194 
199  inline void set_mkl_epsilon(float64_t eps) { mkl_epsilon=eps; }
200 
205  inline float64_t get_mkl_epsilon() { return mkl_epsilon; }
206 
211  inline int32_t get_mkl_iterations() { return mkl_iterations; }
212 
223  virtual bool perform_mkl_step(const float64_t* sumw, float64_t suma);
224 
232  const float64_t* sumw, const float64_t suma)
233  {
234  return mkl->perform_mkl_step(sumw, suma);
235  }
236 
237 
241  virtual float64_t compute_sum_alpha()=0;
242 
247  virtual void compute_sum_beta(float64_t* sumw);
248 
250  virtual const char* get_name() const { return "MKL"; }
251 
252  protected:
261  virtual bool train_machine(CFeatures* data=NULL);
262 
266  virtual void init_training()=0;
267 
283  void perform_mkl_step(float64_t* beta, float64_t* old_beta, int num_kernels,
284  int32_t* label, int32_t* active2dnum,
285  float64_t* a, float64_t* lin, float64_t* sumw, int32_t& inner_iters);
286 
287 
301  float64_t compute_optimal_betas_via_cplex(float64_t* beta, const float64_t* old_beta, int32_t num_kernels,
302  const float64_t* sumw, float64_t suma, int32_t& inner_iters);
303 
317  int num_kernels, const float64_t* sumw, float64_t suma, int32_t& inner_iters);
318 
331  float64_t* beta, const float64_t* old_beta, const int32_t num_kernels,
332  const float64_t* sumw, const float64_t suma, const float64_t mkl_objective);
333 
335  inline void elasticnet_transform(float64_t *beta, float64_t lmd, int32_t len)
336  {
337  for (int32_t i=0;i <len;i++)
338  beta[i]=beta[i]/(1.0-lmd+lmd*beta[i]);
339  }
340 
342  void elasticnet_dual(float64_t *ff, float64_t *gg, float64_t *hh,
343  const float64_t &del, const float64_t* nm, int32_t len,
344  const float64_t &lambda);
345 
358  float64_t* beta, const float64_t* old_beta, const int32_t num_kernels,
359  const float64_t* sumw, const float64_t suma, const float64_t mkl_objective);
360 
373  float64_t* beta, const float64_t* old_beta, const int32_t num_kernels,
374  const float64_t* sumw, const float64_t suma, const float64_t mkl_objective);
375 
388  int32_t num_kernels, const float64_t* sumw, float64_t suma, float64_t mkl_objective);
389 
394  virtual bool converged()
395  {
396  return w_gap<mkl_epsilon;
397  }
398 
400  void init_solver();
401 
402  protected:
415 
419 
423  int32_t mkl_iterations;
428 
431 
436 
439 
441  class Self;
442  Unique<Self> self;
443 
446 };
447 }
448 #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:205
void set_mkl_block_norm(float64_t q)
Definition: MKL.cpp:480
virtual bool converged()
Definition: MKL.h:394
float64_t * W
Definition: MKL.h:430
float64_t compute_svm_primal_objective()
Definition: SVM.cpp:267
float64_t mkl_epsilon
Definition: MKL.h:425
float64_t ent_lambda
Definition: MKL.h:414
virtual void init_training()=0
void elasticnet_transform(float64_t *beta, float64_t lmd, int32_t len)
Definition: MKL.h:335
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:751
bool get_interleaved_optimization_enabled()
Definition: MKL.h:168
CSVM * svm
Definition: MKL.h:404
virtual void compute_sum_beta(float64_t *sumw)
Definition: MKL.cpp:1565
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:787
CMKL * mkl
Definition: SVM.h:272
void set_mkl_norm(float64_t norm)
Definition: MKL.cpp:458
int32_t get_mkl_iterations()
Definition: MKL.h:211
CSVM * get_svm()
Definition: MKL.h:122
#define SG_REF(x)
Definition: SGObject.h:54
float64_t mkl_norm
Definition: MKL.h:408
virtual ~CMKL()
Definition: MKL.cpp:254
float64_t compute_elasticnet_dual_objective()
Definition: MKL.cpp:676
virtual bool perform_mkl_step(const float64_t *sumw, float64_t suma)
Definition: MKL.cpp:488
virtual float64_t compute_mkl_dual_objective()
Definition: MKL.cpp:1610
void set_mkl_epsilon(float64_t eps)
Definition: MKL.h:199
void set_interleaved_optimization_enabled(bool enable)
Definition: MKL.h:159
CMKL(CSVM *s=NULL)
Definition: MKL.cpp:243
int32_t mkl_iterations
Definition: MKL.h:423
float64_t w_gap
Definition: MKL.h:433
float64_t C_mkl
Definition: MKL.h:406
CTime training_time_clock
Definition: MKL.h:438
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:876
void set_constraint_generator(CSVM *s)
Definition: MKL.h:102
bool lp_initialized
Definition: MKL.h:445
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:649
double float64_t
Definition: common.h:50
Multiple Kernel Learning.
Definition: MKL.h:85
bool interleaved_optimization
Definition: MKL.h:427
float64_t * beta_local
Definition: MKL.h:421
void set_svm(CSVM *s)
Definition: MKL.h:111
void init_solver()
Definition: MKL.cpp:265
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:557
#define SG_UNREF(x)
Definition: SGObject.h:55
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:1068
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual float64_t compute_sum_alpha()=0
virtual bool train_machine(CFeatures *data=NULL)
Definition: MKL.cpp:282
virtual const char * get_name() const
Definition: MKL.h:250
The class Features is the base class of all feature objects.
Definition: Features.h:68
A generic Support Vector Machine Interface.
Definition: SVM.h:49
void set_elasticnet_lambda(float64_t elasticnet_lambda)
Definition: MKL.cpp:467
float64_t compute_mkl_primal_objective()
Definition: MKL.h:177
float64_t mkl_block_norm
Definition: MKL.h:418
float64_t rho
Definition: MKL.h:435
static bool perform_mkl_step_helper(CMKL *mkl, const float64_t *sumw, const float64_t suma)
Definition: MKL.h:231
void set_C_mkl(float64_t C)
Definition: MKL.h:132
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:1411

SHOGUN Machine Learning Toolbox - Documentation