SHOGUN  6.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 
98  virtual CSGObject* clone();
99 
105  {
106  set_svm(s);
107  }
108 
113  inline void set_svm(CSVM* s)
114  {
115  SG_REF(s);
116  SG_UNREF(svm);
117  svm=s;
118  }
119 
124  inline CSVM* get_svm()
125  {
126  SG_REF(svm);
127  return svm;
128  }
129 
134  inline void set_C_mkl(float64_t C) { C_mkl = C; }
135 
140  void set_mkl_norm(float64_t norm);
141 
148  void set_elasticnet_lambda(float64_t elasticnet_lambda);
149 
155 
161  inline void set_interleaved_optimization_enabled(bool enable)
162  {
164  }
165 
171  {
173  }
174 
180  {
182  }
183 
189 
190 
196 
201  inline void set_mkl_epsilon(float64_t eps) { mkl_epsilon=eps; }
202 
207  inline float64_t get_mkl_epsilon() { return mkl_epsilon; }
208 
213  inline int32_t get_mkl_iterations() { return mkl_iterations; }
214 
225  virtual bool perform_mkl_step(const float64_t* sumw, float64_t suma);
226 
234  const float64_t* sumw, const float64_t suma)
235  {
236  return mkl->perform_mkl_step(sumw, suma);
237  }
238 
239 
243  virtual float64_t compute_sum_alpha()=0;
244 
249  virtual void compute_sum_beta(float64_t* sumw);
250 
252  virtual const char* get_name() const { return "MKL"; }
253 
254  protected:
263  virtual bool train_machine(CFeatures* data=NULL);
264 
268  virtual void init_training()=0;
269 
285  void perform_mkl_step(float64_t* beta, float64_t* old_beta, int num_kernels,
286  int32_t* label, int32_t* active2dnum,
287  float64_t* a, float64_t* lin, float64_t* sumw, int32_t& inner_iters);
288 
289 
303  float64_t compute_optimal_betas_via_cplex(float64_t* beta, const float64_t* old_beta, int32_t num_kernels,
304  const float64_t* sumw, float64_t suma, int32_t& inner_iters);
305 
319  int num_kernels, const float64_t* sumw, float64_t suma, int32_t& inner_iters);
320 
333  float64_t* beta, const float64_t* old_beta, const int32_t num_kernels,
334  const float64_t* sumw, const float64_t suma, const float64_t mkl_objective);
335 
337  inline void elasticnet_transform(float64_t *beta, float64_t lmd, int32_t len)
338  {
339  for (int32_t i=0;i <len;i++)
340  beta[i]=beta[i]/(1.0-lmd+lmd*beta[i]);
341  }
342 
344  void elasticnet_dual(float64_t *ff, float64_t *gg, float64_t *hh,
345  const float64_t &del, const float64_t* nm, int32_t len,
346  const float64_t &lambda);
347 
360  float64_t* beta, const float64_t* old_beta, const int32_t num_kernels,
361  const float64_t* sumw, const float64_t suma, const float64_t mkl_objective);
362 
375  float64_t* beta, const float64_t* old_beta, const int32_t num_kernels,
376  const float64_t* sumw, const float64_t suma, const float64_t mkl_objective);
377 
390  int32_t num_kernels, const float64_t* sumw, float64_t suma, float64_t mkl_objective);
391 
396  virtual bool converged()
397  {
398  return w_gap<mkl_epsilon;
399  }
400 
402  void init_solver();
403 
404  private:
405  void register_params();
406 
407  protected:
420 
424 
428 
430  int32_t mkl_iterations;
435 
440 
443 
445  class Self;
446  Unique<Self> self;
447 
450 };
451 }
452 #endif //__MKL_H__
Class Time that implements a stopwatch based on either cpu time or wall clock time.
Definition: Time.h:42
float64_t get_mkl_epsilon()
Definition: MKL.h:207
void set_mkl_block_norm(float64_t q)
Definition: MKL.cpp:533
virtual bool converged()
Definition: MKL.h:396
float64_t compute_svm_primal_objective()
Definition: SVM.cpp:262
virtual CSGObject * clone()
Definition: MKL.cpp:293
float64_t mkl_epsilon
Definition: MKL.h:432
float64_t ent_lambda
Definition: MKL.h:419
virtual void init_training()=0
void elasticnet_transform(float64_t *beta, float64_t lmd, int32_t len)
Definition: MKL.h:337
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:804
bool get_interleaved_optimization_enabled()
Definition: MKL.h:170
CSVM * svm
Definition: MKL.h:409
virtual void compute_sum_beta(float64_t *sumw)
Definition: MKL.cpp:1618
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:840
CMKL * mkl
Definition: SVM.h:287
int32_t beta_local_size
Definition: MKL.h:427
void set_mkl_norm(float64_t norm)
Definition: MKL.cpp:511
int32_t get_mkl_iterations()
Definition: MKL.h:213
CSVM * get_svm()
Definition: MKL.h:124
#define SG_REF(x)
Definition: SGObject.h:52
float64_t mkl_norm
Definition: MKL.h:413
virtual ~CMKL()
Definition: MKL.cpp:251
float64_t compute_elasticnet_dual_objective()
Definition: MKL.cpp:729
virtual bool perform_mkl_step(const float64_t *sumw, float64_t suma)
Definition: MKL.cpp:541
virtual float64_t compute_mkl_dual_objective()
Definition: MKL.cpp:1663
void set_mkl_epsilon(float64_t eps)
Definition: MKL.h:201
void set_interleaved_optimization_enabled(bool enable)
Definition: MKL.h:161
CMKL(CSVM *s=NULL)
Definition: MKL.cpp:243
int32_t mkl_iterations
Definition: MKL.h:430
float64_t w_gap
Definition: MKL.h:437
float64_t C_mkl
Definition: MKL.h:411
CTime training_time_clock
Definition: MKL.h:442
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:125
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:929
void set_constraint_generator(CSVM *s)
Definition: MKL.h:104
bool lp_initialized
Definition: MKL.h:449
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:702
double float64_t
Definition: common.h:60
Multiple Kernel Learning.
Definition: MKL.h:85
bool interleaved_optimization
Definition: MKL.h:434
float64_t * beta_local
Definition: MKL.h:426
void set_svm(CSVM *s)
Definition: MKL.h:113
void init_solver()
Definition: MKL.cpp:317
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:610
#define SG_UNREF(x)
Definition: SGObject.h:53
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:1121
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:334
virtual const char * get_name() const
Definition: MKL.h:252
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:520
float64_t compute_mkl_primal_objective()
Definition: MKL.h:179
float64_t mkl_block_norm
Definition: MKL.h:423
float64_t rho
Definition: MKL.h:439
static bool perform_mkl_step_helper(CMKL *mkl, const float64_t *sumw, const float64_t suma)
Definition: MKL.h:233
void set_C_mkl(float64_t C)
Definition: MKL.h:134
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:1464

SHOGUN Machine Learning Toolbox - Documentation