SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ExponentialKernel.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  * Gaussian Kernel used as template, attribution:
8  * Written (W) 1999-2010 Soeren Sonnenburg
9  * Exponential Kernel
10  * Written (W) 2011 Justin Patera
11  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
12  */
13 
14 #include <shogun/lib/common.h>
15 #include <shogun/base/Parameter.h>
18 #include <shogun/io/SGIO.h>
19 
20 using namespace shogun;
21 
23  : CDotKernel(), m_distance(NULL), m_width(1)
24 {
25  init();
26 }
27 
29  CDotFeatures* l, CDotFeatures* r, float64_t width, CDistance* distance, int32_t size)
30 : CDotKernel(size), m_distance(distance), m_width(width)
31 {
32  init();
33  ASSERT(distance)
34  SG_REF(distance);
35  init(l,r);
36 }
37 
39 {
40  cleanup();
42 }
43 
45 {
47 }
48 
49 bool CExponentialKernel::init(CFeatures* l, CFeatures* r)
50 {
52  CDotKernel::init(l, r);
53  m_distance->init(l, r);
54  return init_normalizer();
55 }
56 
57 float64_t CExponentialKernel::compute(int32_t idx_a, int32_t idx_b)
58 {
60  float64_t dist=m_distance->distance(idx_a, idx_b);
61  return exp(-dist/m_width);
62 }
63 
65 {
67 }
68 
69 
70 void CExponentialKernel::init()
71 {
72  SG_ADD(&m_width, "width", "Kernel width.", MS_AVAILABLE);
73  SG_ADD((CSGObject**) &m_distance, "distance", "Distance to be used.",
74  MS_AVAILABLE);
75 }
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
virtual void load_serializable_post()
Definition: Kernel.cpp:916
virtual bool init(CFeatures *l, CFeatures *r)
virtual void cleanup()
Definition: Kernel.cpp:162
Class Distance, a base class for all the distances used in the Shogun toolbox.
Definition: Distance.h:81
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
Features that support dot products among other operations.
Definition: DotFeatures.h:44
#define SG_REF(x)
Definition: SGObject.h:51
Template class DotKernel is the base class for kernels working on DotFeatures.
Definition: DotKernel.h:31
#define ASSERT(x)
Definition: SGIO.h:201
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
double float64_t
Definition: common.h:50
virtual bool init_normalizer()
Definition: Kernel.cpp:157
virtual float64_t distance(int32_t idx_a, int32_t idx_b)
Definition: Distance.cpp:189
#define SG_UNREF(x)
Definition: SGObject.h:52
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)
#define SG_ADD(...)
Definition: SGObject.h:81
virtual bool init(CFeatures *lhs, CFeatures *rhs)
Definition: Distance.cpp:78

SHOGUN Machine Learning Toolbox - Documentation