[mlpack-git] master: remove unnecessary kernel traits (1df8dc0)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Wed Apr 29 14:43:34 EDT 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/ee384655c4462e422e343e9725437fd772ca4449...182d4a629c1b23f683dff7b284844e4e3e9f5cc4

>---------------------------------------------------------------

commit 1df8dc04c15c60d24622cf722e5db9d1226a3f84
Author: HurricaneTong <HurricaneTong at HurricaneTong.local>
Date:   Thu Feb 26 15:17:38 2015 +0800

    remove unnecessary kernel traits
    
    UsesSquaredDistance is unnecessary as smart complier can do the same
    optimization.


>---------------------------------------------------------------

1df8dc04c15c60d24622cf722e5db9d1226a3f84
 src/mlpack/methods/mean_shift/mean_shift_impl.hpp | 29 ++---------------------
 1 file changed, 2 insertions(+), 27 deletions(-)

diff --git a/src/mlpack/methods/mean_shift/mean_shift_impl.hpp b/src/mlpack/methods/mean_shift/mean_shift_impl.hpp
index c0ef683..acc580d 100644
--- a/src/mlpack/methods/mean_shift/mean_shift_impl.hpp
+++ b/src/mlpack/methods/mean_shift/mean_shift_impl.hpp
@@ -41,7 +41,6 @@ void MeanShift<
   MatType>::
 Radius(double radius) {
   this->radius = radius;
-  squaredRadius = radius * radius;
 }
 
 // Estimate radius based on given dataset.
@@ -80,9 +79,7 @@ EstimateRadius(const MatType &data) {
 // General way to calculate the weight of a data point.
 template <typename KernelType,
           typename MatType>
-template <typename Kernel>
-typename std::enable_if<!kernel::KernelTraits<Kernel>::
-  UsesSquaredDistance, bool>::type
+bool
 MeanShift<
   KernelType,
   MatType>::
@@ -99,28 +96,6 @@ CalcWeight(const arma::colvec& centroid, const arma::colvec& point,
 
 }
 
-// Faster way to calculate the weight of a data point.
-template <typename KernelType,
-          typename MatType>
-template <typename Kernel>
-typename std::enable_if<kernel::KernelTraits<Kernel>::
-  UsesSquaredDistance, bool>::type
-MeanShift<
-  KernelType,
-  MatType>::
-CalcWeight(const arma::colvec& centroid, const arma::colvec& point,
-           double& weight) {
-
-  double squaredDist = metric::SquaredEuclideanDistance::
-                       Evaluate(centroid, point);
-  if (squaredDist >= squaredRadius || squaredDist == 0) {
-    return false;
-  }
-  squaredDist /= squaredRadius;
-  weight = kernel.GradientForSquaredDistance(squaredDist);
-  return true;
-}
-
 /**
  * Perform Mean Shift clustering on the data, returning a list of cluster
  * assignments and centroids.
@@ -161,7 +136,7 @@ Cluster(const MatType& data,
       for (size_t j = 0; j < data.n_cols; ++j) {
 
         double weight = 0;
-        if (CalcWeight<KernelType>(allCentroids.col(i), data.col(j), weight)) {
+        if (CalcWeight(allCentroids.col(i), data.col(j), weight)) {
           sumWeight += weight;
           newCentroid += weight * data.col(j);
         }



More information about the mlpack-git mailing list