[mlpack-git] master: Fix centroid calculation for cover tree. (fc38043)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Wed May 20 23:06:10 EDT 2015


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

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/77d750c8fd46140b1d6060424f68768a21c89377...7e9cd46afb53817ae93ccbd02637d7726137ce4d

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

commit fc380437e1ea8dc25e8548c0a1cffa0fa84c1356
Author: Ryan Curtin <ryan at ratml.org>
Date:   Thu May 14 18:08:30 2015 -0400

    Fix centroid calculation for cover tree.


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

fc380437e1ea8dc25e8548c0a1cffa0fa84c1356
 src/mlpack/methods/kmeans/dual_tree_kmeans_statistic.hpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/mlpack/methods/kmeans/dual_tree_kmeans_statistic.hpp b/src/mlpack/methods/kmeans/dual_tree_kmeans_statistic.hpp
index 09a14a0..8209860 100644
--- a/src/mlpack/methods/kmeans/dual_tree_kmeans_statistic.hpp
+++ b/src/mlpack/methods/kmeans/dual_tree_kmeans_statistic.hpp
@@ -46,7 +46,14 @@ class DualTreeKMeansStatistic : public
     // Empirically calculate the centroid.
     centroid.zeros(node.Dataset().n_rows);
     for (size_t i = 0; i < node.NumPoints(); ++i)
+    {
+      // Correct handling of cover tree: don't double-count the point which
+      // appears in the children.
+      if (tree::TreeTraits<TreeType>::HasSelfChildren && i == 0 &&
+          node.NumChildren() > 0)
+        continue;
       centroid += node.Dataset().col(node.Point(i));
+    }
 
     for (size_t i = 0; i < node.NumChildren(); ++i)
       centroid += node.Child(i).NumDescendants() *



More information about the mlpack-git mailing list