[mlpack-git] master: Add epsilon for kfn (both epsilon and percentage). (7f68a27)

gitdub at mlpack.org gitdub at mlpack.org
Wed Jun 22 14:09:07 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/a9f5622c8a14409111f2d71bf5c0f8aaa8ad4ae1...37fda23945b4f998cd5fa6ec011ae345236c8552

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

commit 7f68a278d9a69de9d0564cea6d54c7db8c95a49a
Author: MarcosPividori <marcos.pividori at gmail.com>
Date:   Tue Jun 14 10:57:57 2016 -0300

    Add epsilon for kfn (both epsilon and percentage).


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

7f68a278d9a69de9d0564cea6d54c7db8c95a49a
 src/mlpack/methods/neighbor_search/kfn_main.cpp | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/mlpack/methods/neighbor_search/kfn_main.cpp b/src/mlpack/methods/neighbor_search/kfn_main.cpp
index 3a4e4b7..163e8ed 100644
--- a/src/mlpack/methods/neighbor_search/kfn_main.cpp
+++ b/src/mlpack/methods/neighbor_search/kfn_main.cpp
@@ -72,6 +72,8 @@ PARAM_INT("seed", "Random seed (if 0, std::time(NULL) is used).", "s", 0);
 PARAM_FLAG("naive", "If true, O(n^2) naive mode is used for computation.", "N");
 PARAM_FLAG("single_mode", "If true, single-tree search is used (as opposed to "
     "dual-tree search).", "s");
+PARAM_DOUBLE("epsilon", "If specified, will do approximate furthest neighbor "
+    "search with given relative error. Must be in the range [0,1).", "e", 0);
 PARAM_DOUBLE("percentage", "If specified, will do approximate furthest neighbor"
     " search. Must be in the range (0,1] (decimal form). Resultant neighbors "
     "will be at least (p*100) % of the distance as the true furthest neighbor.",
@@ -142,11 +144,23 @@ int main(int argc, char *argv[])
     Log::Fatal << "Invalid leaf size: " << lsInt << ".  Must be greater than 0."
         << endl;
 
+  // Sanity check on epsilon.
+  double epsilon = CLI::GetParam<double>("epsilon");
+  if (epsilon < 0 || epsilon >= 1)
+    Log::Fatal << "Invalid epsilon: " << epsilon << ".  Must be in the range "
+        << "[0,1)." << endl;
+
   // Sanity check on percentage.
   const double percentage = CLI::GetParam<double>("percentage");
   if (percentage <= 0 || percentage > 1)
-    Log::Fatal << "Invalid percentage: " << percentage
-        << ".  Must be in the range (0,1] (decimal form)."<< endl;
+    Log::Fatal << "Invalid percentage: " << percentage << ".  Must be in the "
+        << "range (0,1] (decimal form)." << endl;
+
+  if (CLI::HasParam("percentage") && CLI::HasParam("epsilon"))
+    Log::Fatal << "Cannot provide both epsilon and percentage." << endl;
+
+  if (CLI::HasParam("percentage"))
+    epsilon = 1 - percentage;
 
   // We either have to load the reference data, or we have to load the model.
   NSModel<FurthestNeighborSort> kfn;
@@ -186,7 +200,7 @@ int main(int argc, char *argv[])
         << referenceSet.n_rows << "x" << referenceSet.n_cols << ")." << endl;
 
     kfn.BuildModel(std::move(referenceSet), size_t(lsInt), naive, singleMode,
-        1 - percentage);
+        epsilon);
   }
   else
   {
@@ -202,7 +216,7 @@ int main(int argc, char *argv[])
     kfn.SingleMode() = CLI::HasParam("single_mode");
     kfn.Naive() = CLI::HasParam("naive");
     kfn.LeafSize() = size_t(lsInt);
-    kfn.Epsilon() = 1 - percentage;
+    kfn.Epsilon() = epsilon;
   }
 
   // Perform search, if desired.




More information about the mlpack-git mailing list