SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 }

SHOGUN Machine Learning Toolbox - Documentation