[mlpack-svn] r12710 - mlpack/trunk/src/mlpack/tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu May 17 12:55:59 EDT 2012
Author: rcurtin
Date: 2012-05-17 12:55:58 -0400 (Thu, 17 May 2012)
New Revision: 12710
Added:
mlpack/trunk/src/mlpack/tests/max_ip_test.cpp
Modified:
mlpack/trunk/src/mlpack/tests/CMakeLists.txt
Log:
Add simple first test for MaxIP.
Modified: mlpack/trunk/src/mlpack/tests/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/tests/CMakeLists.txt 2012-05-17 16:55:50 UTC (rev 12709)
+++ mlpack/trunk/src/mlpack/tests/CMakeLists.txt 2012-05-17 16:55:58 UTC (rev 12710)
@@ -21,6 +21,7 @@
local_coordinate_coding_test.cpp
lrsdp_test.cpp
math_test.cpp
+ max_ip_test.cpp
nbc_test.cpp
nca_test.cpp
pca_test.cpp
Added: mlpack/trunk/src/mlpack/tests/max_ip_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/max_ip_test.cpp (rev 0)
+++ mlpack/trunk/src/mlpack/tests/max_ip_test.cpp 2012-05-17 16:55:58 UTC (rev 12710)
@@ -0,0 +1,55 @@
+/**
+ * @file max_ip_test.cpp
+ * @author Ryan Curtin
+ *
+ * Ensure that the maximum inner product search is successful.
+ */
+#include <mlpack/core.hpp>
+#include <mlpack/methods/maxip/max_ip.hpp>
+#include <mlpack/core/kernels/linear_kernel.hpp>
+
+#include <boost/test/unit_test.hpp>
+#include "old_boost_test_definitions.hpp"
+
+using namespace mlpack;
+using namespace mlpack::tree;
+using namespace mlpack::maxip;
+using namespace mlpack::kernel;
+
+BOOST_AUTO_TEST_SUITE(MaxIPTest);
+
+/**
+ * Compare single-tree and naive.
+ */
+BOOST_AUTO_TEST_CASE(SingleTreeVsNaive)
+{
+ // First create a random dataset.
+ arma::mat data;
+ data.randn(5, 5000);
+
+ // Now run MaxIP naively.
+ MaxIP<LinearKernel> naive(data, false, true);
+
+ arma::Mat<size_t> naiveIndices;
+ arma::mat naiveProducts;
+ naive.Search(10, naiveIndices, naiveProducts);
+
+ // Now run it in single-tree mode.
+ MaxIP<LinearKernel> single(data, true);
+
+ arma::Mat<size_t> singleIndices;
+ arma::mat singleProducts;
+ single.Search(10, singleIndices, singleProducts);
+
+ // Compare the results.
+ for (size_t q = 0; q < singleIndices.n_cols; ++q)
+ {
+ for (size_t r = 0; r < singleIndices.n_rows; ++r)
+ {
+ BOOST_REQUIRE_EQUAL(singleIndices(r, q), naiveIndices(r, q));
+ BOOST_REQUIRE_CLOSE(singleProducts(r, q), naiveProducts(r, q), 1e-5);
+ }
+ }
+}
+
+BOOST_AUTO_TEST_SUITE_END();
More information about the mlpack-svn
mailing list