SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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
virtual float64_t normalize_rhs(float64_t value, int32_t idx_rhs)
virtual float64_t compute(int32_t x, int32_t y)=0
virtual int32_t get_num_vec_lhs()
Definition: Kernel.h:517
virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs)
virtual const char * get_name() const
#define ASSERT(x)
Definition: SGIO.h:201
double float64_t
Definition: common.h:50
float64_t scale
the constant scaling factor (avg of diagonal or user given const)
The class Kernel Normalizer defines a function to post-process kernel values.
CFeatures * rhs
feature vectors to occur on right hand side
Definition: Kernel.h:1062
virtual float64_t normalize(float64_t value, int32_t idx_lhs, int32_t idx_rhs)
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
Normalize the kernel by either a constant or the average value of the diagonal elements (depending on...
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
#define SG_ADD(...)
Definition: SGObject.h:84

SHOGUN Machine Learning Toolbox - Documentation