SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AvgDiagKernelNormalizer.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 _AVGDIAGKERNELNORMALIZER_H___
12 #define _AVGDIAGKERNELNORMALIZER_H___
13 
14 #include <shogun/lib/config.h>
15 
17 namespace shogun
18 {
34 {
35  public:
42  {
43  scale=c;
44 
45  SG_ADD(&scale, "scale", "Scale quotient by which kernel is scaled.",
46  MS_AVAILABLE);
47  }
48 
51  {
52  }
53 
56  virtual bool init(CKernel* k)
57  {
58  if (scale<=0)
59  {
60  ASSERT(k)
61  int32_t num=k->get_num_vec_lhs();
62  ASSERT(num>0)
63 
64  CFeatures* old_lhs=k->lhs;
65  CFeatures* old_rhs=k->rhs;
66  k->lhs=old_lhs;
67  k->rhs=old_lhs;
68 
69  float64_t sum=0;
70  for (int32_t i=0; i<num; i++)
71  sum+=k->compute(i, i);
72 
73  scale=sum/num;
74  k->lhs=old_lhs;
75  k->rhs=old_rhs;
76  }
77 
78  return true;
79  }
80 
87  float64_t value, int32_t idx_lhs, int32_t idx_rhs)
88  {
89  return value/scale;
90  }
91 
96  virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs)
97  {
98  return value/sqrt(scale);
99  }
100 
105  virtual float64_t normalize_rhs(float64_t value, int32_t idx_rhs)
106  {
107  return value/sqrt(scale);
108  }
109 
111  virtual const char* get_name() const { return "AvgDiagKernelNormalizer"; }
112 
113  protected:
116 };
117 }
118 #endif

SHOGUN Machine Learning Toolbox - Documentation