gaussian_kernel.hpp
Go to the documentation of this file.00001
00024 #ifndef __MLPACK_CORE_KERNELS_GAUSSIAN_KERNEL_HPP
00025 #define __MLPACK_CORE_KERNELS_GAUSSIAN_KERNEL_HPP
00026
00027 #include <mlpack/core.hpp>
00028 #include <mlpack/core/metrics/lmetric.hpp>
00029
00030 namespace mlpack {
00031 namespace kernel {
00032
00043 class GaussianKernel
00044 {
00045 public:
00049 GaussianKernel() : bandwidth(1.0), gamma(-0.5)
00050 { }
00051
00057 GaussianKernel(double bandwidth) :
00058 bandwidth(bandwidth),
00059 gamma(-0.5 * pow(bandwidth, -2.0))
00060 { }
00061
00073 template<typename VecType>
00074 double Evaluate(const VecType& a, const VecType& b) const
00075 {
00076
00077 return exp(gamma * metric::SquaredEuclideanDistance::Evaluate(a, b));
00078 }
00079
00087 double Evaluate(double t) const
00088 {
00089
00090 return exp(gamma * std::pow(t, 2.0));
00091 }
00092
00099 double Normalizer(size_t dimension)
00100 {
00101 return pow(sqrt(2.0 * M_PI) * bandwidth, (double) dimension);
00102 }
00103
00111 template<typename VecType>
00112 double ConvolutionIntegral(const VecType& a, const VecType& b)
00113 {
00114 return Evaluate(sqrt(metric::SquaredEuclideanDistance::Evaluate(a, b) / 2.0)) /
00115 (Normalizer(a.n_rows) * pow(2.0, (double) a.n_rows / 2.0));
00116 }
00117
00118
00120 double Bandwidth() const { return bandwidth; }
00121
00124 void Bandwidth(const double bandwidth)
00125 {
00126 this->bandwidth = bandwidth;
00127 this->gamma = -0.5 * pow(bandwidth, -2.0);
00128 }
00129
00131 double Gamma() const { return gamma; }
00132
00133 private:
00135 double bandwidth;
00136
00139 double gamma;
00140 };
00141
00143 template<>
00144 class KernelTraits<GaussianKernel>
00145 {
00146 public:
00148 static const bool IsNormalized = true;
00149 };
00150
00151 };
00152 };
00153
00154 #endif