SHOGUN  v3.0.0
 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 
15 namespace shogun
16 {
32 {
33  public:
40  {
41  scale=c;
42 
43  SG_ADD(&scale, "scale", "Scale quotient by which kernel is scaled.",
44  MS_AVAILABLE);
45  }
46 
49  {
50  }
51 
54  virtual bool init(CKernel* k)
55  {
56  if (scale<=0)
57  {
58  ASSERT(k)
59  int32_t num=k->get_num_vec_lhs();
60  ASSERT(num>0)
61 
62  CFeatures* old_lhs=k->lhs;
63  CFeatures* old_rhs=k->rhs;
64  k->lhs=old_lhs;
65  k->rhs=old_lhs;
66 
67  float64_t sum=0;
68  for (int32_t i=0; i<num; i++)
69  sum+=k->compute(i, i);
70 
71  scale=sum/num;
72  k->lhs=old_lhs;
73  k->rhs=old_rhs;
74  }
75 
76  return true;
77  }
78 
85  float64_t value, int32_t idx_lhs, int32_t idx_rhs)
86  {
87  return value/scale;
88  }
89 
94  virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs)
95  {
96  return value/sqrt(scale);
97  }
98 
103  virtual float64_t normalize_rhs(float64_t value, int32_t idx_rhs)
104  {
105  return value/sqrt(scale);
106  }
107 
109  virtual const char* get_name() const { return "AvgDiagKernelNormalizer"; }
110 
111  protected:
114 };
115 }
116 #endif

SHOGUN Machine Learning Toolbox - Documentation