MLPACK  1.0.7
spherical_kernel.hpp
Go to the documentation of this file.
1 
23 #ifndef __MLPACK_CORE_KERNELS_SPHERICAL_KERNEL_H
24 #define __MLPACK_CORE_KERNELS_SPHERICAL_KERNEL_H
25 
26 #include <boost/math/special_functions/gamma.hpp>
27 #include <mlpack/core.hpp>
28 
29 namespace mlpack {
30 namespace kernel {
31 
33 {
34  public:
36  bandwidth(1.0),
37  bandwidthSquared(1.0) {}
38  SphericalKernel(double b) :
39  bandwidth(b),
40  bandwidthSquared(b*b) {}
41 
42  template<typename VecType>
43  double Evaluate(const VecType& a, const VecType& b)
44  {
45  return
47  1.0 : 0.0;
48  }
61  template<typename VecType>
62  double ConvolutionIntegral(const VecType& a, const VecType& b)
63  {
64  double distance = sqrt(metric::SquaredEuclideanDistance::Evaluate(a, b));
65  if (distance >= 2.0 * bandwidth)
66  {
67  return 0.0;
68  }
69  double volumeSquared = pow(Normalizer(a.n_rows), 2.0);
70 
71  switch(a.n_rows)
72  {
73  case 1:
74  return 1.0 / volumeSquared * (2.0 * bandwidth - distance);
75  break;
76  case 2:
77  return 1.0 / volumeSquared *
78  (2.0 * bandwidth * bandwidth * acos(distance/(2.0 * bandwidth)) -
79  distance / 4.0 * sqrt(4.0*bandwidth*bandwidth-distance*distance));
80  break;
81  default:
82  Log::Fatal << "The spherical kernel does not support convolution\
83  integrals above dimension two, yet..." << std::endl;
84  return -1.0;
85  break;
86  }
87  }
88  double Normalizer(size_t dimension)
89  {
90  return pow(bandwidth, (double) dimension) * pow(M_PI, dimension / 2.0) /
91  boost::math::tgamma(dimension / 2.0 + 1.0);
92  }
93  double Evaluate(double t)
94  {
95  return (t <= bandwidth) ? 1.0 : 0.0;
96  }
97 
98  private:
99  double bandwidth;
101 };
102 
104 template<>
106 {
107  public:
109  static const bool IsNormalized = true;
110 };
111 
112 }; // namespace kernel
113 }; // namespace mlpack
114 
115 #endif