00001 00022 #ifndef __MLPACK_CORE_KERNELS_TRIANGULAR_KERNEL_HPP 00023 #define __MLPACK_CORE_KERNELS_TRIANGULAR_KERNEL_HPP 00024 00025 #include <mlpack/core.hpp> 00026 #include <mlpack/core/metrics/lmetric.hpp> 00027 00028 namespace mlpack { 00029 namespace kernel { 00030 00040 class TriangularKernel 00041 { 00042 public: 00048 TriangularKernel(const double bandwidth = 1.0) : bandwidth(bandwidth) { } 00049 00056 template<typename Vec1Type, typename Vec2Type> 00057 double Evaluate(const Vec1Type& a, const Vec2Type& b) const 00058 { 00059 return std::max(0.0, (1 - metric::EuclideanDistance::Evaluate(a, b) / 00060 bandwidth)); 00061 } 00062 00069 double Evaluate(const double distance) const 00070 { 00071 return std::max(0.0, (1 - distance) / bandwidth); 00072 } 00073 00075 double Bandwidth() const { return bandwidth; } 00077 double& Bandwidth() { return bandwidth; } 00078 00079 private: 00081 double bandwidth; 00082 }; 00083 00085 template<> 00086 class KernelTraits<TriangularKernel> 00087 { 00088 public: 00090 static const bool IsNormalized = true; 00091 }; 00092 00093 }; // namespace kernel 00094 }; // namespace mlpack 00095 00096 #endif