SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DistanceKernel.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) 2007-2009 Christian Gehl
8  * Copyright (C) 2007-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 #include <shogun/lib/config.h>
12 
13 #include <shogun/lib/common.h>
14 #include <shogun/io/SGIO.h>
17 
18 using namespace shogun;
19 
21 : CKernel(0), distance(NULL), width(0.0)
22 {
24 }
25 
27 : CKernel(size), distance(d)
28 {
30  set_width(w);
33 }
34 
36  CFeatures *l, CFeatures *r, float64_t w , CDistance* d)
37 : CKernel(10), distance(d)
38 {
39  set_width(w);
42  init(l, r);
44 }
45 
47 {
48  // important to have the cleanup of CKernel first, it calls get_name which
49  // uses the distance
50  cleanup();
52 }
53 
54 bool CDistanceKernel::init(CFeatures* l, CFeatures* r)
55 {
57  CKernel::init(l,r);
58  distance->init(l,r);
59  return init_normalizer();
60 }
61 
62 float64_t CDistanceKernel::compute(int32_t idx_a, int32_t idx_b)
63 {
64  float64_t result=distance->distance(idx_a, idx_b);
65  return exp(-result/width);
66 }
67 
69 {
70  SG_ADD(&width, "width", "Kernel width.", MS_AVAILABLE);
71  SG_ADD((CSGObject**) &distance, "distance", "Distance to be used.",
72  MS_AVAILABLE);
73 }

SHOGUN Machine Learning Toolbox - Documentation