MLPACK
1.0.4
|
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 // The precalculation of gamma saves us a little computation time. 00077 return exp(gamma * metric::SquaredEuclideanDistance::Evaluate(a, b)); 00078 } 00079 00087 double Evaluate(double t) const 00088 { 00089 // The precalculation of gamma saves us a little computation time. 00090 return exp(gamma * t * t); 00091 } 00098 double Normalizer(size_t dimension) 00099 { 00100 return pow(sqrt(2.0 * M_PI) * bandwidth, (double) dimension); 00101 } 00109 template<typename VecType> 00110 double ConvolutionIntegral(const VecType& a, const VecType& b) 00111 { 00112 return Evaluate(sqrt(metric::SquaredEuclideanDistance::Evaluate(a, b) / 2.0)) / 00113 (Normalizer(a.n_rows) * pow(2.0, (double) a.n_rows / 2.0)); 00114 } 00115 00116 00118 double Bandwidth() const { return bandwidth; } 00119 00122 void Bandwidth(const double bandwidth) 00123 { 00124 this->bandwidth = bandwidth; 00125 this->gamma = -0.5 * pow(bandwidth, -2.0); 00126 } 00127 00129 double Gamma() const { return gamma; } 00130 00131 private: 00133 double bandwidth; 00134 00137 double gamma; 00138 }; 00139 00140 }; // namespace kernel 00141 }; // namespace mlpack 00142 00143 #endif