laplacian_kernel.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_KERNELS_LAPLACIAN_KERNEL_HPP
13 #define MLPACK_CORE_KERNELS_LAPLACIAN_KERNEL_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace kernel {
19 
31 {
32  public:
36  LaplacianKernel() : bandwidth(1.0)
37  { }
38 
44  LaplacianKernel(double bandwidth) :
45  bandwidth(bandwidth)
46  { }
47 
60  template<typename VecTypeA, typename VecTypeB>
61  double Evaluate(const VecTypeA& a, const VecTypeB& b) const
62  {
63  // The precalculation of gamma saves us a little computation time.
64  return exp(-metric::EuclideanDistance::Evaluate(a, b) / bandwidth);
65  }
66 
75  double Evaluate(const double t) const
76  {
77  // The precalculation of gamma saves us a little computation time.
78  return exp(-t / bandwidth);
79  }
80 
90  double Gradient(const double t) const {
91  return exp(-t / bandwidth) / -bandwidth;
92  }
93 
95  double Bandwidth() const { return bandwidth; }
97  double& Bandwidth() { return bandwidth; }
98 
100  template<typename Archive>
101  void serialize(Archive& ar, const uint32_t /* version */)
102  {
103  ar(CEREAL_NVP(bandwidth));
104  }
105 
106  private:
108  double bandwidth;
109 };
110 
112 template<>
114 {
115  public:
117  static const bool IsNormalized = true;
119  static const bool UsesSquaredDistance = false;
120 };
121 
122 } // namespace kernel
123 } // namespace mlpack
124 
125 #endif
double Gradient(const double t) const
Evaluation of the gradient of the Laplacian kernel given the distance between two points...
This is a template class that can provide information about various kernels.
Linear algebra utility functions, generally performed on matrices or vectors.
double Bandwidth() const
Get the bandwidth.
The core includes that mlpack expects; standard C++ includes and Armadillo.
void serialize(Archive &ar, const uint32_t)
Serialize the kernel.
static VecTypeA::elem_type Evaluate(const VecTypeA &a, const VecTypeB &b)
Computes the distance between two points.
double & Bandwidth()
Modify the bandwidth.
LaplacianKernel()
Default constructor; sets bandwidth to 1.0.
LaplacianKernel(double bandwidth)
Construct the Laplacian kernel with a custom bandwidth.
double Evaluate(const double t) const
Evaluation of the Laplacian kernel given the distance between two points.
The standard Laplacian kernel.
double Evaluate(const VecTypeA &a, const VecTypeB &b) const
Evaluation of the Laplacian kernel.