[mlpack-git] master: Refactor: remove unnecessary temporary. (b3c521f)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 12 16:03:56 EDT 2015


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

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/eddd7167d69b6c88b271ef2e51d1c20e13f1acd8...70342dd8e5c17e0c164cfb8189748671e9c0dd44

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

commit b3c521ff48f1462855807059e5e0143abc4eaf1e
Author: Ryan Curtin <ryan at ratml.org>
Date:   Tue Feb 3 17:46:38 2015 -0500

    Refactor: remove unnecessary temporary.


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

b3c521ff48f1462855807059e5e0143abc4eaf1e
 src/mlpack/methods/kmeans/dtnn_kmeans_impl.hpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/mlpack/methods/kmeans/dtnn_kmeans_impl.hpp b/src/mlpack/methods/kmeans/dtnn_kmeans_impl.hpp
index 80a25e7..9d50113 100644
--- a/src/mlpack/methods/kmeans/dtnn_kmeans_impl.hpp
+++ b/src/mlpack/methods/kmeans/dtnn_kmeans_impl.hpp
@@ -170,7 +170,7 @@ double DTNNKMeans<MetricType, MatType, TreeType>::Iterate(
 
   // Now, calculate how far the clusters moved, after normalizing them.
   double residual = 0.0;
-  double maxMovement = 0.0;
+  clusterDistances[centroids.n_cols] = 0.0;
   for (size_t c = 0; c < centroids.n_cols; ++c)
   {
     // Get the mapping to the old cluster, if necessary.
@@ -189,11 +189,10 @@ double DTNNKMeans<MetricType, MatType, TreeType>::Iterate(
       clusterDistances[old] = movement;
       residual += std::pow(movement, 2.0);
 
-      if (movement > maxMovement)
-        maxMovement = movement;
+      if (movement > clusterDistances[centroids.n_cols])
+        clusterDistances[centroids.n_cols] = movement;
     }
   }
-  clusterDistances[centroids.n_cols] = maxMovement;
   distanceCalculations += centroids.n_cols;
 
 //  lastIterationCentroids = oldCentroids;



More information about the mlpack-git mailing list