[mlpack-git] master: Add command line parameter to calculate the effective error. (9a8a9eb)
gitdub at mlpack.org
gitdub at mlpack.org
Thu Aug 11 15:06:28 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/0f4b25acd6aaa14294c044874ba6cc0751712baa...0a19d07bd39e6223991976474bc79671ba8aa0f0
>---------------------------------------------------------------
commit 9a8a9eb789f5a423faad41314314db22f7f59aa2
Author: MarcosPividori <marcos.pividori at gmail.com>
Date: Thu Aug 11 16:06:28 2016 -0300
Add command line parameter to calculate the effective error.
>---------------------------------------------------------------
9a8a9eb789f5a423faad41314314db22f7f59aa2
src/mlpack/methods/neighbor_search/knn_main.cpp | 26 +++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/src/mlpack/methods/neighbor_search/knn_main.cpp b/src/mlpack/methods/neighbor_search/knn_main.cpp
index 97db49d..0505687 100644
--- a/src/mlpack/methods/neighbor_search/knn_main.cpp
+++ b/src/mlpack/methods/neighbor_search/knn_main.cpp
@@ -82,6 +82,9 @@ PARAM_FLAG("single_mode", "If true, single-tree search is used (as opposed to "
"dual-tree search).", "S");
PARAM_DOUBLE_IN("epsilon", "If specified, will do approximate nearest neighbor "
"search with given relative error.", "e", 0);
+PARAM_STRING_IN("effective_error", "If specified, will compare the results "
+ "against the provided distances file, and will print the average relative "
+ "error.", "E", "");
// Convenience typedef.
typedef NSModel<NearestNeighborSort> KNNModel;
@@ -292,6 +295,29 @@ int main(int argc, char *argv[])
data::Save(CLI::GetParam<string>("neighbors_file"), neighbors);
if (CLI::HasParam("distances_file"))
data::Save(CLI::GetParam<string>("distances_file"), distances);
+
+ // Calculate the effective error, if desired.
+ if (CLI::HasParam("effective_error"))
+ {
+ const string exactFile = CLI::GetParam<string>("effective_error");
+ arma::mat distancesExact;
+ data::Load(exactFile, distancesExact, true);
+
+ if (distancesExact.n_elem != distances.n_elem)
+ Log::Fatal << "The effective error file must have the same number of "
+ << "values than the set of distances being queried!" << endl;
+
+ double effectiveError = 0;
+ for (size_t i = 0; i < distances.n_elem; i++)
+ {
+ if (distancesExact(i) != 0 && distances(i) != DBL_MAX)
+ effectiveError += (distances(i) - distancesExact(i)) /
+ distancesExact(i);
+ }
+ effectiveError /= distances.n_elem;
+
+ Log::Info << "Effective error: " << effectiveError << endl;
+ }
}
if (CLI::HasParam("output_model_file"))
More information about the mlpack-git
mailing list