SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MultitaskKernelMklNormalizer.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) 2010 Christian Widmer
8  * Copyright (C) 2010 Max-Planck-Society
9  */
10 
11 #ifndef _MULTITASKKERNELMKLNORMALIZER_H___
12 #define _MULTITASKKERNELMKLNORMALIZER_H___
13 
14 #include <shogun/lib/config.h>
15 
17 #include <shogun/kernel/Kernel.h>
18 #include <algorithm>
19 #include <string>
20 
21 namespace shogun
22 {
23 
24 
29 {
30 
31 public:
32 
36  {
38  }
39 
40 
43  virtual bool init(CKernel* k)
44  {
45 
46  //same as first-element normalizer
47  CFeatures* old_lhs=k->lhs;
48  CFeatures* old_rhs=k->rhs;
49  k->lhs=old_lhs;
50  k->rhs=old_lhs;
51 
52  if (std::string(k->get_name()) == "WeightedDegree") {
53  SG_INFO("using first-element normalization\n")
54  scale=k->compute(0, 0);
55  } else {
56  SG_INFO("no inner normalization for non-WDK kernel\n")
57  scale=1.0;
58  }
59 
60 
61  k->lhs=old_lhs;
62  k->rhs=old_rhs;
63 
64  ASSERT(k)
65  int32_t num_lhs = k->get_num_vec_lhs();
66  int32_t num_rhs = k->get_num_vec_rhs();
67  ASSERT(num_lhs>0)
68  ASSERT(num_rhs>0)
69 
70 
71  return true;
72  }
73 
74 
75 
80  virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs)
81  {
82  SG_ERROR("normalize_lhs not implemented")
83  return 0;
84  }
85 
90  virtual float64_t normalize_rhs(float64_t value, int32_t idx_rhs)
91  {
92  SG_ERROR("normalize_rhs not implemented")
93  return 0;
94  }
95 
96 public:
97 
98 
102  virtual float64_t get_beta(int32_t idx) = 0;
103 
108  virtual void set_beta(int32_t idx, float64_t weight) = 0;
109 
110 
114  virtual int32_t get_num_betas() = 0;
115 
116 
118  virtual const char* get_name() const
119  {
120  return "MultitaskKernelMklNormalizer";
121  }
122 
123 protected:
124 
125 
128 
129 };
130 }
131 #endif
virtual const char * get_name() const =0
#define SG_INFO(...)
Definition: SGIO.h:118
virtual float64_t compute(int32_t x, int32_t y)=0
virtual void set_beta(int32_t idx, float64_t weight)=0
#define SG_ERROR(...)
Definition: SGIO.h:129
virtual float64_t normalize_rhs(float64_t value, int32_t idx_rhs)
virtual int32_t get_num_vec_lhs()
Definition: Kernel.h:517
#define ASSERT(x)
Definition: SGIO.h:201
double float64_t
Definition: common.h:50
The class Kernel Normalizer defines a function to post-process kernel values.
virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs)
virtual int32_t get_num_vec_rhs()
Definition: Kernel.h:526
CFeatures * rhs
feature vectors to occur on right hand side
Definition: Kernel.h:1062
Base-class for parameterized Kernel Normalizers.
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
CFeatures * lhs
feature vectors to occur on left hand side
Definition: Kernel.h:1060
The class Features is the base class of all feature objects.
Definition: Features.h:68
The Kernel base class.
Definition: Kernel.h:159
virtual float64_t get_beta(int32_t idx)=0

SHOGUN Machine Learning Toolbox - Documentation