[mlpack-svn] r14976 - mlpack/trunk/src/mlpack/tests

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Apr 29 15:37:55 EDT 2013


Author: rcurtin
Date: 2013-04-29 15:37:55 -0400 (Mon, 29 Apr 2013)
New Revision: 14976

Modified:
   mlpack/trunk/src/mlpack/tests/fastmks_test.cpp
Log:
Don't use global distanceEvaluations anymore.  Remove debugging output.


Modified: mlpack/trunk/src/mlpack/tests/fastmks_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/fastmks_test.cpp	2013-04-29 19:37:37 UTC (rev 14975)
+++ mlpack/trunk/src/mlpack/tests/fastmks_test.cpp	2013-04-29 19:37:55 UTC (rev 14976)
@@ -4,12 +4,10 @@
  *
  * Ensure that fast max-kernel search is correct.
  */
-#include <stddef.h>
-size_t distanceEvaluations;
-
 #include <mlpack/core.hpp>
 #include <mlpack/methods/fastmks/fastmks.hpp>
 #include <mlpack/core/kernels/linear_kernel.hpp>
+#include <mlpack/core/kernels/polynomial_kernel.hpp>
 
 #include <boost/test/unit_test.hpp>
 #include "old_boost_test_definitions.hpp"
@@ -26,11 +24,8 @@
  */
 BOOST_AUTO_TEST_CASE(SingleTreeVsNaive)
 {
-  distanceEvaluations = 0;
-
   // First create a random dataset.
   arma::mat data;
-  srand(time(NULL));
   data.randn(5, 1000);
   LinearKernel lk;
 
@@ -59,4 +54,71 @@
   }
 }
 
+/**
+ * Compare dual-tree and naive.
+ */
+BOOST_AUTO_TEST_CASE(DualTreeVsNaive)
+{
+  // First create a random dataset.
+  arma::mat data;
+  data.randn(10, 5000);
+  LinearKernel lk;
+
+  // Now run FastMKS naively.
+  FastMKS<LinearKernel> naive(data, lk, false, true);
+
+  arma::Mat<size_t> naiveIndices;
+  arma::mat naiveProducts;
+  naive.Search(10, naiveIndices, naiveProducts);
+
+  // Now run it in dual-tree mode.
+  FastMKS<LinearKernel> tree(data, lk);
+
+  arma::Mat<size_t> treeIndices;
+  arma::mat treeProducts;
+  tree.Search(10, treeIndices, treeProducts);
+
+  for (size_t q = 0; q < treeIndices.n_cols; ++q)
+  {
+    for (size_t r = 0; r < treeIndices.n_rows; ++r)
+    {
+      BOOST_REQUIRE_EQUAL(treeIndices(r, q), naiveIndices(r, q));
+      BOOST_REQUIRE_CLOSE(treeProducts(r, q), naiveProducts(r, q), 1e-5);
+    }
+  }
+}
+
+/**
+ * Compare dual-tree and single-tree on a larger dataset.
+ */
+BOOST_AUTO_TEST_CASE(DualTreeVsSingleTree)
+{
+  // First create a random dataset.
+  arma::mat data;
+  data.randu(20, 15000);
+  PolynomialKernel pk(5.0, 2.5);
+
+  FastMKS<PolynomialKernel> single(data, pk, true);
+
+  arma::Mat<size_t> singleIndices;
+  arma::mat singleProducts;
+  single.Search(10, singleIndices, singleProducts);
+
+  // Now run it in dual-tree mode.
+  FastMKS<PolynomialKernel> tree(data, pk);
+
+  arma::Mat<size_t> treeIndices;
+  arma::mat treeProducts;
+  tree.Search(10, treeIndices, treeProducts);
+
+  for (size_t q = 0; q < treeIndices.n_cols; ++q)
+  {
+    for (size_t r = 0; r < treeIndices.n_rows; ++r)
+    {
+      BOOST_REQUIRE_EQUAL(treeIndices(r, q), singleIndices(r, q));
+      BOOST_REQUIRE_CLOSE(treeProducts(r, q), singleProducts(r, q), 1e-5);
+    }
+  }
+}
+
 BOOST_AUTO_TEST_SUITE_END();




More information about the mlpack-svn mailing list