SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RationalQuadraticKernel.cpp
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) 2011 RafaƂ Surowiecki
8  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9  */
10 
13 
14 using namespace shogun;
15 
16 CRationalQuadraticKernel::CRationalQuadraticKernel(): CKernel(0), m_distance(NULL), m_coef(0.001)
17 {
18  init();
19 }
20 
22 : CKernel(cache), m_distance(distance), m_coef(coef)
23 {
26  init();
27 }
28 
30 : CKernel(10), m_distance(dist), m_coef(coef)
31 {
34  init();
35  init(l, r);
36 }
37 
39 {
40  cleanup();
42 }
43 
44 bool CRationalQuadraticKernel::init(CFeatures* l, CFeatures* r)
45 {
47  CKernel::init(l,r);
48  m_distance->init(l,r);
49  return init_normalizer();
50 }
51 
52 float64_t CRationalQuadraticKernel::compute(int32_t idx_a, int32_t idx_b)
53 {
54  float64_t dist = m_distance->distance(idx_a, idx_b);
55  float64_t pDist = dist * dist;
56  return 1-pDist/(pDist+m_coef);
57 }
58 
59 void CRationalQuadraticKernel::init()
60 {
61  SG_ADD(&m_coef, "coef", "Kernel coefficient.", MS_AVAILABLE);
62  SG_ADD((CSGObject**) &m_distance, "distance", "Distance to be used.",
63  MS_AVAILABLE);
64 }
65 
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
virtual void cleanup()
Definition: Kernel.cpp:173
Class Distance, a base class for all the distances used in the Shogun toolbox.
Definition: Distance.h:87
#define SG_REF(x)
Definition: SGObject.h:54
virtual bool init(CFeatures *l, CFeatures *r)
#define ASSERT(x)
Definition: SGIO.h:201
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
CDistance * m_distance
distance to be used
float64_t m_coef
coefficient parameter of kernel
double float64_t
Definition: common.h:50
virtual bool init_normalizer()
Definition: Kernel.cpp:168
virtual float64_t distance(int32_t idx_a, int32_t idx_b)
Definition: Distance.cpp:206
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The class Features is the base class of all feature objects.
Definition: Features.h:68
virtual float64_t compute(int32_t idx_a, int32_t idx_b)
The Kernel base class.
Definition: Kernel.h:159
#define SG_ADD(...)
Definition: SGObject.h:84
virtual bool init(CFeatures *lhs, CFeatures *rhs)
Definition: Distance.cpp:78

SHOGUN Machine Learning Toolbox - Documentation