[mlpack] 12/53: Add flag to print test error.

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 5249e985a26a7a5cb00ba261db89c1c0e9c5f24e
Author: Ryan Curtin <ryan at ratml.org>
Date:   Tue Apr 19 20:17:47 2016 -0400

    Add flag to print test error.
---
 qdafn_main.cpp | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/qdafn_main.cpp b/qdafn_main.cpp
index 47969c8..0e86647 100644
--- a/qdafn_main.cpp
+++ b/qdafn_main.cpp
@@ -6,6 +6,7 @@
  */
 #include <mlpack/core.hpp>
 #include "qdafn.hpp"
+#include <mlpack/methods/neighbor_search/neighbor_search.hpp>
 
 using namespace qdafn;
 using namespace mlpack;
@@ -40,6 +41,9 @@ PARAM_STRING("neighbors_file", "File to save furthest neighbor indices to.",
 PARAM_STRING("distances_file", "File to save furthest neighbor distances to.",
     "d", "");
 
+PARAM_FLAG("calculate_error", "If set, calculate the average distance error.",
+    "e");
+
 int main(int argc, char** argv)
 {
   CLI::ParseCommandLine(argc, argv);
@@ -67,6 +71,25 @@ int main(int argc, char** argv)
   q.Search(queryData, k, neighbors, distances);
   Timer::Stop("qdafn_search");
 
+  // Print the number of base cases.
+  Log::Info << "Total distance evaluations: " <<
+      (queryData.n_cols * numProjections) << "." << endl;
+
+  if (CLI::HasParam("calculate_error"))
+  {
+    neighbor::AllkFN kfn(referenceData);
+
+    arma::Mat<size_t> trueNeighbors;
+    arma::mat trueDistances;
+
+    kfn.Search(queryData, 1, trueNeighbors, trueDistances);
+
+    const double averageError = arma::sum(trueDistances / distances.row(0)) /
+        distances.n_cols;
+
+    Log::Info << "Average error: " << averageError << "." << endl;
+  }
+
   // Save the results.
   if (CLI::HasParam("neighbors_file"))
     data::Save(CLI::GetParam<string>("neighbors_file"), neighbors);

-- 
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