SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RidgeKernelNormalizer.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  */
10 
11 #ifndef _RIDGEKERNELNORMALIZER_H___
12 #define _RIDGEKERNELNORMALIZER_H___
13 
14 #include <shogun/lib/config.h>
15 
17 
18 namespace shogun
19 {
46 {
47  public:
60  {
61  SG_ADD(&scale, "scale", "Scale quotient by which kernel is scaled.",
62  MS_AVAILABLE);
63  SG_ADD(&ridge, "ridge", "Ridge added to diagonal.", MS_AVAILABLE);
64 
65  scale=c;
66  ridge=r;
67  }
68 
71  {
72  }
73 
76  virtual bool init(CKernel* k)
77  {
78  if (scale<=0)
79  {
80  ASSERT(k)
81  int32_t num=k->get_num_vec_lhs();
82  ASSERT(num>0)
83 
84  CFeatures* old_lhs=k->lhs;
85  CFeatures* old_rhs=k->rhs;
86  k->lhs=old_lhs;
87  k->rhs=old_lhs;
88 
89  float64_t sum=0;
90  for (int32_t i=0; i<num; i++)
91  sum+=k->compute(i, i);
92 
93  scale=sum/num;
94  k->lhs=old_lhs;
95  k->rhs=old_rhs;
96  }
97 
98  ridge*=scale;
99  return true;
100  }
101 
108  float64_t value, int32_t idx_lhs, int32_t idx_rhs)
109  {
110  if (idx_lhs==idx_rhs)
111  return value+ridge;
112  else
113  return value;
114  }
115 
120  virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs)
121  {
122  SG_ERROR("linadd not supported with Ridge normalization.\n")
123  return 0;
124  }
125 
130  virtual float64_t normalize_rhs(float64_t value, int32_t idx_rhs)
131  {
132  SG_ERROR("linadd not supported with Ridge normalization.\n")
133  return 0;
134  }
135 
137  virtual const char* get_name() const { return "RidgeKernelNormalizer"; }
138 
139  protected:
144 };
145 }
146 #endif // _RIDGEKERNELNORMALIZER_H___

SHOGUN Machine Learning Toolbox - Documentation