[mlpack] 248/324: Fix changed API.

Barak A. Pearlmutter barak+git at cs.nuim.ie
Sun Aug 17 08:22:15 UTC 2014


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

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

commit 73d1efc640aa15aea8b1359a4d06b48ab31d48bc
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Wed Jul 30 16:58:23 2014 +0000

    Fix changed API.
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16927 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/tests/kmeans_test.cpp | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/mlpack/tests/kmeans_test.cpp b/src/mlpack/tests/kmeans_test.cpp
index a79630a..0853a0d 100644
--- a/src/mlpack/tests/kmeans_test.cpp
+++ b/src/mlpack/tests/kmeans_test.cpp
@@ -137,8 +137,9 @@ BOOST_AUTO_TEST_CASE(AllowEmptyClusterTest)
   arma::Col<size_t> countsOld = counts;
 
   // Make sure the method doesn't modify any points.
+  metric::LMetric<2, true> metric;
   BOOST_REQUIRE_EQUAL(AllowEmptyClusters::EmptyCluster(kMeansData, 2, centroids,
-      counts, assignments), 0);
+      counts, metric), 0);
 
   // Make sure no assignments were changed.
   for (size_t i = 0; i < assignments.n_elem; i++)
@@ -164,16 +165,39 @@ BOOST_AUTO_TEST_CASE(MaxVarianceNewClusterTest)
   arma::mat centroids(2, 3);
   centroids.col(0) = (1.0 / 3.0) * (data.col(0) + data.col(1) + data.col(2));
   centroids.col(1) = 0.5 * (data.col(3) + data.col(4));
-  centroids(0, 2) = 0;
-  centroids(1, 2) = 0;
+  centroids(0, 2) = DBL_MAX;
+  centroids(1, 2) = DBL_MAX;
 
   arma::Col<size_t> counts("3 2 0");
 
+  metric::LMetric<2, true> metric;
+
   // This should only change one point.
   BOOST_REQUIRE_EQUAL(MaxVarianceNewCluster::EmptyCluster(data, 2, centroids,
-      counts, assignments), 1);
+      counts, metric), 1);
+
+  // Add the variance of each point's distance away from the cluster.  I think
+  // this is the sensible thing to do.
+  for (size_t i = 0; i < data.n_cols; ++i)
+  {
+    // Find the closest centroid to this point.
+    double minDistance = std::numeric_limits<double>::infinity();
+    size_t closestCluster = centroids.n_cols; // Invalid value.
+
+    for (size_t j = 0; j < centroids.n_cols; j++)
+    {
+      const double distance = metric.Evaluate(data.col(i), centroids.col(j));
+
+      if (distance < minDistance)
+      {
+        minDistance = distance;
+        closestCluster = j;
+      }
+    }
+
+    assignments[i] = closestCluster;
+  }
 
-  // Ensure that the cluster assignments are right.
   BOOST_REQUIRE_EQUAL(assignments[0], 0);
   BOOST_REQUIRE_EQUAL(assignments[1], 0);
   BOOST_REQUIRE_EQUAL(assignments[2], 2);

-- 
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