SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
15 #include <shogun/kernel/Kernel.h>
16 #include <algorithm>
17 #include <string>
18 
19 namespace shogun
20 {
21 
22 
27 {
28 
29 public:
30 
34  {
36  }
37 
38 
41  virtual bool init(CKernel* k)
42  {
43 
44  //same as first-element normalizer
45  CFeatures* old_lhs=k->lhs;
46  CFeatures* old_rhs=k->rhs;
47  k->lhs=old_lhs;
48  k->rhs=old_lhs;
49 
50  if (std::string(k->get_name()) == "WeightedDegree") {
51  SG_INFO("using first-element normalization\n");
52  scale=k->compute(0, 0);
53  } else {
54  SG_INFO("no inner normalization for non-WDK kernel\n");
55  scale=1.0;
56  }
57 
58 
59  k->lhs=old_lhs;
60  k->rhs=old_rhs;
61 
62  ASSERT(k);
63  int32_t num_lhs = k->get_num_vec_lhs();
64  int32_t num_rhs = k->get_num_vec_rhs();
65  ASSERT(num_lhs>0);
66  ASSERT(num_rhs>0);
67 
68 
69  return true;
70  }
71 
72 
73 
78  inline virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs)
79  {
80  SG_ERROR("normalize_lhs not implemented");
81  return 0;
82  }
83 
88  inline virtual float64_t normalize_rhs(float64_t value, int32_t idx_rhs)
89  {
90  SG_ERROR("normalize_rhs not implemented");
91  return 0;
92  }
93 
94 public:
95 
96 
100  virtual float64_t get_beta(int32_t idx) = 0;
101 
106  virtual void set_beta(int32_t idx, float64_t weight) = 0;
107 
108 
112  virtual int32_t get_num_betas() = 0;
113 
114 
116  inline virtual const char* get_name() const
117  {
118  return "MultitaskKernelMklNormalizer";
119  }
120 
121 protected:
122 
123 
126 
127 };
128 }
129 #endif

SHOGUN Machine Learning Toolbox - Documentation