[mlpack-svn] r17243 - mlpack/trunk/src/mlpack/tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Sun Oct 12 16:30:25 EDT 2014
Author: rcurtin
Date: Sun Oct 12 16:30:25 2014
New Revision: 17243
Log:
Add test for Pelleg-Moore k-means clustering.
Modified:
mlpack/trunk/src/mlpack/tests/kmeans_test.cpp
Modified: mlpack/trunk/src/mlpack/tests/kmeans_test.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/tests/kmeans_test.cpp (original)
+++ mlpack/trunk/src/mlpack/tests/kmeans_test.cpp Sun Oct 12 16:30:25 2014
@@ -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(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();
More information about the mlpack-svn
mailing list