[mlpack-git] master: kmeans: small fix with inf variance (b243c2d)

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


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

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

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

commit b243c2d2b7dba062103da18657c9142eb9c2f675
Author: Nikita Araslanov <araslanov at uni-bonn.de>
Date:   Sun Nov 22 16:37:38 2015 +0100

    kmeans: small fix with inf variance


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

b243c2d2b7dba062103da18657c9142eb9c2f675
 src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp | 5 ++++-
 1 file changed, 4 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 b6090ae..fe82e5f 100644
--- a/src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp
+++ b/src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp
@@ -65,7 +65,10 @@ size_t MaxVarianceNewCluster::EmptyCluster(const MatType& data,
   // Modify the variances, as necessary.
   variances[emptyCluster] = 0;
   // One has already been subtracted from clusterCounts[maxVarCluster].
-  variances[maxVarCluster] = (1.0 / (clusterCounts[maxVarCluster])) *
+  if (clusterCounts[maxVarCluster] <= 1)
+    variances[maxVarCluster] = 0;
+  else
+    variances[maxVarCluster] = (1.0 / clusterCounts[maxVarCluster]) *
       ((clusterCounts[maxVarCluster] + 1) * variances[maxVarCluster] - maxDistance);
 
   // Output some debugging information.



More information about the mlpack-git mailing list