SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  register_params();
20  set_sigma(1.0);
21 }
22 
24 : CKernel(size), distance(dist)
25 {
28  register_params();
29  set_sigma(sig);
30 }
31 
33  CFeatures *l, CFeatures *r, float64_t sig, CDistance* dist)
34 : CKernel(10), distance(dist)
35 {
38  register_params();
39  set_sigma(sig);
40  init(l, r);
41 }
42 
44 {
45  cleanup();
47 }
48 
49 bool CSphericalKernel::init(CFeatures* l, CFeatures* r)
50 {
52  CKernel::init(l,r);
53  distance->init(l,r);
54  return init_normalizer();
55 }
56 
57 void CSphericalKernel::register_params()
58 {
59  SG_ADD((CSGObject**) &distance, "distance", "Distance to be used.",
60  MS_AVAILABLE);
61  SG_ADD(&sigma, "sigma", "Sigma kernel parameter.", MS_AVAILABLE);
62 }
63 
64 float64_t CSphericalKernel::compute(int32_t idx_a, int32_t idx_b)
65 {
66  float64_t dist=distance->distance(idx_a, idx_b);
67  float64_t ds_ratio=dist/sigma;
68 
69  if (dist < sigma)
70  return 1.0-1.5*(ds_ratio)+0.5*(ds_ratio*ds_ratio*ds_ratio);
71  else
72  return 0;
73 }

SHOGUN Machine Learning Toolbox - Documentation