[mlpack-git] master: Force re-Precalculate() when we run out of points in one cluster. (ec8a151)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Mon Nov 23 08:26:04 EST 2015


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

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/1bb8434eec26338121f6bcfbbf7c83daff35a570...ec8a15165b12c246df58cb5e66afe1c6d865ce07

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

commit ec8a15165b12c246df58cb5e66afe1c6d865ce07
Author: Ryan Curtin <ryan at ratml.org>
Date:   Mon Nov 23 08:25:39 2015 -0500

    Force re-Precalculate() when we run out of points in one cluster.
    
    See #481.


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

ec8a15165b12c246df58cb5e66afe1c6d865ce07
 src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp b/src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp
index fe82e5f..6ea9d0c 100644
--- a/src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp
+++ b/src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp
@@ -64,12 +64,21 @@ size_t MaxVarianceNewCluster::EmptyCluster(const MatType& data,
 
   // Modify the variances, as necessary.
   variances[emptyCluster] = 0;
-  // One has already been subtracted from clusterCounts[maxVarCluster].
+  // One has already been subtracted from clusterCounts[maxVarCluster].  If
+  // EmptyCluster() is called again, we can't pull another point from
+  // maxVarCluster (we'd be making an empty cluster), so force a call to
+  // Precalculate() if EmptyCluster() is called again by changing
+  // this->iteration.
   if (clusterCounts[maxVarCluster] <= 1)
+  {
     variances[maxVarCluster] = 0;
+    --this->iteration;
+  }
   else
+  {
     variances[maxVarCluster] = (1.0 / clusterCounts[maxVarCluster]) *
       ((clusterCounts[maxVarCluster] + 1) * variances[maxVarCluster] - maxDistance);
+  }
 
   // Output some debugging information.
   Log::Debug << "Point " << furthestPoint << " assigned to empty cluster " <<



More information about the mlpack-git mailing list