SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CircularKernel.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) 2011 Abhinav Maurya
8  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9  * Copyright (C) 2011 Indian Institute of Technology Bombay
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 
29  set_sigma(sig);
30  init();
31 }
32 
34  CFeatures *l, CFeatures *r, float64_t sig, CDistance* dist)
35 : CKernel(10), distance(dist)
36 {
39  set_sigma(sig);
40  init();
41  init(l, r);
42 }
43 
45 {
46  cleanup();
48 }
49 
50 bool CCircularKernel::init(CFeatures* l, CFeatures* r)
51 {
53  CKernel::init(l,r);
54  distance->init(l,r);
55  return init_normalizer();
56 }
57 
59 {
61 }
62 
63 void CCircularKernel::init()
64 {
65  SG_ADD((CSGObject**) &distance, "distance", "Distance to be used.",
66  MS_AVAILABLE);
67  SG_ADD(&sigma, "sigma", "Sigma kernel parameter.", MS_AVAILABLE);
68 }
69 
70 float64_t CCircularKernel::compute(int32_t idx_a, int32_t idx_b)
71 {
72  float64_t dist=distance->distance(idx_a, idx_b);
73  float64_t ds_ratio=dist/sigma;
74 
75  if (dist < sigma)
76  return (2/M_PI)*acos(-ds_ratio) - (2/M_PI)*ds_ratio*sqrt(1-ds_ratio*ds_ratio);
77  else
78  return 0;
79 }

SHOGUN Machine Learning Toolbox - Documentation