[mlpack] 35/149: Add test for Pelleg-Moore k-means clustering.

Barak A. Pearlmutter barak+git at pearlmutter.net
Sat May 2 09:11:06 UTC 2015


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit 5516e6557e191725e5329ccc2db7519dd4bfd5eb
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Sun Oct 12 20:30:25 2014 +0000

    Add test for Pelleg-Moore k-means clustering.
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@17243 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/tests/kmeans_test.cpp | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/src/mlpack/tests/kmeans_test.cpp b/src/mlpack/tests/kmeans_test.cpp
index ddf5a22..178bdb5 100644
--- a/src/mlpack/tests/kmeans_test.cpp
+++ b/src/mlpack/tests/kmeans_test.cpp
@@ -9,6 +9,7 @@
 #include <mlpack/methods/kmeans/refined_start.hpp>
 #include <mlpack/methods/kmeans/elkan_kmeans.hpp>
 #include <mlpack/methods/kmeans/hamerly_kmeans.hpp>
+#include <mlpack/methods/kmeans/pelleg_moore_kmeans.hpp>
 
 #include <boost/test/unit_test.hpp>
 #include "old_boost_test_definitions.hpp"
@@ -555,4 +556,38 @@ BOOST_AUTO_TEST_CASE(HamerlyTest)
   }
 }
 
+BOOST_AUTO_TEST_CASE(PellegMooreTest)
+{
+  const size_t trials = 5;
+
+  for (size_t t = 0; t < trials; ++t)
+  {
+    arma::mat dataset(10, 1000);
+    dataset.randu();
+
+    const size_t k = 5 * (t + 1);
+    arma::mat centroids(10, k);
+    centroids.randu();
+
+    // Make sure the Pelleg-Moore algorithm and the naive method return the same
+    // clusters.
+    arma::mat naiveCentroids(centroids);
+    KMeans<> km;
+    arma::Col<size_t> assignments;
+    km.Cluster(dataset, k, assignments, naiveCentroids, false, true);
+
+    KMeans<metric::EuclideanDistance, RandomPartition, MaxVarianceNewCluster,
+        PellegMooreKMeans> pellegMoore;
+    arma::Col<size_t> pmAssignments;
+    arma::mat pmCentroids(centroids);
+    pellegMoore.Cluster(dataset, k, pmAssignments, pmCentroids, false, true);
+
+    for (size_t i = 0; i < dataset.n_cols; ++i)
+      BOOST_REQUIRE_EQUAL(assignments[i], pmAssignments[i]);
+
+    for (size_t i = 0; i < centroids.n_elem; ++i)
+      BOOST_REQUIRE_CLOSE(naiveCentroids[i], pmCentroids[i], 1e-5);
+  }
+}
+
 BOOST_AUTO_TEST_SUITE_END();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list