[mlpack-git] master: Splits ComputeRecall test into multiple tests (5f0777e)

gitdub at mlpack.org gitdub at mlpack.org
Thu Jun 9 12:41:10 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/2bd1227d0f41dd61e444f3c84c56eefd946014e2...4129a7c1d7432498b7d2e991fdeb63b3e3c46fe4

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

commit 5f0777e0e2ad23a6c79f0030e24a504fe417788d
Author: Yannis Mentekidis <mentekid at gmail.com>
Date:   Thu Jun 9 19:41:10 2016 +0300

    Splits ComputeRecall test into multiple tests


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

5f0777e0e2ad23a6c79f0030e24a504fe417788d
 src/mlpack/tests/lsh_test.cpp | 55 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 52 insertions(+), 3 deletions(-)

diff --git a/src/mlpack/tests/lsh_test.cpp b/src/mlpack/tests/lsh_test.cpp
index 30844d4..0988059 100644
--- a/src/mlpack/tests/lsh_test.cpp
+++ b/src/mlpack/tests/lsh_test.cpp
@@ -327,10 +327,10 @@ BOOST_AUTO_TEST_CASE(LSHTrainTest)
 }
 
 /**
- * Test: this verifies ComputeRecall works correctly. It inputs a few "base" and
- * "found" vectors and checks that recall is what expected.
+ * Test: this verifies ComputeRecall works correctly by providing two identical
+ * vectors and requiring that Recall is equal to 1.
  */
-BOOST_AUTO_TEST_CASE(ComputeRecallTest)
+BOOST_AUTO_TEST_CASE(RecallTestIdentical)
 {
   const size_t k = 5; // 5 nearest neighbors
   const size_t numQueries = 1;
@@ -347,6 +347,23 @@ BOOST_AUTO_TEST_CASE(ComputeRecallTest)
   
   LSHSearch<> lsh;
   BOOST_REQUIRE_EQUAL(lsh.ComputeRecall(base, q1), 1);
+}
+
+/**
+ * Test: this verifies ComputeRecall returns correct values for partially
+ * correct found neighbors. This is important because this is a good example of
+ * how the recall and accuracy metrics differ - accuracy in this case would be
+ * 0, recall should not be
+ */
+BOOST_AUTO_TEST_CASE(RecallTestPartiallyCorrect)
+{
+  const size_t k = 5; // 5 nearest neighbors
+  const size_t numQueries = 1;
+
+  // base = [1; 2; 3; 4; 5]
+  arma::Mat<size_t> base;
+  base.set_size(k, numQueries);
+  base.col(0) = arma::linspace< arma::Col<size_t> >(1, k, k);
 
   // q2 = [2; 3; 4; 6; 7]. Expect recall = 0.6. This is important because this
   // is a good example of how recall and accuracy differ. Accuracy here would
@@ -360,17 +377,49 @@ BOOST_AUTO_TEST_CASE(ComputeRecallTest)
     6 << arma::endr << 
     7 << arma::endr;
 
+  LSHSearch<> lsh;
   BOOST_REQUIRE_CLOSE(lsh.ComputeRecall(base, q2), 0.6, 0.0001);
+}
+
+/**
+ * Test: If given a completely wrong vector, ComputeRecall should return 0
+ */
+BOOST_AUTO_TEST_CASE(RecallTestIncorrect)
+{
+  const size_t k = 5; // 5 nearest neighbors
+  const size_t numQueries = 1;
 
+  // base = [1; 2; 3; 4; 5]
+  arma::Mat<size_t> base;
+  base.set_size(k, numQueries);
+  base.col(0) = arma::linspace< arma::Col<size_t> >(1, k, k);
   // q3 = [6; 7; 8; 9; 10]. Expected recall = 0
   arma::Mat<size_t> q3;
   q3.set_size(k, numQueries);
   q3.col(0) = arma::linspace< arma::Col<size_t> >(k + 1, 2 * k, k);
+
+  LSHSearch<> lsh;
   BOOST_REQUIRE_EQUAL(lsh.ComputeRecall(base, q3), 0);
+}
 
+/**
+ * Test: If given a vector of wrong shape, ComputeRecall should throw an
+ * exception
+ */
+BOOST_AUTO_TEST_CASE(RecallTestException)
+{
+  const size_t k = 5; // 5 nearest neighbors
+  const size_t numQueries = 1;
+
+  // base = [1; 2; 3; 4; 5]
+  arma::Mat<size_t> base;
+  base.set_size(k, numQueries);
+  base.col(0) = arma::linspace< arma::Col<size_t> >(1, k, k);
   // verify that nonsense arguments throw exception
   arma::Mat<size_t> q4;
   q4.set_size(2 * k, numQueries);
+
+  LSHSearch<> lsh;
   BOOST_REQUIRE_THROW(lsh.ComputeRecall(base, q4), std::invalid_argument);
 
 }




More information about the mlpack-git mailing list