SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SphericalKernel.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  * Based on GaussianKernel, Written (W) 1999-2010 Soeren Sonnenburg
8  * Written (W) 2011 Shashwat Lal Das
9  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
10  */
11 
14 
15 using namespace shogun;
16 
18 {
19  init();
20  set_sigma(1.0);
21 }
22 
24 : CKernel(size), distance(dist)
25 {
28  init();
29  set_sigma(sig);
30 }
31 
33  CFeatures *l, CFeatures *r, float64_t sig, CDistance* dist)
34 : CKernel(10), distance(dist)
35 {
38  init();
39  set_sigma(sig);
40  init(l, r);
41 }
42 
44 {
45  cleanup();
47 }
48 
50 {
52  CKernel::init(l,r);
53  distance->init(l,r);
54  return init_normalizer();
55 }
56 
58 {
59  m_parameters->add((CSGObject**) &distance, "distance", "Distance to be used.");
60  m_parameters->add(&sigma, "sigma", "Sigma kernel parameter.");
61 }
62 
63 float64_t CSphericalKernel::compute(int32_t idx_a, int32_t idx_b)
64 {
65  float64_t dist=distance->distance(idx_a, idx_b);
66  float64_t ds_ratio=dist/sigma;
67 
68  if (dist < sigma)
69  return 1.0-1.5*(ds_ratio)+0.5*(ds_ratio*ds_ratio*ds_ratio);
70  else
71  return 0;
72 }

SHOGUN Machine Learning Toolbox - Documentation