MLPACK  1.0.11
triangular_kernel.hpp
Go to the documentation of this file.
1 
22 #ifndef __MLPACK_CORE_KERNELS_TRIANGULAR_KERNEL_HPP
23 #define __MLPACK_CORE_KERNELS_TRIANGULAR_KERNEL_HPP
24 
25 #include <mlpack/core.hpp>
27 
28 namespace mlpack {
29 namespace kernel {
30 
41 {
42  public:
48  TriangularKernel(const double bandwidth = 1.0) : bandwidth(bandwidth) { }
49 
56  template<typename Vec1Type, typename Vec2Type>
57  double Evaluate(const Vec1Type& a, const Vec2Type& b) const
58  {
59  return std::max(0.0, (1 - metric::EuclideanDistance::Evaluate(a, b) /
60  bandwidth));
61  }
62 
69  double Evaluate(const double distance) const
70  {
71  return std::max(0.0, (1 - distance) / bandwidth);
72  }
73 
75  double Bandwidth() const { return bandwidth; }
77  double& Bandwidth() { return bandwidth; }
78 
80  std::string ToString() const
81  {
82  std::ostringstream convert;
83  convert << "TriangularKernel [" << this << "]" << std::endl;
84  convert << " Bandwidth: " << bandwidth << std::endl;
85  return convert.str();
86  }
87 
88  private:
90  double bandwidth;
91 };
92 
94 template<>
96 {
97  public:
99  static const bool IsNormalized = true;
100 };
101 
102 }; // namespace kernel
103 }; // namespace mlpack
104 
105 #endif
This is a template class that can provide information about various kernels.
The trivially simple triangular kernel, defined by.
double Evaluate(const double distance) const
Evaluate the triangular kernel given that the distance between the two points is known.
double Evaluate(const Vec1Type &a, const Vec2Type &b) const
Evaluate the triangular kernel for the two given vectors.
std::string ToString() const
Return a string representation of the kernel.
double bandwidth
The bandwidth of the kernel.
double & Bandwidth()
Modify the bandwidth of the kernel.
TriangularKernel(const double bandwidth=1.0)
Initialize the triangular kernel with the given bandwidth (default 1.0).
static double Evaluate(const VecType1 &a, const VecType2 &b)
Computes the distance between two points.
static const bool IsNormalized
If true, then the kernel is normalized: K(x, x) = K(y, y) = 1 for all x.
double Bandwidth() const
Get the bandwidth of the kernel.