[mlpack] 09/53: A better test. I'm reasonably convinced this works right now.

Barak A. Pearlmutter barak+git at pearlmutter.net
Mon Nov 14 00:46:46 UTC 2016


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch master
in repository mlpack.

commit 19c6965d55f76793702b22257b2db17b9c955e93
Author: Ryan Curtin <ryan at ratml.org>
Date:   Tue Apr 19 13:18:28 2016 -0700

    A better test.  I'm reasonably convinced this works right now.
---
 qdafn_test.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/qdafn_test.cpp b/qdafn_test.cpp
index 83c1da4..ee10610 100644
--- a/qdafn_test.cpp
+++ b/qdafn_test.cpp
@@ -10,11 +10,13 @@
 
 #include <mlpack/core.hpp>
 #include "qdafn.hpp"
+#include <mlpack/methods/neighbor_search/neighbor_search.hpp>
 
 using namespace std;
 using namespace arma;
 using namespace mlpack;
 using namespace qdafn;
+using namespace mlpack::neighbor;
 
 /**
  * With one reference point, make sure that is the one that is returned.
@@ -48,3 +50,53 @@ BOOST_AUTO_TEST_CASE(QDAFNTrivialTest)
     BOOST_REQUIRE_CLOSE(distances[i], dist, 1e-5);
   }
 }
+
+/**
+ * Given a random uniform reference set, ensure that we get a neighbor and
+ * distance within 10% of the actual true furthest neighbor distance at least
+ * 70% of the time.
+ */
+BOOST_AUTO_TEST_CASE(QDAFNUniformSet)
+{
+  arma::mat uniformSet = arma::randu<arma::mat>(25, 1000);
+
+  QDAFN<> qdafn(uniformSet, 10, 30);
+
+  // Get the actual neighbors.
+  AllkFN kfn(uniformSet);
+  arma::Mat<size_t> trueNeighbors;
+  arma::mat trueDistances;
+
+  kfn.Search(1000, trueNeighbors, trueDistances);
+
+  arma::Mat<size_t> qdafnNeighbors;
+  arma::mat qdafnDistances;
+
+  qdafn.Search(uniformSet, 1, qdafnNeighbors, qdafnDistances);
+
+  BOOST_REQUIRE_EQUAL(qdafnNeighbors.n_rows, 1);
+  BOOST_REQUIRE_EQUAL(qdafnNeighbors.n_cols, 1000);
+  BOOST_REQUIRE_EQUAL(qdafnDistances.n_rows, 1);
+  BOOST_REQUIRE_EQUAL(qdafnDistances.n_cols, 1000);
+
+  size_t successes = 0;
+  for (size_t i = 0; i < 1000; ++i)
+  {
+    // Find the true neighbor.
+    size_t trueIndex = 1000;
+    for (size_t j = 0; j < 1000; ++j)
+    {
+      if (trueNeighbors(j, i) == qdafnNeighbors(0, i))
+      {
+        trueIndex = j;
+        break;
+      }
+    }
+
+    BOOST_REQUIRE_NE(trueIndex, 1000);
+    if (0.9 * trueDistances(0, i) <= qdafnDistances(0, i))
+      ++successes;
+  }
+
+  BOOST_REQUIRE_GE(successes, 700);
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list