[mlpack-svn] r15932 - mlpack/trunk/src/mlpack/core/kernels
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Oct 4 12:31:04 EDT 2013
Author: rcurtin
Date: Fri Oct 4 12:31:04 2013
New Revision: 15932
Log:
Minor updates for normalized kernels.
Modified:
mlpack/trunk/src/mlpack/core/kernels/epanechnikov_kernel.cpp
mlpack/trunk/src/mlpack/core/kernels/epanechnikov_kernel.hpp
mlpack/trunk/src/mlpack/core/kernels/epanechnikov_kernel_impl.hpp
mlpack/trunk/src/mlpack/core/kernels/gaussian_kernel.hpp
mlpack/trunk/src/mlpack/core/kernels/laplacian_kernel.hpp
mlpack/trunk/src/mlpack/core/kernels/triangular_kernel.hpp
Modified: mlpack/trunk/src/mlpack/core/kernels/epanechnikov_kernel.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/kernels/epanechnikov_kernel.cpp (original)
+++ mlpack/trunk/src/mlpack/core/kernels/epanechnikov_kernel.cpp Fri Oct 4 12:31:04 2013
@@ -26,8 +26,7 @@
/**
* Evaluate the kernel not for two points but for a numerical value.
*/
-double EpanechnikovKernel::Evaluate(const double t)
+double EpanechnikovKernel::Evaluate(const double distance) const
{
- double evaluatee = 1.0 - t * t * inverseBandwidthSquared;
- return (evaluatee > 0.0) ? evaluatee : 0.0;
+ return std::max(0.0, 1 - std::pow(distance, 2.0) * inverseBandwidthSquared);
}
Modified: mlpack/trunk/src/mlpack/core/kernels/epanechnikov_kernel.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/kernels/epanechnikov_kernel.hpp (original)
+++ mlpack/trunk/src/mlpack/core/kernels/epanechnikov_kernel.hpp Fri Oct 4 12:31:04 2013
@@ -41,7 +41,13 @@
* @param b The other input vector.
*/
template<typename Vec1Type, typename Vec2Type>
- double Evaluate(const Vec1Type& a, const Vec2Type& b);
+ double Evaluate(const Vec1Type& a, const Vec2Type& b) const;
+
+ /**
+ * Evaluate the Epanechnikov kernel given that the distance between the two
+ * input points is known.
+ */
+ double Evaluate(const double distance) const;
/**
* Obtains the convolution integral [integral of K(||x-a||) K(||b-x||) dx]
@@ -62,11 +68,6 @@
*/
double Normalizer(const size_t dimension);
- /**
- * Evaluate the kernel not for two points but for a numerical value.
- */
- double Evaluate(const double t);
-
private:
//! Bandwidth of the kernel.
double bandwidth;
Modified: mlpack/trunk/src/mlpack/core/kernels/epanechnikov_kernel_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/kernels/epanechnikov_kernel_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/core/kernels/epanechnikov_kernel_impl.hpp Fri Oct 4 12:31:04 2013
@@ -17,6 +17,7 @@
template<typename Vec1Type, typename Vec2Type>
inline double EpanechnikovKernel::Evaluate(const Vec1Type& a, const Vec2Type& b)
+ const
{
return std::max(0.0, 1.0 - metric::SquaredEuclideanDistance::Evaluate(a, b)
* inverseBandwidthSquared);
Modified: mlpack/trunk/src/mlpack/core/kernels/gaussian_kernel.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/kernels/gaussian_kernel.hpp (original)
+++ mlpack/trunk/src/mlpack/core/kernels/gaussian_kernel.hpp Fri Oct 4 12:31:04 2013
@@ -63,17 +63,18 @@
}
/**
- * Evaluation of the Gaussian kernel using a double precision argument.
+ * Evaluation of the Gaussian kernel given the distance between two points.
*
- * @param t double value.
+ * @param t The distance between the two points the kernel is evaluated on.
* @return K(t) using the bandwidth (@f$\mu at f$) specified in the
* constructor.
*/
double Evaluate(double t) const
{
// The precalculation of gamma saves us a little computation time.
- return exp(gamma * t * t);
+ return exp(gamma * std::pow(t, 2.0));
}
+
/**
* Obtain the normalization constant of the Gaussian kernel.
*
@@ -84,6 +85,7 @@
{
return pow(sqrt(2.0 * M_PI) * bandwidth, (double) dimension);
}
+
/**
* Obtain a convolution integral of the Gaussian kernel.
*
Modified: mlpack/trunk/src/mlpack/core/kernels/laplacian_kernel.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/kernels/laplacian_kernel.hpp (original)
+++ mlpack/trunk/src/mlpack/core/kernels/laplacian_kernel.hpp Fri Oct 4 12:31:04 2013
@@ -59,13 +59,14 @@
}
/**
- * Evaluation of the Laplacian kernel using a double precision argument.
+ * Evaluation of the Laplacian kernel given the distance between two points.
*
- * @param t double value.
+ * @param t The distance between the two points the kernel should be evaluated
+ * on.
* @return K(t) using the bandwidth (@f$\mu at f$) specified in the
* constructor.
*/
- double Evaluate(double t) const
+ double Evaluate(const double t) const
{
// The precalculation of gamma saves us a little computation time.
return exp(-t / bandwidth);
Modified: mlpack/trunk/src/mlpack/core/kernels/triangular_kernel.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/kernels/triangular_kernel.hpp (original)
+++ mlpack/trunk/src/mlpack/core/kernels/triangular_kernel.hpp Fri Oct 4 12:31:04 2013
@@ -39,12 +39,23 @@
* @param b Second vector.
*/
template<typename Vec1Type, typename Vec2Type>
- double Evaluate(const Vec1Type& a, const Vec2Type& b)
+ double Evaluate(const Vec1Type& a, const Vec2Type& b) const
{
return std::max(0.0, (1 - metric::EuclideanDistance::Evaluate(a, b) /
bandwidth));
}
+ /**
+ * Evaluate the triangular kernel given that the distance between the two
+ * points is known.
+ *
+ * @param distance The distance between the two points.
+ */
+ double Evaluate(const double distance) const
+ {
+ return std::max(0.0, (1 - distance) / bandwidth);
+ }
+
//! Get the bandwidth of the kernel.
double Bandwidth() const { return bandwidth; }
//! Modify the bandwidth of the kernel.
More information about the mlpack-svn
mailing list