[mlpack-svn] r16927 - mlpack/trunk/src/mlpack/tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Jul 30 12:58:23 EDT 2014
Author: rcurtin
Date: Wed Jul 30 12:58:23 2014
New Revision: 16927
Log:
Fix changed API.
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 Wed Jul 30 12:58:23 2014
@@ -137,8 +137,9 @@
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 @@
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);
More information about the mlpack-svn
mailing list