[mlpack-git] master: Add test case (51a0896)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Wed Apr 29 14:43:03 EDT 2015


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

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/ee384655c4462e422e343e9725437fd772ca4449...182d4a629c1b23f683dff7b284844e4e3e9f5cc4

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

commit 51a089601192ef1dd6c0c6e0b5289e25dfda38ca
Author: HurricaneTong <HurricaneTong at HurricaneTong.local>
Date:   Thu Jan 22 13:54:19 2015 +0800

    Add test case


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

51a089601192ef1dd6c0c6e0b5289e25dfda38ca
 src/mlpack/tests/CMakeLists.txt      |  1 +
 src/mlpack/tests/mean_shift_test.cpp | 88 ++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)

diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt
index 0caa3bb..e569506 100644
--- a/src/mlpack/tests/CMakeLists.txt
+++ b/src/mlpack/tests/CMakeLists.txt
@@ -21,6 +21,7 @@ add_executable(mlpack_test
   kernel_pca_test.cpp
   kernel_traits_test.cpp
   kmeans_test.cpp
+  mean_shift_test.cpp
   lars_test.cpp
   lbfgs_test.cpp
   lin_alg_test.cpp
diff --git a/src/mlpack/tests/mean_shift_test.cpp b/src/mlpack/tests/mean_shift_test.cpp
new file mode 100644
index 0000000..f5c071a
--- /dev/null
+++ b/src/mlpack/tests/mean_shift_test.cpp
@@ -0,0 +1,88 @@
+/**
+ * @file mean_shift_test.cpp
+ * @author Shangtong Zhang
+ */
+
+#include <mlpack/core.hpp>
+
+#include <mlpack/methods/mean_shift/mean_shift.hpp>
+
+#include <boost/test/unit_test.hpp>
+#include "old_boost_test_definitions.hpp"
+
+using namespace mlpack;
+using namespace mlpack::meanshift;
+
+BOOST_AUTO_TEST_SUITE(MeanShiftTest);
+
+// Generate dataset; written transposed because it's easier to read.
+arma::mat meanShiftData("  0.0   0.0;" // Class 1.
+                     "  0.3   0.4;"
+                     "  0.1   0.0;"
+                     "  0.1   0.3;"
+                     " -0.2  -0.2;"
+                     " -0.1   0.3;"
+                     " -0.4   0.1;"
+                     "  0.2  -0.1;"
+                     "  0.3   0.0;"
+                     " -0.3  -0.3;"
+                     "  0.1  -0.1;"
+                     "  0.2  -0.3;"
+                     " -0.3   0.2;"
+                     " 10.0  10.0;" // Class 2.
+                     " 10.1   9.9;"
+                     "  9.9  10.0;"
+                     " 10.2   9.7;"
+                     " 10.2   9.8;"
+                     "  9.7  10.3;"
+                     "  9.9  10.1;"
+                     "-10.0   5.0;" // Class 3.
+                     " -9.8   5.1;"
+                     " -9.9   4.9;"
+                     "-10.0   4.9;"
+                     "-10.2   5.2;"
+                     "-10.1   5.1;"
+                     "-10.3   5.3;"
+                     "-10.0   4.8;"
+                     " -9.6   5.0;"
+                     " -9.8   5.1;");
+
+
+/**
+ * 30-point 3-class test case for Mean Shift.
+ */
+BOOST_AUTO_TEST_CASE(MeanShiftSimpleTest) {
+ 
+  MeanShift<> meanShift;
+  
+  arma::Col<size_t> assignments;
+  arma::mat centroids;
+  meanShift.Cluster((arma::mat) trans(meanShiftData), assignments, centroids);
+  
+  // Now make sure we got it all right.  There is no restriction on how the
+  // clusters are ordered, so we have to be careful about that.
+  size_t firstClass = assignments(0);
+  
+  for (size_t i = 1; i < 13; i++)
+    BOOST_REQUIRE_EQUAL(assignments(i), firstClass);
+  
+  size_t secondClass = assignments(13);
+  
+  // To ensure that class 1 != class 2.
+  BOOST_REQUIRE_NE(firstClass, secondClass);
+  
+  for (size_t i = 13; i < 20; i++)
+    BOOST_REQUIRE_EQUAL(assignments(i), secondClass);
+  
+  size_t thirdClass = assignments(20);
+  
+  // To ensure that this is the third class which we haven't seen yet.
+  BOOST_REQUIRE_NE(firstClass, thirdClass);
+  BOOST_REQUIRE_NE(secondClass, thirdClass);
+  
+  for (size_t i = 20; i < 30; i++)
+    BOOST_REQUIRE_EQUAL(assignments(i), thirdClass);
+  
+}
+
+BOOST_AUTO_TEST_SUITE_END();
\ No newline at end of file



More information about the mlpack-git mailing list