From 6db6de598389d780d51fe19a1d8484f9f1071920 Mon Sep 17 00:00:00 2001 From: MarcosPividori Date: Thu, 2 Jun 2016 15:53:45 -0300 Subject: [PATCH 01/13] Modify KNN/KFN to include Approximate Neighbor Search. --- .../methods/neighbor_search/kfn_main.cpp | 12 ++++- .../methods/neighbor_search/knn_main.cpp | 14 ++++-- .../neighbor_search/neighbor_search.hpp | 15 +++++++ .../neighbor_search/neighbor_search_impl.hpp | 32 +++++++++---- .../neighbor_search/neighbor_search_rules.hpp | 4 ++ .../neighbor_search_rules_impl.hpp | 10 ++++- .../methods/neighbor_search/ns_model.hpp | 17 ++++++- .../methods/neighbor_search/ns_model_impl.hpp | 45 +++++++++++++++---- .../sort_policies/furthest_neighbor_sort.hpp | 17 +++++++ .../sort_policies/nearest_neighbor_sort.hpp | 15 +++++++ 10 files changed, 158 insertions(+), 23 deletions(-) diff --git a/src/mlpack/methods/neighbor_search/kfn_main.cpp b/src/mlpack/methods/neighbor_search/kfn_main.cpp index d6807400e7..a2fbf2eba9 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.", "e", 0); // Convenience typedef. typedef NSModel KFNModel; @@ -138,6 +140,12 @@ int main(int argc, char *argv[]) Log::Fatal << "Invalid leaf size: " << lsInt << ". Must be greater than 0." << endl; + // Sanity check on epsilon. + const double epsilon = CLI::GetParam("epsilon"); + if (epsilon < 0) + Log::Fatal << "Invalid epsilon: " << epsilon << ". Must be non-negative. " + << endl; + // We either have to load the reference data, or we have to load the model. NSModel kfn; const bool naive = CLI::HasParam("naive"); @@ -175,7 +183,8 @@ int main(int argc, char *argv[]) Log::Info << "Loaded reference data from '" << referenceFile << "' (" << referenceSet.n_rows << "x" << referenceSet.n_cols << ")." << endl; - kfn.BuildModel(std::move(referenceSet), size_t(lsInt), naive, singleMode); + kfn.BuildModel(std::move(referenceSet), size_t(lsInt), naive, singleMode, + epsilon); } else { @@ -191,6 +200,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() = epsilon; } // Perform search, if desired. diff --git a/src/mlpack/methods/neighbor_search/knn_main.cpp b/src/mlpack/methods/neighbor_search/knn_main.cpp index 4957e88ebe..880f5db90f 100644 --- a/src/mlpack/methods/neighbor_search/knn_main.cpp +++ b/src/mlpack/methods/neighbor_search/knn_main.cpp @@ -74,6 +74,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 nearest neighbor " + "search with given relative error.", "e", 0); // Convenience typedef. typedef NSModel KNNModel; @@ -137,10 +139,14 @@ int main(int argc, char *argv[]) // Sanity check on leaf size. const int lsInt = CLI::GetParam("leaf_size"); if (lsInt < 1) - { Log::Fatal << "Invalid leaf size: " << lsInt << ". Must be greater " "than 0." << endl; - } + + // Sanity check on epsilon. + const double epsilon = CLI::GetParam("epsilon"); + if (epsilon < 0) + Log::Fatal << "Invalid epsilon: " << epsilon << ". Must be non-negative. " + << endl; // We either have to load the reference data, or we have to load the model. NSModel knn; @@ -180,7 +186,8 @@ int main(int argc, char *argv[]) << referenceSet.n_rows << " x " << referenceSet.n_cols << ")." << endl; - knn.BuildModel(std::move(referenceSet), size_t(lsInt), naive, singleMode); + knn.BuildModel(std::move(referenceSet), size_t(lsInt), naive, singleMode, + epsilon); } else { @@ -196,6 +203,7 @@ int main(int argc, char *argv[]) knn.SingleMode() = CLI::HasParam("single_mode"); knn.Naive() = CLI::HasParam("naive"); knn.LeafSize() = size_t(lsInt); + knn.Epsilon() = epsilon; } // Perform search, if desired. diff --git a/src/mlpack/methods/neighbor_search/neighbor_search.hpp b/src/mlpack/methods/neighbor_search/neighbor_search.hpp index 999f261c8f..f1acea458d 100644 --- a/src/mlpack/methods/neighbor_search/neighbor_search.hpp +++ b/src/mlpack/methods/neighbor_search/neighbor_search.hpp @@ -84,11 +84,13 @@ class NeighborSearch * dual-tree search). This overrides singleMode (if it is set to true). * @param singleMode If true, single-tree search will be used (as opposed to * dual-tree search). + * @param epsilon Relative approximate error (non-negative). * @param metric An optional instance of the MetricType class. */ NeighborSearch(const MatType& referenceSet, const bool naive = false, const bool singleMode = false, + const double epsilon = 0, const MetricType metric = MetricType()); /** @@ -108,11 +110,13 @@ class NeighborSearch * dual-tree search). This overrides singleMode (if it is set to true). * @param singleMode If true, single-tree search will be used (as opposed to * dual-tree search). + * @param epsilon Relative approximate error (non-negative). * @param metric An optional instance of the MetricType class. */ NeighborSearch(MatType&& referenceSet, const bool naive = false, const bool singleMode = false, + const double epsilon = 0, const MetricType metric = MetricType()); /** @@ -138,10 +142,12 @@ class NeighborSearch * @param referenceSet Set of reference points corresponding to referenceTree. * @param singleMode Whether single-tree computation should be used (as * opposed to dual-tree computation). + * @param epsilon Relative approximate error (non-negative). * @param metric Instantiated distance metric. */ NeighborSearch(Tree* referenceTree, const bool singleMode = false, + const double epsilon = 0, const MetricType metric = MetricType()); /** @@ -152,10 +158,12 @@ class NeighborSearch * @param naive Whether to use naive search. * @param singleMode Whether single-tree computation should be used (as * opposed to dual-tree computation). + * @param epsilon Relative approximate error (non-negative). * @param metric Instantiated metric. */ NeighborSearch(const bool naive = false, const bool singleMode = false, + const double epsilon = 0, const MetricType metric = MetricType()); @@ -270,6 +278,11 @@ class NeighborSearch //! Modify whether or not search is done in single-tree mode. bool& SingleMode() { return singleMode; } + //! Access the relative error to be considered in approximate search. + double Epsilon() const { return epsilon; } + //! Modify the relative error to be considered in approximate search. + double& Epsilon() { return epsilon; } + //! Access the reference dataset. const MatType& ReferenceSet() const { return *referenceSet; } @@ -294,6 +307,8 @@ class NeighborSearch bool naive; //! Indicates if single-tree search is being used (as opposed to dual-tree). bool singleMode; + //! Indicates the relative error to be considered in approximate search. + double epsilon; //! Instantiation of metric. MetricType metric; diff --git a/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp b/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp index d86f5146e1..2d7468bbf7 100644 --- a/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp +++ b/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp @@ -75,6 +75,7 @@ NeighborSearch:: NeighborSearch(const MatType& referenceSetIn, const bool naive, const bool singleMode, + const double epsilon, const MetricType metric) : referenceTree(naive ? NULL : BuildTree(referenceSetIn, oldFromNewReferences)), @@ -83,12 +84,14 @@ NeighborSearch(const MatType& referenceSetIn, setOwner(false), naive(naive), singleMode(!naive && singleMode), // No single mode if naive. + epsilon(epsilon), metric(metric), baseCases(0), scores(0), treeNeedsReset(false) { - // Nothing to do. + if (epsilon < 0) + throw std::invalid_argument("epsilon must be non-negative"); } // Construct the object. @@ -103,6 +106,7 @@ NeighborSearch:: NeighborSearch(MatType&& referenceSetIn, const bool naive, const bool singleMode, + const double epsilon, const MetricType metric) : referenceTree(naive ? NULL : BuildTree(std::move(referenceSetIn), @@ -113,12 +117,14 @@ NeighborSearch(MatType&& referenceSetIn, setOwner(naive), naive(naive), singleMode(!naive && singleMode), + epsilon(epsilon), metric(metric), baseCases(0), scores(0), treeNeedsReset(false) { - // Nothing to do. + if (epsilon < 0) + throw std::invalid_argument("epsilon must be non-negative"); } // Construct the object. @@ -132,6 +138,7 @@ template:: NeighborSearch(Tree* referenceTree, const bool singleMode, + const double epsilon, const MetricType metric) : referenceTree(referenceTree), referenceSet(&referenceTree->Dataset()), @@ -139,12 +146,14 @@ NeighborSearch(Tree* referenceTree, setOwner(false), naive(false), singleMode(singleMode), + epsilon(epsilon), metric(metric), baseCases(0), scores(0), treeNeedsReset(false) { - // Nothing else to initialize. + if (epsilon < 0) + throw std::invalid_argument("epsilon must be non-negative"); } // Construct the object without a reference dataset. @@ -158,6 +167,7 @@ template:: NeighborSearch(const bool naive, const bool singleMode, + const double epsilon, const MetricType metric) : referenceTree(NULL), referenceSet(new MatType()), // Empty matrix. @@ -165,11 +175,14 @@ NeighborSearch:: setOwner(true), naive(naive), singleMode(singleMode), + epsilon(epsilon), metric(metric), baseCases(0), scores(0), treeNeedsReset(false) { + if (epsilon < 0) + throw std::invalid_argument("epsilon must be non-negative"); // Build the tree on the empty dataset, if necessary. if (!naive) { @@ -364,7 +377,8 @@ Search(const MatType& querySet, if (naive) { // Create the helper object for the tree traversal. - RuleType rules(*referenceSet, querySet, *neighborPtr, *distancePtr, metric); + RuleType rules(*referenceSet, querySet, *neighborPtr, *distancePtr, metric, + epsilon); // The naive brute-force traversal. for (size_t i = 0; i < querySet.n_cols; ++i) @@ -376,7 +390,8 @@ Search(const MatType& querySet, else if (singleMode) { // Create the helper object for the tree traversal. - RuleType rules(*referenceSet, querySet, *neighborPtr, *distancePtr, metric); + RuleType rules(*referenceSet, querySet, *neighborPtr, *distancePtr, metric, + epsilon); // Create the traverser. typename Tree::template SingleTreeTraverser traverser(rules); @@ -402,7 +417,7 @@ Search(const MatType& querySet, // Create the helper object for the tree traversal. RuleType rules(*referenceSet, queryTree->Dataset(), *neighborPtr, - *distancePtr, metric); + *distancePtr, metric, epsilon); // Create the traverser. TraversalType traverser(rules); @@ -527,7 +542,8 @@ Search(Tree* queryTree, // Create the helper object for the traversal. typedef NeighborSearchRules RuleType; - RuleType rules(*referenceSet, querySet, *neighborPtr, distances, metric); + RuleType rules(*referenceSet, querySet, *neighborPtr, distances, metric, + epsilon); // Create the traverser. TraversalType traverser(rules); @@ -598,7 +614,7 @@ Search(const size_t k, // Create the helper object for the traversal. typedef NeighborSearchRules RuleType; RuleType rules(*referenceSet, *referenceSet, *neighborPtr, *distancePtr, - metric, true /* don't return the same point as nearest neighbor */); + metric, epsilon, true /* don't return the same point as nearest neighbor */); if (naive) { diff --git a/src/mlpack/methods/neighbor_search/neighbor_search_rules.hpp b/src/mlpack/methods/neighbor_search/neighbor_search_rules.hpp index 474d22b005..47a7933dd0 100644 --- a/src/mlpack/methods/neighbor_search/neighbor_search_rules.hpp +++ b/src/mlpack/methods/neighbor_search/neighbor_search_rules.hpp @@ -22,6 +22,7 @@ class NeighborSearchRules arma::Mat& neighbors, arma::mat& distances, MetricType& metric, + const double epsilon = 0, const bool sameSet = false); /** * Get the distance from the query point to the reference point. @@ -120,6 +121,9 @@ class NeighborSearchRules //! Denotes whether or not the reference and query sets are the same. bool sameSet; + //! Relative error to be considered in approximate search. + const double epsilon; + //! The last query point BaseCase() was called with. size_t lastQueryIndex; //! The last reference point BaseCase() was called with. diff --git a/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp b/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp index cc2b957491..6edf103136 100644 --- a/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp +++ b/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp @@ -20,6 +20,7 @@ NeighborSearchRules::NeighborSearchRules( arma::Mat& neighbors, arma::mat& distances, MetricType& metric, + const double epsilon, const bool sameSet) : referenceSet(referenceSet), querySet(querySet), @@ -27,6 +28,7 @@ NeighborSearchRules::NeighborSearchRules( distances(distances), metric(metric), sameSet(sameSet), + epsilon(epsilon), lastQueryIndex(querySet.n_cols), lastReferenceIndex(referenceSet.n_cols), baseCases(0), @@ -112,7 +114,8 @@ inline double NeighborSearchRules::Score( } // Compare against the best k'th distance for this query point so far. - const double bestDistance = distances(distances.n_rows - 1, queryIndex); + double bestDistance = distances(distances.n_rows - 1, queryIndex); + bestDistance = SortPolicy::Relax(bestDistance, epsilon); return (SortPolicy::IsBetter(distance, bestDistance)) ? distance : DBL_MAX; } @@ -128,7 +131,8 @@ inline double NeighborSearchRules::Rescore( return oldScore; // Just check the score again against the distances. - const double bestDistance = distances(distances.n_rows - 1, queryIndex); + double bestDistance = distances(distances.n_rows - 1, queryIndex); + bestDistance = SortPolicy::Relax(bestDistance, epsilon); return (SortPolicy::IsBetter(oldScore, bestDistance)) ? oldScore : DBL_MAX; } @@ -419,6 +423,8 @@ inline double NeighborSearchRules:: queryNode.Stat().SecondBound() = bestDistance; queryNode.Stat().AuxBound() = auxDistance; + worstDistance = SortPolicy::Relax(worstDistance, epsilon); + if (SortPolicy::IsBetter(worstDistance, bestDistance)) return worstDistance; else diff --git a/src/mlpack/methods/neighbor_search/ns_model.hpp b/src/mlpack/methods/neighbor_search/ns_model.hpp index d87549e920..db3331a3e4 100644 --- a/src/mlpack/methods/neighbor_search/ns_model.hpp +++ b/src/mlpack/methods/neighbor_search/ns_model.hpp @@ -177,6 +177,16 @@ class NaiveVisitor : public boost::static_visitor bool& operator()(NSType *ns) const; }; +/** + * EpsilonVisitor exposes the Epsilon method of the given NSType. + */ +class EpsilonVisitor : public boost::static_visitor +{ + public: + template + double& operator()(NSType *ns) const; +}; + /** * ReferenceSetVisitor exposes the referenceSet of the given NSType. */ @@ -266,6 +276,10 @@ class NSModel bool Naive() const; bool& Naive(); + //! Expose Epsilon. + double Epsilon() const; + double& Epsilon(); + //! Expose leafSize. size_t LeafSize() const { return leafSize; } size_t& LeafSize() { return leafSize; } @@ -282,7 +296,8 @@ class NSModel void BuildModel(arma::mat&& referenceSet, const size_t leafSize, const bool naive, - const bool singleMode); + const bool singleMode, + const double epsilon = 0); //! Perform neighbor search. The query set will be reordered. void Search(arma::mat&& querySet, diff --git a/src/mlpack/methods/neighbor_search/ns_model_impl.hpp b/src/mlpack/methods/neighbor_search/ns_model_impl.hpp index 5ed97721cd..bbca3d2a3b 100644 --- a/src/mlpack/methods/neighbor_search/ns_model_impl.hpp +++ b/src/mlpack/methods/neighbor_search/ns_model_impl.hpp @@ -185,6 +185,15 @@ bool& NaiveVisitor::operator()(NSType* ns) const throw std::runtime_error("no neighbor search model initialized"); } +//! Expose the Epsilon method of the given NSType. +template +double& EpsilonVisitor::operator()(NSType* ns) const +{ + if (ns) + return ns->Epsilon(); + throw std::runtime_error("no neighbor search model initialized"); +} + //! Expose the referenceSet of the given NSType. template const arma::mat& ReferenceSetVisitor::operator()(NSType* ns) const @@ -293,12 +302,25 @@ bool& NSModel::Naive() return boost::apply_visitor(NaiveVisitor(), nSearch); } +template +double NSModel::Epsilon() const +{ + return boost::apply_visitor(EpsilonVisitor(), nSearch); +} + +template +double& NSModel::Epsilon() +{ + return boost::apply_visitor(EpsilonVisitor(), nSearch); +} + //! Build the reference tree. template void NSModel::BuildModel(arma::mat&& referenceSet, const size_t leafSize, const bool naive, - const bool singleMode) + const bool singleMode, + const double epsilon) { // Initialize random basis if necessary. if (randomBasis) @@ -348,23 +370,26 @@ void NSModel::BuildModel(arma::mat&& referenceSet, switch (treeType) { case KD_TREE: - nSearch = new NSType(naive, singleMode); + nSearch = new NSType(naive, singleMode, + epsilon); break; case COVER_TREE: nSearch = new NSType(naive, - singleMode); + singleMode, epsilon); break; case R_TREE: - nSearch = new NSType(naive, singleMode); + nSearch = new NSType(naive, singleMode, epsilon); break; case R_STAR_TREE: - nSearch = new NSType(naive, singleMode); + nSearch = new NSType(naive, singleMode, + epsilon); break; case BALL_TREE: - nSearch = new NSType(naive, singleMode); + nSearch = new NSType(naive, singleMode, + epsilon); break; case X_TREE: - nSearch = new NSType(naive, singleMode); + nSearch = new NSType(naive, singleMode, epsilon); break; } @@ -389,7 +414,11 @@ void NSModel::Search(arma::mat&& querySet, if (randomBasis) querySet = q * querySet; - Log::Info << "Searching for " << k << " nearest neighbors with "; + Log::Info << "Searching for " << k; + if (Epsilon() != 0) + Log::Info << " approximate nearest neighbors (e=" << Epsilon() << ") with "; + else + Log::Info << " nearest neighbors with "; if (!Naive() && !SingleMode()) Log::Info << "dual-tree " << TreeName() << " search..." << std::endl; else if (!Naive()) diff --git a/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp b/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp index 87a72622e8..a69c167921 100644 --- a/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp +++ b/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp @@ -145,6 +145,23 @@ class FurthestNeighborSort */ static inline double CombineWorst(const double a, const double b) { return std::max(a - b, 0.0); } + + /** + * Return the given value relaxed. + * + * @param value Value to relax. + * @param epsilon Relative error (non-negative). + * + * @return double Value relaxed. + */ + static inline double Relax(const double value, const double epsilon) + { + if (value == 0) + return 0; + if (value == DBL_MAX || epsilon >= 1) + return DBL_MAX; + return (1 / (1 - epsilon)) * value; + } }; } // namespace neighbor diff --git a/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp b/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp index f57635a2a5..42a08b0641 100644 --- a/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp +++ b/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp @@ -150,6 +150,21 @@ class NearestNeighborSort return DBL_MAX; return a + b; } + + /** + * Return the given value relaxed. + * + * @param value Value to relax. + * @param epsilon Relative error (non-negative). + * + * @return double Value relaxed. + */ + static inline double Relax(const double value, const double epsilon) + { + if (value == DBL_MAX) + return DBL_MAX; + return (1 / (1 + epsilon)) * value; + } }; } // namespace neighbor From 0f65abf878cf37fa0fb6e8c04bd2b85524355320 Mon Sep 17 00:00:00 2001 From: MarcosPividori Date: Mon, 6 Jun 2016 13:35:52 -0300 Subject: [PATCH 02/13] Add tests for approximate Nearest Neighbor Search. --- src/mlpack/tests/CMakeLists.txt | 1 + src/mlpack/tests/aknn_test.cpp | 397 ++++++++++++++++++++++++++++++++ 2 files changed, 398 insertions(+) create mode 100644 src/mlpack/tests/aknn_test.cpp diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index bd204f7e0d..1d5f61bb25 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -31,6 +31,7 @@ add_executable(mlpack_test kmeans_test.cpp knn_test.cpp krann_search_test.cpp + aknn_test.cpp lars_test.cpp lbfgs_test.cpp lin_alg_test.cpp diff --git a/src/mlpack/tests/aknn_test.cpp b/src/mlpack/tests/aknn_test.cpp new file mode 100644 index 0000000000..0fab49b72c --- /dev/null +++ b/src/mlpack/tests/aknn_test.cpp @@ -0,0 +1,397 @@ +/** + * @file aknn_test.cpp + * + * Test file for KNN class with different values of epsilon. + */ +#include +#include +#include +#include +#include +#include +#include +#include "old_boost_test_definitions.hpp" + +using namespace mlpack; +using namespace mlpack::neighbor; +using namespace mlpack::tree; +using namespace mlpack::metric; +using namespace mlpack::bound; + +BOOST_AUTO_TEST_SUITE(AKNNTest); + +/** + * Test the dual-tree nearest-neighbors method with different values for + * epsilon. This uses both a query and reference dataset. + * + * Errors are produced if the results are not according to relative error. + */ +BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) +{ + arma::mat dataset; + + if (!data::Load("test_data_3_1000.csv", dataset)) + BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); + + KNN naive(dataset, true); + arma::Mat neighborsNaive; + arma::mat distancesNaive; + naive.Search(dataset, 15, neighborsNaive, distancesNaive); + + for (size_t c = 0; c < 4; c++) + { + KNN* knn; + double epsilon; + + switch (c) + { + case 0: // Use the dual-tree method with e=0.02. + epsilon = 0.02; + break; + case 1: // Use the dual-tree method with e=0.05. + epsilon = 0.05; + break; + case 2: // Use the dual-tree method with e=0.10. + epsilon = 0.10; + break; + case 3: // Use the dual-tree method with e=0.20. + epsilon = 0.20; + break; + } + + knn = new KNN(dataset, false, false, epsilon); + + // Now perform the actual calculation. + arma::Mat neighborsTree; + arma::mat distancesTree; + knn->Search(dataset, 15, neighborsTree, distancesTree); + + for (size_t i = 0; i < neighborsTree.n_elem; i++) + BOOST_REQUIRE_CLOSE(distancesTree(i), distancesNaive(i), epsilon * 100); + + // Clean the memory. + delete knn; + } +} + +/** + * Test the dual-tree nearest-neighbors method with the naive method. This uses + * only a reference dataset. + * + * Errors are produced if the results are not according to relative error. + */ +BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) +{ + arma::mat dataset; + + if (!data::Load("test_data_3_1000.csv", dataset)) + BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); + + KNN naive(dataset, true); + arma::Mat neighborsNaive; + arma::mat distancesNaive; + naive.Search(15, neighborsNaive, distancesNaive); + + KNN knn(dataset, false, false, 0.05); + arma::Mat neighborsTree; + arma::mat distancesTree; + knn.Search(15, neighborsTree, distancesTree); + + for (size_t i = 0; i < neighborsTree.n_elem; i++) + BOOST_REQUIRE_CLOSE(distancesTree(i), distancesNaive(i), 5); +} + +/** + * Test the single-tree nearest-neighbors method with the naive method. This + * uses only a reference dataset. + * + * Errors are produced if the results are not according to relative error. + */ +BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) +{ + arma::mat dataset; + + if (!data::Load("test_data_3_1000.csv", dataset)) + BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); + + KNN naive(dataset, true); + arma::Mat neighborsNaive; + arma::mat distancesNaive; + naive.Search(15, neighborsNaive, distancesNaive); + + KNN knn(dataset, false, true, 0.05); + arma::Mat neighborsTree; + arma::mat distancesTree; + knn.Search(15, neighborsTree, distancesTree); + + for (size_t i = 0; i < neighborsTree.n_elem; i++) + BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 5); +} + +/** + * Test the cover tree single-tree nearest-neighbors method against the naive + * method. This uses only a random reference dataset. + * + * Errors are produced if the results are not according to relative error. + */ +BOOST_AUTO_TEST_CASE(SingleCoverTreeTest) +{ + arma::mat data; + data.randu(75, 1000); // 75 dimensional, 1000 points. + + KNN naive(data, true); + arma::Mat naiveNeighbors; + arma::mat naiveDistances; + naive.Search(data, 15, naiveNeighbors, naiveDistances); + + StandardCoverTree, + arma::mat> tree(data); + + NeighborSearch, arma::mat, StandardCoverTree> + coverTreeSearch(&tree, true, 0.05); + + arma::Mat coverTreeNeighbors; + arma::mat coverTreeDistances; + coverTreeSearch.Search(data, 15, coverTreeNeighbors, coverTreeDistances); + + for (size_t i = 0; i < coverTreeNeighbors.n_elem; ++i) + BOOST_REQUIRE_CLOSE(coverTreeDistances[i], naiveDistances[i], 5); +} + +/** + * Test the cover tree dual-tree nearest neighbors method against the naive + * method. + * + * Errors are produced if the results are not according to relative error. + */ +BOOST_AUTO_TEST_CASE(DualCoverTreeTest) +{ + arma::mat dataset; + data::Load("test_data_3_1000.csv", dataset); + + KNN naive(dataset, true); + arma::Mat naiveNeighbors; + arma::mat naiveDistances; + naive.Search(dataset, 15, naiveNeighbors, naiveDistances); + + StandardCoverTree, + arma::mat> referenceTree(dataset); + + NeighborSearch coverTreeSearch(&referenceTree, false, 0.05); + + arma::Mat coverNeighbors; + arma::mat coverDistances; + coverTreeSearch.Search(&referenceTree, 15, coverNeighbors, coverDistances); + + for (size_t i = 0; i < coverNeighbors.n_elem; ++i) + BOOST_REQUIRE_CLOSE(coverDistances[i], naiveDistances[i], 5); +} + +/** + * Test the ball tree single-tree nearest-neighbors method against the naive + * method. This uses only a random reference dataset. + * + * Errors are produced if the results are not according to relative error. + */ +BOOST_AUTO_TEST_CASE(SingleBallTreeTest) +{ + arma::mat data; + data.randu(50, 300); // 50 dimensional, 300 points. + + KNN naive(data, true); + arma::Mat naiveNeighbors; + arma::mat naiveDistances; + naive.Search(data, 15, naiveNeighbors, naiveDistances); + + NeighborSearch + ballTreeSearch(data, false, true, 0.05); + + arma::Mat ballNeighbors; + arma::mat ballDistances; + ballTreeSearch.Search(data, 15, ballNeighbors, ballDistances); + + for (size_t i = 0; i < ballNeighbors.n_elem; ++i) + BOOST_REQUIRE_CLOSE(ballDistances(i), naiveDistances(i), 5); +} + +/** + * Test the ball tree dual-tree nearest neighbors method against the naive + * method. + * + * Errors are produced if the results are not according to relative error. + */ +BOOST_AUTO_TEST_CASE(DualBallTreeTest) +{ + arma::mat dataset; + data::Load("test_data_3_1000.csv", dataset); + + KNN naive(dataset, true); + arma::Mat naiveNeighbors; + arma::mat naiveDistances; + naive.Search(15, naiveNeighbors, naiveDistances); + + NeighborSearch + ballTreeSearch(dataset, false, false, 0.05); + arma::Mat ballNeighbors; + arma::mat ballDistances; + ballTreeSearch.Search(15, ballNeighbors, ballDistances); + + for (size_t i = 0; i < ballNeighbors.n_elem; ++i) + BOOST_REQUIRE_CLOSE(ballDistances(i), naiveDistances(i), 5); +} + +// Make sure sparse nearest neighbors works with kd trees. +BOOST_AUTO_TEST_CASE(SparseKNNKDTreeTest) +{ + // The dimensionality of these datasets must be high so that the probability + // of a completely empty point is very low. In this case, with dimensionality + // 70, the probability of all 70 dimensions being zero is 0.8^70 = 1.65e-7 in + // the reference set and 0.9^70 = 6.27e-4 in the query set. + arma::sp_mat queryDataset; + queryDataset.sprandu(70, 200, 0.2); + arma::sp_mat referenceDataset; + referenceDataset.sprandu(70, 500, 0.1); + arma::mat denseQuery(queryDataset); + arma::mat denseReference(referenceDataset); + + typedef NeighborSearch SparseKNN; + + SparseKNN a(referenceDataset, false, false, 0.05); + KNN naive(denseReference, true); + + arma::mat sparseDistances; + arma::Mat sparseNeighbors; + a.Search(queryDataset, 10, sparseNeighbors, sparseDistances); + + arma::mat naiveDistances; + arma::Mat naiveNeighbors; + naive.Search(denseQuery, 10, naiveNeighbors, naiveDistances); + + for (size_t i = 0; i < naiveNeighbors.n_cols; ++i) + for (size_t j = 0; j < naiveNeighbors.n_rows; ++j) + BOOST_REQUIRE_CLOSE(naiveDistances(j, i), sparseDistances(j, i), 5); +} + +// Ensure that we can build an NSModel and get correct +// results. +BOOST_AUTO_TEST_CASE(KNNModelTest) +{ + typedef NSModel KNNModel; + + arma::mat queryData = arma::randu(10, 50); + arma::mat referenceData = arma::randu(10, 200); + + // Build all the possible models. + KNNModel models[12]; + models[0] = KNNModel(KNNModel::TreeTypes::KD_TREE, true); + models[1] = KNNModel(KNNModel::TreeTypes::KD_TREE, false); + models[2] = KNNModel(KNNModel::TreeTypes::COVER_TREE, true); + models[3] = KNNModel(KNNModel::TreeTypes::COVER_TREE, false); + models[4] = KNNModel(KNNModel::TreeTypes::R_TREE, true); + models[5] = KNNModel(KNNModel::TreeTypes::R_TREE, false); + models[6] = KNNModel(KNNModel::TreeTypes::R_STAR_TREE, true); + models[7] = KNNModel(KNNModel::TreeTypes::R_STAR_TREE, false); + models[8] = KNNModel(KNNModel::TreeTypes::X_TREE, true); + models[9] = KNNModel(KNNModel::TreeTypes::X_TREE, false); + models[10] = KNNModel(KNNModel::TreeTypes::BALL_TREE, true); + models[11] = KNNModel(KNNModel::TreeTypes::BALL_TREE, false); + + for (size_t j = 0; j < 3; ++j) + { + // Get a baseline. + KNN knn(referenceData); + arma::Mat baselineNeighbors; + arma::mat baselineDistances; + knn.Search(queryData, 3, baselineNeighbors, baselineDistances); + + for (size_t i = 0; i < 12; ++i) + { + // We only have std::move() constructors so make a copy of our data. + arma::mat referenceCopy(referenceData); + arma::mat queryCopy(queryData); + if (j == 0) + models[i].BuildModel(std::move(referenceCopy), 20, false, false, 0.05); + if (j == 1) + models[i].BuildModel(std::move(referenceCopy), 20, false, true, 0.05); + if (j == 2) + models[i].BuildModel(std::move(referenceCopy), 20, true, false); + + arma::Mat neighbors; + arma::mat distances; + + models[i].Search(std::move(queryCopy), 3, neighbors, distances); + + BOOST_REQUIRE_EQUAL(neighbors.n_rows, baselineNeighbors.n_rows); + BOOST_REQUIRE_EQUAL(neighbors.n_cols, baselineNeighbors.n_cols); + BOOST_REQUIRE_EQUAL(neighbors.n_elem, baselineNeighbors.n_elem); + BOOST_REQUIRE_EQUAL(distances.n_rows, baselineDistances.n_rows); + BOOST_REQUIRE_EQUAL(distances.n_cols, baselineDistances.n_cols); + BOOST_REQUIRE_EQUAL(distances.n_elem, baselineDistances.n_elem); + for (size_t k = 0; k < distances.n_elem; ++k) + BOOST_REQUIRE_CLOSE(distances[k], baselineDistances[k], 5); + } + } +} + +// Ensure that we can build an NSModel and get correct +// results, in the case where the reference set is the same as the query set. +BOOST_AUTO_TEST_CASE(KNNModelMonochromaticTest) +{ + typedef NSModel KNNModel; + + arma::mat referenceData = arma::randu(10, 200); + + // Build all the possible models. + KNNModel models[12]; + models[0] = KNNModel(KNNModel::TreeTypes::KD_TREE, true); + models[1] = KNNModel(KNNModel::TreeTypes::KD_TREE, false); + models[2] = KNNModel(KNNModel::TreeTypes::COVER_TREE, true); + models[3] = KNNModel(KNNModel::TreeTypes::COVER_TREE, false); + models[4] = KNNModel(KNNModel::TreeTypes::R_TREE, true); + models[5] = KNNModel(KNNModel::TreeTypes::R_TREE, false); + models[6] = KNNModel(KNNModel::TreeTypes::R_STAR_TREE, true); + models[7] = KNNModel(KNNModel::TreeTypes::R_STAR_TREE, false); + models[8] = KNNModel(KNNModel::TreeTypes::X_TREE, true); + models[9] = KNNModel(KNNModel::TreeTypes::X_TREE, false); + models[10] = KNNModel(KNNModel::TreeTypes::BALL_TREE, true); + models[11] = KNNModel(KNNModel::TreeTypes::BALL_TREE, false); + + for (size_t j = 0; j < 3; ++j) + { + // Get a baseline. + KNN knn(referenceData); + arma::Mat baselineNeighbors; + arma::mat baselineDistances; + knn.Search(3, baselineNeighbors, baselineDistances); + + for (size_t i = 0; i < 12; ++i) + { + // We only have a std::move() constructor... so copy the data. + arma::mat referenceCopy(referenceData); + if (j == 0) + models[i].BuildModel(std::move(referenceCopy), 20, false, false, 0.05); + if (j == 1) + models[i].BuildModel(std::move(referenceCopy), 20, false, true, 0.05); + if (j == 2) + models[i].BuildModel(std::move(referenceCopy), 20, true, false); + + arma::Mat neighbors; + arma::mat distances; + + models[i].Search(3, neighbors, distances); + + BOOST_REQUIRE_EQUAL(neighbors.n_rows, baselineNeighbors.n_rows); + BOOST_REQUIRE_EQUAL(neighbors.n_cols, baselineNeighbors.n_cols); + BOOST_REQUIRE_EQUAL(neighbors.n_elem, baselineNeighbors.n_elem); + BOOST_REQUIRE_EQUAL(distances.n_rows, baselineDistances.n_rows); + BOOST_REQUIRE_EQUAL(distances.n_cols, baselineDistances.n_cols); + BOOST_REQUIRE_EQUAL(distances.n_elem, baselineDistances.n_elem); + for (size_t k = 0; k < distances.n_elem; ++k) + BOOST_REQUIRE_CLOSE(distances[k], baselineDistances[k], 5); + } + } +} + +BOOST_AUTO_TEST_SUITE_END(); From c64bdba5ca5fe578904e6b8ebe54cc9dda1562e3 Mon Sep 17 00:00:00 2001 From: MarcosPividori Date: Mon, 6 Jun 2016 13:37:32 -0300 Subject: [PATCH 03/13] Add tests for approximate Furthest Neighbor Search. --- src/mlpack/tests/CMakeLists.txt | 1 + src/mlpack/tests/akfn_test.cpp | 241 ++++++++++++++++++++++++++++++++ 2 files changed, 242 insertions(+) create mode 100644 src/mlpack/tests/akfn_test.cpp diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index 1d5f61bb25..967edeee4e 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -28,6 +28,7 @@ add_executable(mlpack_test kernel_pca_test.cpp kernel_traits_test.cpp kfn_test.cpp + akfn_test.cpp kmeans_test.cpp knn_test.cpp krann_search_test.cpp diff --git a/src/mlpack/tests/akfn_test.cpp b/src/mlpack/tests/akfn_test.cpp new file mode 100644 index 0000000000..59178c57da --- /dev/null +++ b/src/mlpack/tests/akfn_test.cpp @@ -0,0 +1,241 @@ +/** + * @file akfn_test.cpp + * + * Tests for KFN (k-furthest-neighbors) with different values of epsilon. + */ +#include +#include +#include +#include +#include "old_boost_test_definitions.hpp" + +using namespace mlpack; +using namespace mlpack::neighbor; +using namespace mlpack::tree; +using namespace mlpack::metric; +using namespace mlpack::bound; + +BOOST_AUTO_TEST_SUITE(AKFNTest); + +/** + * Test the dual-tree furthest-neighbors method with different values for + * epsilon. This uses both a query and reference dataset. + * + * Errors are produced if the results are not according to relative error. + */ +BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) +{ + arma::mat dataset; + + if (!data::Load("test_data_3_1000.csv", dataset)) + BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); + + KFN naive(dataset, true); + arma::Mat neighborsNaive; + arma::mat distancesNaive; + naive.Search(dataset, 15, neighborsNaive, distancesNaive); + + for (size_t c = 0; c < 4; c++) + { + KFN* kfn; + double epsilon; + + switch (c) + { + case 0: // Use the dual-tree method with e=0.02. + epsilon = 0.02; + break; + case 1: // Use the dual-tree method with e=0.05. + epsilon = 0.05; + break; + case 2: // Use the dual-tree method with e=0.10. + epsilon = 0.10; + break; + case 3: // Use the dual-tree method with e=0.20. + epsilon = 0.20; + break; + } + + kfn = new KFN(dataset, false, false, epsilon); + + // Now perform the actual calculation. + arma::Mat neighborsTree; + arma::mat distancesTree; + kfn->Search(dataset, 15, neighborsTree, distancesTree); + + for (size_t i = 0; i < neighborsTree.n_elem; i++) + BOOST_REQUIRE_CLOSE(distancesTree(i), distancesNaive(i), epsilon * 100); + + // Clean the memory. + delete kfn; + } +} + +/** + * Test the dual-tree furthest-neighbors method with the naive method. This + * uses only a reference dataset. + * + * Errors are produced if the results are not according to relative error. + */ +BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) +{ + arma::mat dataset; + + if (!data::Load("test_data_3_1000.csv", dataset)) + BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); + + KFN naive(dataset, true); + arma::Mat neighborsNaive; + arma::mat distancesNaive; + naive.Search(15, neighborsNaive, distancesNaive); + + KFN kfn(dataset, false, false, 0.05); + arma::Mat neighborsTree; + arma::mat distancesTree; + kfn.Search(15, neighborsTree, distancesTree); + + for (size_t i = 0; i < neighborsTree.n_elem; i++) + BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 5); +} + +/** + * Test the single-tree furthest-neighbors method with the naive method. This + * uses only a reference dataset. + * + * Errors are produced if the results are not according to relative error. + */ +BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) +{ + arma::mat dataset; + + if (!data::Load("test_data_3_1000.csv", dataset)) + BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); + + KFN naive(dataset, true); + arma::Mat neighborsNaive; + arma::mat distancesNaive; + naive.Search(15, neighborsNaive, distancesNaive); + + KFN kfn(dataset, false, true, 0.05); + arma::Mat neighborsTree; + arma::mat distancesTree; + kfn.Search(15, neighborsTree, distancesTree); + + for (size_t i = 0; i < neighborsTree.n_elem; i++) + BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 5); +} + +/** + * Test the cover tree single-tree furthest-neighbors method against the naive + * method. This uses only a random reference dataset. + * + * Errors are produced if the results are not according to relative error. + */ +BOOST_AUTO_TEST_CASE(SingleCoverTreeTest) +{ + arma::mat data; + data.randu(75, 1000); // 75 dimensional, 1000 points. + + KFN naive(data, true); + arma::Mat naiveNeighbors; + arma::mat naiveDistances; + naive.Search(data, 15, naiveNeighbors, naiveDistances); + + StandardCoverTree, + arma::mat> tree(data); + + NeighborSearch, arma::mat, StandardCoverTree> + coverTreeSearch(&tree, true, 0.05); + + arma::Mat coverTreeNeighbors; + arma::mat coverTreeDistances; + coverTreeSearch.Search(data, 15, coverTreeNeighbors, coverTreeDistances); + + for (size_t i = 0; i < coverTreeNeighbors.n_elem; ++i) + BOOST_REQUIRE_CLOSE(coverTreeDistances[i], naiveDistances[i], 5); +} + +/** + * Test the cover tree dual-tree furthest neighbors method against the naive + * method. + * + * Errors are produced if the results are not according to relative error. + */ +BOOST_AUTO_TEST_CASE(DualCoverTreeTest) +{ + arma::mat dataset; + data::Load("test_data_3_1000.csv", dataset); + + KFN naive(dataset, true); + arma::Mat naiveNeighbors; + arma::mat naiveDistances; + naive.Search(dataset, 15, naiveNeighbors, naiveDistances); + + StandardCoverTree, + arma::mat> referenceTree(dataset); + + NeighborSearch, arma::mat, StandardCoverTree> + coverTreeSearch(&referenceTree, false, 0.05); + + arma::Mat coverTreeNeighbors; + arma::mat coverTreeDistances; + coverTreeSearch.Search(dataset, 15, coverTreeNeighbors, coverTreeDistances); + + for (size_t i = 0; i < coverTreeNeighbors.n_elem; ++i) + BOOST_REQUIRE_CLOSE(coverTreeDistances[i], naiveDistances[i], 5); +} + +/** + * Test the ball tree single-tree furthest-neighbors method against the naive + * method. This uses only a random reference dataset. + * + * Errors are produced if the results are not according to relative error. + */ +BOOST_AUTO_TEST_CASE(SingleBallTreeTest) +{ + arma::mat data; + data.randu(75, 1000); // 75 dimensional, 1000 points. + + KFN naive(data, true); + arma::Mat naiveNeighbors; + arma::mat naiveDistances; + naive.Search(data, 15, naiveNeighbors, naiveDistances); + + NeighborSearch + ballTreeSearch(data, false, true, 0.05); + + arma::Mat ballNeighbors; + arma::mat ballDistances; + ballTreeSearch.Search(data, 15, ballNeighbors, ballDistances); + + for (size_t i = 0; i < ballNeighbors.n_elem; ++i) + BOOST_REQUIRE_CLOSE(ballDistances(i), naiveDistances(i), 5); +} + +/** + * Test the ball tree dual-tree furthest neighbors method against the naive + * method. + * + * Errors are produced if the results are not according to relative error. + */ +BOOST_AUTO_TEST_CASE(DualBallTreeTest) +{ + arma::mat dataset; + data::Load("test_data_3_1000.csv", dataset); + + KFN naive(dataset, true); + arma::Mat naiveNeighbors; + arma::mat naiveDistances; + naive.Search(15, naiveNeighbors, naiveDistances); + + NeighborSearch + ballTreeSearch(dataset, false, false, 0.05); + arma::Mat ballNeighbors; + arma::mat ballDistances; + ballTreeSearch.Search(15, ballNeighbors, ballDistances); + + for (size_t i = 0; i < ballNeighbors.n_elem; ++i) + BOOST_REQUIRE_CLOSE(ballDistances(i), naiveDistances(i), 5); +} + +BOOST_AUTO_TEST_SUITE_END(); From 5b99eda7868665906459b21640014139831c5ca2 Mon Sep 17 00:00:00 2001 From: MarcosPividori Date: Mon, 6 Jun 2016 15:04:28 -0300 Subject: [PATCH 04/13] Properly check relative error. BOOST_REQUIRE_CLOSE_FRACTION(VAL, REF, ERR) requires: abs(VAL - REF) <= ERR * REF && abs(VAL - REF) <= ERR * VAL REQUIRE_RELATIVE_ERR(VAL, REF, ERR) only requires: abs(VAL - REF) <= ERR * REF --- src/mlpack/tests/akfn_test.cpp | 14 ++++++------- src/mlpack/tests/aknn_test.cpp | 20 +++++++++---------- .../tests/old_boost_test_definitions.hpp | 5 +++++ 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/mlpack/tests/akfn_test.cpp b/src/mlpack/tests/akfn_test.cpp index 59178c57da..350e41e9bf 100644 --- a/src/mlpack/tests/akfn_test.cpp +++ b/src/mlpack/tests/akfn_test.cpp @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) kfn->Search(dataset, 15, neighborsTree, distancesTree); for (size_t i = 0; i < neighborsTree.n_elem; i++) - BOOST_REQUIRE_CLOSE(distancesTree(i), distancesNaive(i), epsilon * 100); + REQUIRE_RELATIVE_ERR(distancesTree(i), distancesNaive(i), epsilon); // Clean the memory. delete kfn; @@ -95,7 +95,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) kfn.Search(15, neighborsTree, distancesTree); for (size_t i = 0; i < neighborsTree.n_elem; i++) - BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 5); + REQUIRE_RELATIVE_ERR(distancesTree[i], distancesNaive[i], 0.05); } /** @@ -122,7 +122,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) kfn.Search(15, neighborsTree, distancesTree); for (size_t i = 0; i < neighborsTree.n_elem; i++) - BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 5); + REQUIRE_RELATIVE_ERR(distancesTree[i], distancesNaive[i], 0.05); } /** @@ -152,7 +152,7 @@ BOOST_AUTO_TEST_CASE(SingleCoverTreeTest) coverTreeSearch.Search(data, 15, coverTreeNeighbors, coverTreeDistances); for (size_t i = 0; i < coverTreeNeighbors.n_elem; ++i) - BOOST_REQUIRE_CLOSE(coverTreeDistances[i], naiveDistances[i], 5); + REQUIRE_RELATIVE_ERR(coverTreeDistances[i], naiveDistances[i], 0.05); } /** @@ -182,7 +182,7 @@ BOOST_AUTO_TEST_CASE(DualCoverTreeTest) coverTreeSearch.Search(dataset, 15, coverTreeNeighbors, coverTreeDistances); for (size_t i = 0; i < coverTreeNeighbors.n_elem; ++i) - BOOST_REQUIRE_CLOSE(coverTreeDistances[i], naiveDistances[i], 5); + REQUIRE_RELATIVE_ERR(coverTreeDistances[i], naiveDistances[i], 0.05); } /** @@ -209,7 +209,7 @@ BOOST_AUTO_TEST_CASE(SingleBallTreeTest) ballTreeSearch.Search(data, 15, ballNeighbors, ballDistances); for (size_t i = 0; i < ballNeighbors.n_elem; ++i) - BOOST_REQUIRE_CLOSE(ballDistances(i), naiveDistances(i), 5); + REQUIRE_RELATIVE_ERR(ballDistances(i), naiveDistances(i), 0.05); } /** @@ -235,7 +235,7 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest) ballTreeSearch.Search(15, ballNeighbors, ballDistances); for (size_t i = 0; i < ballNeighbors.n_elem; ++i) - BOOST_REQUIRE_CLOSE(ballDistances(i), naiveDistances(i), 5); + REQUIRE_RELATIVE_ERR(ballDistances(i), naiveDistances(i), 0.05); } BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/aknn_test.cpp b/src/mlpack/tests/aknn_test.cpp index 0fab49b72c..be14bf1fce 100644 --- a/src/mlpack/tests/aknn_test.cpp +++ b/src/mlpack/tests/aknn_test.cpp @@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) knn->Search(dataset, 15, neighborsTree, distancesTree); for (size_t i = 0; i < neighborsTree.n_elem; i++) - BOOST_REQUIRE_CLOSE(distancesTree(i), distancesNaive(i), epsilon * 100); + REQUIRE_RELATIVE_ERR(distancesTree(i), distancesNaive(i), epsilon); // Clean the memory. delete knn; @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) knn.Search(15, neighborsTree, distancesTree); for (size_t i = 0; i < neighborsTree.n_elem; i++) - BOOST_REQUIRE_CLOSE(distancesTree(i), distancesNaive(i), 5); + REQUIRE_RELATIVE_ERR(distancesTree(i), distancesNaive(i), 0.05); } /** @@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) knn.Search(15, neighborsTree, distancesTree); for (size_t i = 0; i < neighborsTree.n_elem; i++) - BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 5); + REQUIRE_RELATIVE_ERR(distancesTree[i], distancesNaive[i], 0.05); } /** @@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(SingleCoverTreeTest) coverTreeSearch.Search(data, 15, coverTreeNeighbors, coverTreeDistances); for (size_t i = 0; i < coverTreeNeighbors.n_elem; ++i) - BOOST_REQUIRE_CLOSE(coverTreeDistances[i], naiveDistances[i], 5); + REQUIRE_RELATIVE_ERR(coverTreeDistances[i], naiveDistances[i], 0.05); } /** @@ -185,7 +185,7 @@ BOOST_AUTO_TEST_CASE(DualCoverTreeTest) coverTreeSearch.Search(&referenceTree, 15, coverNeighbors, coverDistances); for (size_t i = 0; i < coverNeighbors.n_elem; ++i) - BOOST_REQUIRE_CLOSE(coverDistances[i], naiveDistances[i], 5); + REQUIRE_RELATIVE_ERR(coverDistances[i], naiveDistances[i], 0.05); } /** @@ -212,7 +212,7 @@ BOOST_AUTO_TEST_CASE(SingleBallTreeTest) ballTreeSearch.Search(data, 15, ballNeighbors, ballDistances); for (size_t i = 0; i < ballNeighbors.n_elem; ++i) - BOOST_REQUIRE_CLOSE(ballDistances(i), naiveDistances(i), 5); + REQUIRE_RELATIVE_ERR(ballDistances(i), naiveDistances(i), 0.05); } /** @@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest) ballTreeSearch.Search(15, ballNeighbors, ballDistances); for (size_t i = 0; i < ballNeighbors.n_elem; ++i) - BOOST_REQUIRE_CLOSE(ballDistances(i), naiveDistances(i), 5); + REQUIRE_RELATIVE_ERR(ballDistances(i), naiveDistances(i), 0.05); } // Make sure sparse nearest neighbors works with kd trees. @@ -271,7 +271,7 @@ BOOST_AUTO_TEST_CASE(SparseKNNKDTreeTest) for (size_t i = 0; i < naiveNeighbors.n_cols; ++i) for (size_t j = 0; j < naiveNeighbors.n_rows; ++j) - BOOST_REQUIRE_CLOSE(naiveDistances(j, i), sparseDistances(j, i), 5); + REQUIRE_RELATIVE_ERR(sparseDistances(j, i), naiveDistances(j, i), 0.05); } // Ensure that we can build an NSModel and get correct @@ -330,7 +330,7 @@ BOOST_AUTO_TEST_CASE(KNNModelTest) BOOST_REQUIRE_EQUAL(distances.n_cols, baselineDistances.n_cols); BOOST_REQUIRE_EQUAL(distances.n_elem, baselineDistances.n_elem); for (size_t k = 0; k < distances.n_elem; ++k) - BOOST_REQUIRE_CLOSE(distances[k], baselineDistances[k], 5); + REQUIRE_RELATIVE_ERR(distances[k], baselineDistances[k], 0.05); } } } @@ -389,7 +389,7 @@ BOOST_AUTO_TEST_CASE(KNNModelMonochromaticTest) BOOST_REQUIRE_EQUAL(distances.n_cols, baselineDistances.n_cols); BOOST_REQUIRE_EQUAL(distances.n_elem, baselineDistances.n_elem); for (size_t k = 0; k < distances.n_elem; ++k) - BOOST_REQUIRE_CLOSE(distances[k], baselineDistances[k], 5); + REQUIRE_RELATIVE_ERR(distances[k], baselineDistances[k], 0.05); } } } diff --git a/src/mlpack/tests/old_boost_test_definitions.hpp b/src/mlpack/tests/old_boost_test_definitions.hpp index 9d98c0b3ed..1586f6272c 100644 --- a/src/mlpack/tests/old_boost_test_definitions.hpp +++ b/src/mlpack/tests/old_boost_test_definitions.hpp @@ -35,4 +35,9 @@ #endif +// Require the approximation L to be within a relative error of E respect to the +// actual value R. +#define REQUIRE_RELATIVE_ERR( L, R, E ) \ + BOOST_REQUIRE_LE( abs((R) - (L)), (E) * (R)) + #endif From 44b90f2c2565919c73c0870324c3d53ddbf153e0 Mon Sep 17 00:00:00 2001 From: MarcosPividori Date: Tue, 7 Jun 2016 10:51:51 -0300 Subject: [PATCH 05/13] Update some comments/info. --- .../neighbor_search/neighbor_search_rules_impl.hpp | 4 ++-- src/mlpack/methods/neighbor_search/ns_model_impl.hpp | 10 ++++++---- .../sort_policies/furthest_neighbor_sort.cpp | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp b/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp index 6edf103136..24f94856f5 100644 --- a/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp +++ b/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp @@ -1,8 +1,8 @@ /** - * @file nearest_neighbor_rules_impl.hpp + * @file neighbor_search_rules_impl.hpp * @author Ryan Curtin * - * Implementation of NearestNeighborRules. + * Implementation of NeighborSearchRules. */ #ifndef MLPACK_METHODS_NEIGHBOR_SEARCH_NEAREST_NEIGHBOR_RULES_IMPL_HPP #define MLPACK_METHODS_NEIGHBOR_SEARCH_NEAREST_NEIGHBOR_RULES_IMPL_HPP diff --git a/src/mlpack/methods/neighbor_search/ns_model_impl.hpp b/src/mlpack/methods/neighbor_search/ns_model_impl.hpp index bbca3d2a3b..0a705626a6 100644 --- a/src/mlpack/methods/neighbor_search/ns_model_impl.hpp +++ b/src/mlpack/methods/neighbor_search/ns_model_impl.hpp @@ -416,9 +416,8 @@ void NSModel::Search(arma::mat&& querySet, Log::Info << "Searching for " << k; if (Epsilon() != 0) - Log::Info << " approximate nearest neighbors (e=" << Epsilon() << ") with "; - else - Log::Info << " nearest neighbors with "; + Log::Info << " approximate (e=" << Epsilon() << ")"; + Log::Info << " neighbors with "; if (!Naive() && !SingleMode()) Log::Info << "dual-tree " << TreeName() << " search..." << std::endl; else if (!Naive()) @@ -437,7 +436,10 @@ void NSModel::Search(const size_t k, arma::Mat& neighbors, arma::mat& distances) { - Log::Info << "Searching for " << k << " nearest neighbors with "; + Log::Info << "Searching for " << k; + if (Epsilon() != 0) + Log::Info << " approximate (e=" << Epsilon() << ")"; + Log::Info << " neighbors with "; if (!Naive() && !SingleMode()) Log::Info << "dual-tree " << TreeName() << " search..." << std::endl; else if (!Naive()) diff --git a/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.cpp b/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.cpp index aee4877398..f58e4d2c22 100644 --- a/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.cpp +++ b/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.cpp @@ -1,5 +1,5 @@ /*** - * @file nearest_neighbor_sort.cpp + * @file furthest_neighbor_sort.cpp * @author Ryan Curtin * * Implementation of the simple FurthestNeighborSort policy class. @@ -12,7 +12,7 @@ size_t FurthestNeighborSort::SortDistance(const arma::vec& list, const arma::Col& indices, double newDistance) { - // The first element in the list is the nearest neighbor. We only want to + // The first element in the list is the furthest neighbor. We only want to // insert if the new distance is greater than the last element in the list. if (newDistance < list[list.n_elem - 1]) return (size_t() - 1); // Do not insert. From d4a0f71f125b9ed09749ad9026f3922d6bff2010 Mon Sep 17 00:00:00 2001 From: MarcosPividori Date: Thu, 9 Jun 2016 16:33:45 -0300 Subject: [PATCH 06/13] Change file name for test tools. --- src/mlpack/tests/activation_functions_test.cpp | 2 +- src/mlpack/tests/ada_delta_test.cpp | 2 +- src/mlpack/tests/adaboost_test.cpp | 2 +- src/mlpack/tests/adam_test.cpp | 2 +- src/mlpack/tests/akfn_test.cpp | 2 +- src/mlpack/tests/aknn_test.cpp | 2 +- src/mlpack/tests/arma_extend_test.cpp | 2 +- src/mlpack/tests/armadillo_svd_test.cpp | 2 +- src/mlpack/tests/aug_lagrangian_test.cpp | 2 +- src/mlpack/tests/binarize_test.cpp | 2 +- src/mlpack/tests/cf_test.cpp | 2 +- src/mlpack/tests/cli_test.cpp | 2 +- src/mlpack/tests/convolution_test.cpp | 2 +- src/mlpack/tests/convolutional_network_test.cpp | 2 +- src/mlpack/tests/cosine_tree_test.cpp | 2 +- src/mlpack/tests/decision_stump_test.cpp | 2 +- src/mlpack/tests/det_test.cpp | 2 +- src/mlpack/tests/distribution_test.cpp | 2 +- src/mlpack/tests/emst_test.cpp | 2 +- src/mlpack/tests/fastmks_test.cpp | 2 +- src/mlpack/tests/feedforward_network_test.cpp | 2 +- src/mlpack/tests/gmm_test.cpp | 2 +- src/mlpack/tests/hmm_test.cpp | 2 +- src/mlpack/tests/hoeffding_tree_test.cpp | 2 +- src/mlpack/tests/ind2sub_test.cpp | 2 +- src/mlpack/tests/init_rules_test.cpp | 2 +- src/mlpack/tests/kernel_pca_test.cpp | 2 +- src/mlpack/tests/kernel_test.cpp | 2 +- src/mlpack/tests/kernel_traits_test.cpp | 2 +- src/mlpack/tests/kfn_test.cpp | 2 +- src/mlpack/tests/kmeans_test.cpp | 2 +- src/mlpack/tests/knn_test.cpp | 2 +- src/mlpack/tests/krann_search_test.cpp | 2 +- src/mlpack/tests/lars_test.cpp | 2 +- src/mlpack/tests/layer_traits_test.cpp | 2 +- src/mlpack/tests/lbfgs_test.cpp | 2 +- src/mlpack/tests/lin_alg_test.cpp | 2 +- src/mlpack/tests/linear_regression_test.cpp | 2 +- src/mlpack/tests/load_save_test.cpp | 2 +- src/mlpack/tests/local_coordinate_coding_test.cpp | 2 +- src/mlpack/tests/log_test.cpp | 2 +- src/mlpack/tests/logistic_regression_test.cpp | 2 +- src/mlpack/tests/lrsdp_test.cpp | 2 +- src/mlpack/tests/lsh_test.cpp | 2 +- src/mlpack/tests/lstm_peephole_test.cpp | 2 +- src/mlpack/tests/math_test.cpp | 2 +- src/mlpack/tests/matrix_completion_test.cpp | 2 +- src/mlpack/tests/maximal_inputs_test.cpp | 2 +- src/mlpack/tests/mean_shift_test.cpp | 2 +- src/mlpack/tests/metric_test.cpp | 2 +- src/mlpack/tests/minibatch_sgd_test.cpp | 2 +- src/mlpack/tests/mlpack_test.cpp | 2 +- src/mlpack/tests/nbc_test.cpp | 2 +- src/mlpack/tests/nca_test.cpp | 2 +- src/mlpack/tests/network_util_test.cpp | 2 +- src/mlpack/tests/nmf_test.cpp | 2 +- src/mlpack/tests/nystroem_method_test.cpp | 2 +- src/mlpack/tests/pca_test.cpp | 2 +- src/mlpack/tests/perceptron_test.cpp | 2 +- src/mlpack/tests/performance_functions_test.cpp | 2 +- src/mlpack/tests/pooling_rules_test.cpp | 2 +- src/mlpack/tests/quic_svd_test.cpp | 2 +- src/mlpack/tests/radical_test.cpp | 2 +- src/mlpack/tests/range_search_test.cpp | 2 +- src/mlpack/tests/rectangle_tree_test.cpp | 2 +- src/mlpack/tests/recurrent_network_test.cpp | 2 +- src/mlpack/tests/regularized_svd_test.cpp | 2 +- src/mlpack/tests/rmsprop_test.cpp | 2 +- src/mlpack/tests/sa_test.cpp | 2 +- src/mlpack/tests/sdp_primal_dual_test.cpp | 2 +- src/mlpack/tests/serialization.hpp | 2 +- src/mlpack/tests/serialization_test.cpp | 2 +- src/mlpack/tests/sgd_test.cpp | 2 +- src/mlpack/tests/softmax_regression_test.cpp | 2 +- src/mlpack/tests/sort_policy_test.cpp | 2 +- src/mlpack/tests/sparse_autoencoder_test.cpp | 2 +- src/mlpack/tests/sparse_coding_test.cpp | 2 +- src/mlpack/tests/split_data_test.cpp | 2 +- src/mlpack/tests/svd_batch_test.cpp | 2 +- src/mlpack/tests/svd_incremental_test.cpp | 2 +- src/mlpack/tests/termination_policy_test.cpp | 2 +- .../{old_boost_test_definitions.hpp => test_tools.hpp} | 9 ++++----- src/mlpack/tests/tree_test.cpp | 2 +- src/mlpack/tests/tree_traits_test.cpp | 2 +- src/mlpack/tests/union_find_test.cpp | 2 +- 85 files changed, 88 insertions(+), 89 deletions(-) rename src/mlpack/tests/{old_boost_test_definitions.hpp => test_tools.hpp} (79%) diff --git a/src/mlpack/tests/activation_functions_test.cpp b/src/mlpack/tests/activation_functions_test.cpp index 34ec009ddb..9f32f8d5f9 100644 --- a/src/mlpack/tests/activation_functions_test.cpp +++ b/src/mlpack/tests/activation_functions_test.cpp @@ -25,7 +25,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::ann; diff --git a/src/mlpack/tests/ada_delta_test.cpp b/src/mlpack/tests/ada_delta_test.cpp index 3471821505..483ce62b2f 100644 --- a/src/mlpack/tests/ada_delta_test.cpp +++ b/src/mlpack/tests/ada_delta_test.cpp @@ -12,7 +12,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace arma; using namespace mlpack::optimization; diff --git a/src/mlpack/tests/adaboost_test.cpp b/src/mlpack/tests/adaboost_test.cpp index fd5680d822..9edc57a606 100644 --- a/src/mlpack/tests/adaboost_test.cpp +++ b/src/mlpack/tests/adaboost_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" #include "serialization.hpp" using namespace arma; diff --git a/src/mlpack/tests/adam_test.cpp b/src/mlpack/tests/adam_test.cpp index df36980509..6daa5cb19c 100644 --- a/src/mlpack/tests/adam_test.cpp +++ b/src/mlpack/tests/adam_test.cpp @@ -11,7 +11,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace arma; using namespace mlpack::optimization; diff --git a/src/mlpack/tests/akfn_test.cpp b/src/mlpack/tests/akfn_test.cpp index 350e41e9bf..3621916c4b 100644 --- a/src/mlpack/tests/akfn_test.cpp +++ b/src/mlpack/tests/akfn_test.cpp @@ -7,7 +7,7 @@ #include #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::neighbor; diff --git a/src/mlpack/tests/aknn_test.cpp b/src/mlpack/tests/aknn_test.cpp index be14bf1fce..8d865ba360 100644 --- a/src/mlpack/tests/aknn_test.cpp +++ b/src/mlpack/tests/aknn_test.cpp @@ -10,7 +10,7 @@ #include #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::neighbor; diff --git a/src/mlpack/tests/arma_extend_test.cpp b/src/mlpack/tests/arma_extend_test.cpp index 076a02f3e3..79fd0e90d4 100644 --- a/src/mlpack/tests/arma_extend_test.cpp +++ b/src/mlpack/tests/arma_extend_test.cpp @@ -7,7 +7,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace arma; diff --git a/src/mlpack/tests/armadillo_svd_test.cpp b/src/mlpack/tests/armadillo_svd_test.cpp index cb945b3219..5cfc156ee4 100644 --- a/src/mlpack/tests/armadillo_svd_test.cpp +++ b/src/mlpack/tests/armadillo_svd_test.cpp @@ -2,7 +2,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" BOOST_AUTO_TEST_SUITE(ArmadilloSVDTest); diff --git a/src/mlpack/tests/aug_lagrangian_test.cpp b/src/mlpack/tests/aug_lagrangian_test.cpp index 9507899dbb..fd6ce6d8d5 100644 --- a/src/mlpack/tests/aug_lagrangian_test.cpp +++ b/src/mlpack/tests/aug_lagrangian_test.cpp @@ -10,7 +10,7 @@ #include #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::optimization; diff --git a/src/mlpack/tests/binarize_test.cpp b/src/mlpack/tests/binarize_test.cpp index d0488a2303..ea2638baa0 100644 --- a/src/mlpack/tests/binarize_test.cpp +++ b/src/mlpack/tests/binarize_test.cpp @@ -9,7 +9,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace arma; diff --git a/src/mlpack/tests/cf_test.cpp b/src/mlpack/tests/cf_test.cpp index 834e326f76..6a1f1a6620 100644 --- a/src/mlpack/tests/cf_test.cpp +++ b/src/mlpack/tests/cf_test.cpp @@ -10,7 +10,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" #include "serialization.hpp" BOOST_AUTO_TEST_SUITE(CFTest); diff --git a/src/mlpack/tests/cli_test.cpp b/src/mlpack/tests/cli_test.cpp index d0ebbd3a6e..e6cbc64bfe 100644 --- a/src/mlpack/tests/cli_test.cpp +++ b/src/mlpack/tests/cli_test.cpp @@ -22,7 +22,7 @@ #define DEFAULT_INT 42 #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" #define BASH_RED "\033[0;31m" #define BASH_GREEN "\033[0;32m" diff --git a/src/mlpack/tests/convolution_test.cpp b/src/mlpack/tests/convolution_test.cpp index 368f32d7a2..b273330ff1 100644 --- a/src/mlpack/tests/convolution_test.cpp +++ b/src/mlpack/tests/convolution_test.cpp @@ -13,7 +13,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::ann; diff --git a/src/mlpack/tests/convolutional_network_test.cpp b/src/mlpack/tests/convolutional_network_test.cpp index baa2dff36d..1ca68c2dee 100644 --- a/src/mlpack/tests/convolutional_network_test.cpp +++ b/src/mlpack/tests/convolutional_network_test.cpp @@ -23,7 +23,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::ann; diff --git a/src/mlpack/tests/cosine_tree_test.cpp b/src/mlpack/tests/cosine_tree_test.cpp index 925684f496..6a8c586e6d 100644 --- a/src/mlpack/tests/cosine_tree_test.cpp +++ b/src/mlpack/tests/cosine_tree_test.cpp @@ -9,7 +9,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" BOOST_AUTO_TEST_SUITE(CosineTreeTest); diff --git a/src/mlpack/tests/decision_stump_test.cpp b/src/mlpack/tests/decision_stump_test.cpp index 36c83f7b9e..dae9875dc7 100644 --- a/src/mlpack/tests/decision_stump_test.cpp +++ b/src/mlpack/tests/decision_stump_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::decision_stump; diff --git a/src/mlpack/tests/det_test.cpp b/src/mlpack/tests/det_test.cpp index 9e4e91edfe..7e32defa4d 100644 --- a/src/mlpack/tests/det_test.cpp +++ b/src/mlpack/tests/det_test.cpp @@ -7,7 +7,7 @@ */ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" // This trick does not work on Windows. We will have to comment out the tests // that depend on it. diff --git a/src/mlpack/tests/distribution_test.cpp b/src/mlpack/tests/distribution_test.cpp index 0ca0dfda1e..d0261dd545 100644 --- a/src/mlpack/tests/distribution_test.cpp +++ b/src/mlpack/tests/distribution_test.cpp @@ -7,7 +7,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::distribution; diff --git a/src/mlpack/tests/emst_test.cpp b/src/mlpack/tests/emst_test.cpp index b4776584b1..9e8831aa2e 100644 --- a/src/mlpack/tests/emst_test.cpp +++ b/src/mlpack/tests/emst_test.cpp @@ -6,7 +6,7 @@ #include #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" #include diff --git a/src/mlpack/tests/fastmks_test.cpp b/src/mlpack/tests/fastmks_test.cpp index 973da37965..a7b20e9598 100644 --- a/src/mlpack/tests/fastmks_test.cpp +++ b/src/mlpack/tests/fastmks_test.cpp @@ -9,7 +9,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" #include "serialization.hpp" using namespace mlpack; diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index 6ae92d4ab2..e1412b462b 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -24,7 +24,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::ann; diff --git a/src/mlpack/tests/gmm_test.cpp b/src/mlpack/tests/gmm_test.cpp index 83b9fd3f5b..561c261afe 100644 --- a/src/mlpack/tests/gmm_test.cpp +++ b/src/mlpack/tests/gmm_test.cpp @@ -15,7 +15,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::gmm; diff --git a/src/mlpack/tests/hmm_test.cpp b/src/mlpack/tests/hmm_test.cpp index 762090fdf1..7ea6403b8a 100644 --- a/src/mlpack/tests/hmm_test.cpp +++ b/src/mlpack/tests/hmm_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::hmm; diff --git a/src/mlpack/tests/hoeffding_tree_test.cpp b/src/mlpack/tests/hoeffding_tree_test.cpp index c060267cd1..1c6a678cea 100644 --- a/src/mlpack/tests/hoeffding_tree_test.cpp +++ b/src/mlpack/tests/hoeffding_tree_test.cpp @@ -12,7 +12,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" #include "serialization.hpp" #include diff --git a/src/mlpack/tests/ind2sub_test.cpp b/src/mlpack/tests/ind2sub_test.cpp index ef1014be0c..7f3518f2e9 100644 --- a/src/mlpack/tests/ind2sub_test.cpp +++ b/src/mlpack/tests/ind2sub_test.cpp @@ -6,7 +6,7 @@ */ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" BOOST_AUTO_TEST_SUITE(ind2subTest); diff --git a/src/mlpack/tests/init_rules_test.cpp b/src/mlpack/tests/init_rules_test.cpp index 3d09c268a2..5ef4b9929b 100644 --- a/src/mlpack/tests/init_rules_test.cpp +++ b/src/mlpack/tests/init_rules_test.cpp @@ -14,7 +14,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::ann; diff --git a/src/mlpack/tests/kernel_pca_test.cpp b/src/mlpack/tests/kernel_pca_test.cpp index dae716ff0b..e154630fbf 100644 --- a/src/mlpack/tests/kernel_pca_test.cpp +++ b/src/mlpack/tests/kernel_pca_test.cpp @@ -10,7 +10,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" BOOST_AUTO_TEST_SUITE(KernelPCATest); diff --git a/src/mlpack/tests/kernel_test.cpp b/src/mlpack/tests/kernel_test.cpp index f21835c570..1c320190bd 100644 --- a/src/mlpack/tests/kernel_test.cpp +++ b/src/mlpack/tests/kernel_test.cpp @@ -19,7 +19,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::kernel; diff --git a/src/mlpack/tests/kernel_traits_test.cpp b/src/mlpack/tests/kernel_traits_test.cpp index f9eb88d93b..408df4bcaf 100644 --- a/src/mlpack/tests/kernel_traits_test.cpp +++ b/src/mlpack/tests/kernel_traits_test.cpp @@ -9,7 +9,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::kernel; diff --git a/src/mlpack/tests/kfn_test.cpp b/src/mlpack/tests/kfn_test.cpp index 2701a6a71f..1fc536a63b 100644 --- a/src/mlpack/tests/kfn_test.cpp +++ b/src/mlpack/tests/kfn_test.cpp @@ -7,7 +7,7 @@ #include #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::neighbor; diff --git a/src/mlpack/tests/kmeans_test.cpp b/src/mlpack/tests/kmeans_test.cpp index 3089a3e76f..9353557259 100644 --- a/src/mlpack/tests/kmeans_test.cpp +++ b/src/mlpack/tests/kmeans_test.cpp @@ -18,7 +18,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::kmeans; diff --git a/src/mlpack/tests/knn_test.cpp b/src/mlpack/tests/knn_test.cpp index 51a854aafb..aa169b7b8a 100644 --- a/src/mlpack/tests/knn_test.cpp +++ b/src/mlpack/tests/knn_test.cpp @@ -10,7 +10,7 @@ #include #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::neighbor; diff --git a/src/mlpack/tests/krann_search_test.cpp b/src/mlpack/tests/krann_search_test.cpp index 37e9b35bcc..805adb39e9 100644 --- a/src/mlpack/tests/krann_search_test.cpp +++ b/src/mlpack/tests/krann_search_test.cpp @@ -10,7 +10,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" #include #include diff --git a/src/mlpack/tests/lars_test.cpp b/src/mlpack/tests/lars_test.cpp index 83bd0a8357..5b410fec3a 100644 --- a/src/mlpack/tests/lars_test.cpp +++ b/src/mlpack/tests/lars_test.cpp @@ -10,7 +10,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::regression; diff --git a/src/mlpack/tests/layer_traits_test.cpp b/src/mlpack/tests/layer_traits_test.cpp index 0a0e3cc50b..373d8781c5 100644 --- a/src/mlpack/tests/layer_traits_test.cpp +++ b/src/mlpack/tests/layer_traits_test.cpp @@ -13,7 +13,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::ann; diff --git a/src/mlpack/tests/lbfgs_test.cpp b/src/mlpack/tests/lbfgs_test.cpp index ea111f92ac..f16803c924 100644 --- a/src/mlpack/tests/lbfgs_test.cpp +++ b/src/mlpack/tests/lbfgs_test.cpp @@ -10,7 +10,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack::optimization; using namespace mlpack::optimization::test; diff --git a/src/mlpack/tests/lin_alg_test.cpp b/src/mlpack/tests/lin_alg_test.cpp index afb8876c30..6d11b36297 100644 --- a/src/mlpack/tests/lin_alg_test.cpp +++ b/src/mlpack/tests/lin_alg_test.cpp @@ -10,7 +10,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace arma; using namespace mlpack; diff --git a/src/mlpack/tests/linear_regression_test.cpp b/src/mlpack/tests/linear_regression_test.cpp index 6a0e8686d7..7f175c9544 100644 --- a/src/mlpack/tests/linear_regression_test.cpp +++ b/src/mlpack/tests/linear_regression_test.cpp @@ -7,7 +7,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::regression; diff --git a/src/mlpack/tests/load_save_test.cpp b/src/mlpack/tests/load_save_test.cpp index 3917aead1c..4eb8f12598 100644 --- a/src/mlpack/tests/load_save_test.cpp +++ b/src/mlpack/tests/load_save_test.cpp @@ -9,7 +9,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::data; diff --git a/src/mlpack/tests/local_coordinate_coding_test.cpp b/src/mlpack/tests/local_coordinate_coding_test.cpp index 2e51d90861..cc293b3767 100644 --- a/src/mlpack/tests/local_coordinate_coding_test.cpp +++ b/src/mlpack/tests/local_coordinate_coding_test.cpp @@ -10,7 +10,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" #include "serialization.hpp" using namespace arma; diff --git a/src/mlpack/tests/log_test.cpp b/src/mlpack/tests/log_test.cpp index 09a56c26f8..3a5a43d0d3 100644 --- a/src/mlpack/tests/log_test.cpp +++ b/src/mlpack/tests/log_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; diff --git a/src/mlpack/tests/logistic_regression_test.cpp b/src/mlpack/tests/logistic_regression_test.cpp index 7881bb248d..60acb1c0b5 100644 --- a/src/mlpack/tests/logistic_regression_test.cpp +++ b/src/mlpack/tests/logistic_regression_test.cpp @@ -9,7 +9,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::regression; diff --git a/src/mlpack/tests/lrsdp_test.cpp b/src/mlpack/tests/lrsdp_test.cpp index 1fe0f77f04..5a7b1cee3b 100644 --- a/src/mlpack/tests/lrsdp_test.cpp +++ b/src/mlpack/tests/lrsdp_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::optimization; diff --git a/src/mlpack/tests/lsh_test.cpp b/src/mlpack/tests/lsh_test.cpp index 65d1d78f66..8844972527 100644 --- a/src/mlpack/tests/lsh_test.cpp +++ b/src/mlpack/tests/lsh_test.cpp @@ -6,7 +6,7 @@ #include #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" #include #include diff --git a/src/mlpack/tests/lstm_peephole_test.cpp b/src/mlpack/tests/lstm_peephole_test.cpp index 6192e64123..fef1196235 100644 --- a/src/mlpack/tests/lstm_peephole_test.cpp +++ b/src/mlpack/tests/lstm_peephole_test.cpp @@ -9,7 +9,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::ann; diff --git a/src/mlpack/tests/math_test.cpp b/src/mlpack/tests/math_test.cpp index d5f80e8a3f..c68441d8c5 100644 --- a/src/mlpack/tests/math_test.cpp +++ b/src/mlpack/tests/math_test.cpp @@ -8,7 +8,7 @@ #include #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace math; diff --git a/src/mlpack/tests/matrix_completion_test.cpp b/src/mlpack/tests/matrix_completion_test.cpp index df7020f8ea..697e8098bc 100644 --- a/src/mlpack/tests/matrix_completion_test.cpp +++ b/src/mlpack/tests/matrix_completion_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::matrix_completion; diff --git a/src/mlpack/tests/maximal_inputs_test.cpp b/src/mlpack/tests/maximal_inputs_test.cpp index 62062e1a43..c6e8c109ce 100644 --- a/src/mlpack/tests/maximal_inputs_test.cpp +++ b/src/mlpack/tests/maximal_inputs_test.cpp @@ -9,7 +9,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; diff --git a/src/mlpack/tests/mean_shift_test.cpp b/src/mlpack/tests/mean_shift_test.cpp index e777e154aa..e7577d744f 100644 --- a/src/mlpack/tests/mean_shift_test.cpp +++ b/src/mlpack/tests/mean_shift_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::meanshift; diff --git a/src/mlpack/tests/metric_test.cpp b/src/mlpack/tests/metric_test.cpp index 7eff0bbe90..10952fea8e 100644 --- a/src/mlpack/tests/metric_test.cpp +++ b/src/mlpack/tests/metric_test.cpp @@ -6,7 +6,7 @@ #include #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace std; using namespace mlpack::metric; diff --git a/src/mlpack/tests/minibatch_sgd_test.cpp b/src/mlpack/tests/minibatch_sgd_test.cpp index 90e5b58577..410d4e3c45 100644 --- a/src/mlpack/tests/minibatch_sgd_test.cpp +++ b/src/mlpack/tests/minibatch_sgd_test.cpp @@ -13,7 +13,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace std; using namespace arma; diff --git a/src/mlpack/tests/mlpack_test.cpp b/src/mlpack/tests/mlpack_test.cpp index 5b9f7a8341..b10486ee0e 100644 --- a/src/mlpack/tests/mlpack_test.cpp +++ b/src/mlpack/tests/mlpack_test.cpp @@ -17,7 +17,7 @@ #endif #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" /** * Provide a global fixture for each test. diff --git a/src/mlpack/tests/nbc_test.cpp b/src/mlpack/tests/nbc_test.cpp index a3e43cdd64..dc96f8d954 100644 --- a/src/mlpack/tests/nbc_test.cpp +++ b/src/mlpack/tests/nbc_test.cpp @@ -7,7 +7,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace naive_bayes; diff --git a/src/mlpack/tests/nca_test.cpp b/src/mlpack/tests/nca_test.cpp index d1c00c5a8e..34b1a39714 100644 --- a/src/mlpack/tests/nca_test.cpp +++ b/src/mlpack/tests/nca_test.cpp @@ -11,7 +11,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::metric; diff --git a/src/mlpack/tests/network_util_test.cpp b/src/mlpack/tests/network_util_test.cpp index 766ed852c5..30d633129d 100644 --- a/src/mlpack/tests/network_util_test.cpp +++ b/src/mlpack/tests/network_util_test.cpp @@ -12,7 +12,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::ann; diff --git a/src/mlpack/tests/nmf_test.cpp b/src/mlpack/tests/nmf_test.cpp index 605ce39acc..f50b10a03b 100644 --- a/src/mlpack/tests/nmf_test.cpp +++ b/src/mlpack/tests/nmf_test.cpp @@ -12,7 +12,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" BOOST_AUTO_TEST_SUITE(NMFTest); diff --git a/src/mlpack/tests/nystroem_method_test.cpp b/src/mlpack/tests/nystroem_method_test.cpp index f705439b8e..241d9716b5 100644 --- a/src/mlpack/tests/nystroem_method_test.cpp +++ b/src/mlpack/tests/nystroem_method_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" #include #include diff --git a/src/mlpack/tests/pca_test.cpp b/src/mlpack/tests/pca_test.cpp index d7a78c8830..e4f3b6a311 100644 --- a/src/mlpack/tests/pca_test.cpp +++ b/src/mlpack/tests/pca_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" BOOST_AUTO_TEST_SUITE(PCATest); diff --git a/src/mlpack/tests/perceptron_test.cpp b/src/mlpack/tests/perceptron_test.cpp index 8f2de1e9b6..4fc1c8b57c 100644 --- a/src/mlpack/tests/perceptron_test.cpp +++ b/src/mlpack/tests/perceptron_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace arma; diff --git a/src/mlpack/tests/performance_functions_test.cpp b/src/mlpack/tests/performance_functions_test.cpp index 84839a13a7..9ad9342f45 100644 --- a/src/mlpack/tests/performance_functions_test.cpp +++ b/src/mlpack/tests/performance_functions_test.cpp @@ -11,7 +11,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::ann; diff --git a/src/mlpack/tests/pooling_rules_test.cpp b/src/mlpack/tests/pooling_rules_test.cpp index b85f3e85c9..9909316aeb 100644 --- a/src/mlpack/tests/pooling_rules_test.cpp +++ b/src/mlpack/tests/pooling_rules_test.cpp @@ -10,7 +10,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::ann; diff --git a/src/mlpack/tests/quic_svd_test.cpp b/src/mlpack/tests/quic_svd_test.cpp index f859e2116a..218bfff4c3 100644 --- a/src/mlpack/tests/quic_svd_test.cpp +++ b/src/mlpack/tests/quic_svd_test.cpp @@ -9,7 +9,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" BOOST_AUTO_TEST_SUITE(QUICSVDTest); diff --git a/src/mlpack/tests/radical_test.cpp b/src/mlpack/tests/radical_test.cpp index c5dc323696..c14f449ae7 100644 --- a/src/mlpack/tests/radical_test.cpp +++ b/src/mlpack/tests/radical_test.cpp @@ -7,7 +7,7 @@ #include #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" BOOST_AUTO_TEST_SUITE(RadicalTest); diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index 84cfed8dfc..88429719bd 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -9,7 +9,7 @@ #include #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::range; diff --git a/src/mlpack/tests/rectangle_tree_test.cpp b/src/mlpack/tests/rectangle_tree_test.cpp index f9278c554a..92595c6841 100644 --- a/src/mlpack/tests/rectangle_tree_test.cpp +++ b/src/mlpack/tests/rectangle_tree_test.cpp @@ -12,7 +12,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::neighbor; diff --git a/src/mlpack/tests/recurrent_network_test.cpp b/src/mlpack/tests/recurrent_network_test.cpp index 355aa81d4b..0ec1bcfe4f 100644 --- a/src/mlpack/tests/recurrent_network_test.cpp +++ b/src/mlpack/tests/recurrent_network_test.cpp @@ -20,7 +20,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::ann; diff --git a/src/mlpack/tests/regularized_svd_test.cpp b/src/mlpack/tests/regularized_svd_test.cpp index 1cbb741b5a..b29fe844f6 100644 --- a/src/mlpack/tests/regularized_svd_test.cpp +++ b/src/mlpack/tests/regularized_svd_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::svd; diff --git a/src/mlpack/tests/rmsprop_test.cpp b/src/mlpack/tests/rmsprop_test.cpp index 6fb3e745a3..b62d77f531 100644 --- a/src/mlpack/tests/rmsprop_test.cpp +++ b/src/mlpack/tests/rmsprop_test.cpp @@ -20,7 +20,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace arma; using namespace mlpack; diff --git a/src/mlpack/tests/sa_test.cpp b/src/mlpack/tests/sa_test.cpp index 05e7d9f181..3d87e5d954 100644 --- a/src/mlpack/tests/sa_test.cpp +++ b/src/mlpack/tests/sa_test.cpp @@ -14,7 +14,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace std; using namespace arma; diff --git a/src/mlpack/tests/sdp_primal_dual_test.cpp b/src/mlpack/tests/sdp_primal_dual_test.cpp index f3ed242497..0c42ea1d13 100644 --- a/src/mlpack/tests/sdp_primal_dual_test.cpp +++ b/src/mlpack/tests/sdp_primal_dual_test.cpp @@ -9,7 +9,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::optimization; diff --git a/src/mlpack/tests/serialization.hpp b/src/mlpack/tests/serialization.hpp index 39cf1d8ad9..a53a6e8b8f 100644 --- a/src/mlpack/tests/serialization.hpp +++ b/src/mlpack/tests/serialization.hpp @@ -17,7 +17,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" namespace mlpack { diff --git a/src/mlpack/tests/serialization_test.cpp b/src/mlpack/tests/serialization_test.cpp index 5dbb9aaf40..49a913f23f 100644 --- a/src/mlpack/tests/serialization_test.cpp +++ b/src/mlpack/tests/serialization_test.cpp @@ -7,7 +7,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" #include "serialization.hpp" #include diff --git a/src/mlpack/tests/sgd_test.cpp b/src/mlpack/tests/sgd_test.cpp index 1b273dcbdf..a8f389b1ac 100644 --- a/src/mlpack/tests/sgd_test.cpp +++ b/src/mlpack/tests/sgd_test.cpp @@ -10,7 +10,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace std; using namespace arma; diff --git a/src/mlpack/tests/softmax_regression_test.cpp b/src/mlpack/tests/softmax_regression_test.cpp index d7ed969dce..4fe8568eaf 100644 --- a/src/mlpack/tests/softmax_regression_test.cpp +++ b/src/mlpack/tests/softmax_regression_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::regression; diff --git a/src/mlpack/tests/sort_policy_test.cpp b/src/mlpack/tests/sort_policy_test.cpp index c6fcf5b87a..e336a76170 100644 --- a/src/mlpack/tests/sort_policy_test.cpp +++ b/src/mlpack/tests/sort_policy_test.cpp @@ -12,7 +12,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::neighbor; diff --git a/src/mlpack/tests/sparse_autoencoder_test.cpp b/src/mlpack/tests/sparse_autoencoder_test.cpp index 03d4e72d99..24d0cc6feb 100644 --- a/src/mlpack/tests/sparse_autoencoder_test.cpp +++ b/src/mlpack/tests/sparse_autoencoder_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::nn; diff --git a/src/mlpack/tests/sparse_coding_test.cpp b/src/mlpack/tests/sparse_coding_test.cpp index eab0b9c8aa..6815405e01 100644 --- a/src/mlpack/tests/sparse_coding_test.cpp +++ b/src/mlpack/tests/sparse_coding_test.cpp @@ -11,7 +11,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" #include "serialization.hpp" using namespace arma; diff --git a/src/mlpack/tests/split_data_test.cpp b/src/mlpack/tests/split_data_test.cpp index bbc529baae..1c52f632ba 100644 --- a/src/mlpack/tests/split_data_test.cpp +++ b/src/mlpack/tests/split_data_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace arma; diff --git a/src/mlpack/tests/svd_batch_test.cpp b/src/mlpack/tests/svd_batch_test.cpp index 36f354442f..45f9a12da3 100644 --- a/src/mlpack/tests/svd_batch_test.cpp +++ b/src/mlpack/tests/svd_batch_test.cpp @@ -7,7 +7,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" BOOST_AUTO_TEST_SUITE(SVDBatchTest); diff --git a/src/mlpack/tests/svd_incremental_test.cpp b/src/mlpack/tests/svd_incremental_test.cpp index 2def227416..4fdd4e4ca2 100644 --- a/src/mlpack/tests/svd_incremental_test.cpp +++ b/src/mlpack/tests/svd_incremental_test.cpp @@ -9,7 +9,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" BOOST_AUTO_TEST_SUITE(SVDIncrementalTest); diff --git a/src/mlpack/tests/termination_policy_test.cpp b/src/mlpack/tests/termination_policy_test.cpp index da51afbd88..945d82ce46 100644 --- a/src/mlpack/tests/termination_policy_test.cpp +++ b/src/mlpack/tests/termination_policy_test.cpp @@ -10,7 +10,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" BOOST_AUTO_TEST_SUITE(TerminationPolicyTest); diff --git a/src/mlpack/tests/old_boost_test_definitions.hpp b/src/mlpack/tests/test_tools.hpp similarity index 79% rename from src/mlpack/tests/old_boost_test_definitions.hpp rename to src/mlpack/tests/test_tools.hpp index 1586f6272c..2d4e56e235 100644 --- a/src/mlpack/tests/old_boost_test_definitions.hpp +++ b/src/mlpack/tests/test_tools.hpp @@ -1,12 +1,11 @@ /** - * @file old_boost_test_definitions.hpp + * @file test_tools.hpp * @author Ryan Curtin * - * Ancient Boost.Test versions don't act how we expect. This file includes the - * things we need to fix that. + * This file includes some useful macros for tests. */ -#ifndef MLPACK_TESTS_OLD_BOOST_TEST_DEFINITIONS_HPP -#define MLPACK_TESTS_OLD_BOOST_TEST_DEFINITIONS_HPP +#ifndef MLPACK_TESTS_TEST_TOOLS_HPP +#define MLPACK_TESTS_TEST_TOOLS_HPP #include diff --git a/src/mlpack/tests/tree_test.cpp b/src/mlpack/tests/tree_test.cpp index 14b2f51dd0..81a94463b2 100644 --- a/src/mlpack/tests/tree_test.cpp +++ b/src/mlpack/tests/tree_test.cpp @@ -14,7 +14,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::math; diff --git a/src/mlpack/tests/tree_traits_test.cpp b/src/mlpack/tests/tree_traits_test.cpp index e7b4925924..cf0395d19f 100644 --- a/src/mlpack/tests/tree_traits_test.cpp +++ b/src/mlpack/tests/tree_traits_test.cpp @@ -15,7 +15,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::tree; diff --git a/src/mlpack/tests/union_find_test.cpp b/src/mlpack/tests/union_find_test.cpp index 8468a2a78e..89e78ea8b6 100644 --- a/src/mlpack/tests/union_find_test.cpp +++ b/src/mlpack/tests/union_find_test.cpp @@ -8,7 +8,7 @@ #include #include -#include "old_boost_test_definitions.hpp" +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::emst; From af12e7665519f7342c6662594bb4b22d20a37d5b Mon Sep 17 00:00:00 2001 From: MarcosPividori Date: Thu, 9 Jun 2016 17:46:08 -0300 Subject: [PATCH 07/13] Fix style in test comments. --- src/mlpack/tests/aknn_test.cpp | 16 +++++++++++----- src/mlpack/tests/knn_test.cpp | 4 +++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/mlpack/tests/aknn_test.cpp b/src/mlpack/tests/aknn_test.cpp index 8d865ba360..70abcc8c05 100644 --- a/src/mlpack/tests/aknn_test.cpp +++ b/src/mlpack/tests/aknn_test.cpp @@ -241,7 +241,9 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest) REQUIRE_RELATIVE_ERR(ballDistances(i), naiveDistances(i), 0.05); } -// Make sure sparse nearest neighbors works with kd trees. +/** + * Make sure sparse nearest neighbors works with kd trees. + */ BOOST_AUTO_TEST_CASE(SparseKNNKDTreeTest) { // The dimensionality of these datasets must be high so that the probability @@ -274,8 +276,10 @@ BOOST_AUTO_TEST_CASE(SparseKNNKDTreeTest) REQUIRE_RELATIVE_ERR(sparseDistances(j, i), naiveDistances(j, i), 0.05); } -// Ensure that we can build an NSModel and get correct -// results. +/** + * Ensure that we can build an NSModel and get correct + * results. + */ BOOST_AUTO_TEST_CASE(KNNModelTest) { typedef NSModel KNNModel; @@ -335,8 +339,10 @@ BOOST_AUTO_TEST_CASE(KNNModelTest) } } -// Ensure that we can build an NSModel and get correct -// results, in the case where the reference set is the same as the query set. +/** + * Ensure that we can build an NSModel and get correct + * results, in the case where the reference set is the same as the query set. + */ BOOST_AUTO_TEST_CASE(KNNModelMonochromaticTest) { typedef NSModel KNNModel; diff --git a/src/mlpack/tests/knn_test.cpp b/src/mlpack/tests/knn_test.cpp index aa169b7b8a..85c6b7a79a 100644 --- a/src/mlpack/tests/knn_test.cpp +++ b/src/mlpack/tests/knn_test.cpp @@ -888,7 +888,9 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest) } } -// Make sure sparse nearest neighbors works with kd trees. +/** + * Make sure sparse nearest neighbors works with kd trees. + */ BOOST_AUTO_TEST_CASE(SparseKNNKDTreeTest) { // The dimensionality of these datasets must be high so that the probability From 7a5f66857932b98ca2a631ace6fb7beead7fe962 Mon Sep 17 00:00:00 2001 From: MarcosPividori Date: Sat, 11 Jun 2016 13:59:38 -0300 Subject: [PATCH 08/13] Replace Naive by Dual Tree in approximate tests. Also, Improve code details. --- src/mlpack/tests/akfn_test.cpp | 167 +++++++++++---------- src/mlpack/tests/aknn_test.cpp | 255 ++++++++++++++++----------------- 2 files changed, 209 insertions(+), 213 deletions(-) diff --git a/src/mlpack/tests/akfn_test.cpp b/src/mlpack/tests/akfn_test.cpp index 3621916c4b..61ec6f57a3 100644 --- a/src/mlpack/tests/akfn_test.cpp +++ b/src/mlpack/tests/akfn_test.cpp @@ -23,21 +23,21 @@ BOOST_AUTO_TEST_SUITE(AKFNTest); * * Errors are produced if the results are not according to relative error. */ -BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) +BOOST_AUTO_TEST_CASE(AproxVsExact1) { arma::mat dataset; if (!data::Load("test_data_3_1000.csv", dataset)) BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); - KFN naive(dataset, true); - arma::Mat neighborsNaive; - arma::mat distancesNaive; - naive.Search(dataset, 15, neighborsNaive, distancesNaive); + KFN exact(dataset); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(dataset, 15, neighborsExact, distancesExact); for (size_t c = 0; c < 4; c++) { - KFN* kfn; + KFN* akfn; double epsilon; switch (c) @@ -56,107 +56,106 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) break; } - kfn = new KFN(dataset, false, false, epsilon); - // Now perform the actual calculation. - arma::Mat neighborsTree; - arma::mat distancesTree; - kfn->Search(dataset, 15, neighborsTree, distancesTree); + akfn = new KFN(dataset, false, false, epsilon); + arma::Mat neighborsAprox; + arma::mat distancesAprox; + akfn->Search(dataset, 15, neighborsAprox, distancesAprox); - for (size_t i = 0; i < neighborsTree.n_elem; i++) - REQUIRE_RELATIVE_ERR(distancesTree(i), distancesNaive(i), epsilon); + for (size_t i = 0; i < neighborsAprox.n_elem; i++) + REQUIRE_RELATIVE_ERR(distancesAprox(i), distancesExact(i), epsilon); // Clean the memory. - delete kfn; + delete akfn; } } /** - * Test the dual-tree furthest-neighbors method with the naive method. This + * Test the dual-tree furthest-neighbors method with the exact method. This * uses only a reference dataset. * * Errors are produced if the results are not according to relative error. */ -BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) +BOOST_AUTO_TEST_CASE(AproxVsExact2) { arma::mat dataset; if (!data::Load("test_data_3_1000.csv", dataset)) BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); - KFN naive(dataset, true); - arma::Mat neighborsNaive; - arma::mat distancesNaive; - naive.Search(15, neighborsNaive, distancesNaive); + KFN exact(dataset); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(15, neighborsExact, distancesExact); - KFN kfn(dataset, false, false, 0.05); - arma::Mat neighborsTree; - arma::mat distancesTree; - kfn.Search(15, neighborsTree, distancesTree); + KFN akfn(dataset, false, false, 0.05); + arma::Mat neighborsAprox; + arma::mat distancesAprox; + akfn.Search(15, neighborsAprox, distancesAprox); - for (size_t i = 0; i < neighborsTree.n_elem; i++) - REQUIRE_RELATIVE_ERR(distancesTree[i], distancesNaive[i], 0.05); + for (size_t i = 0; i < neighborsAprox.n_elem; i++) + REQUIRE_RELATIVE_ERR(distancesAprox[i], distancesExact[i], 0.05); } /** - * Test the single-tree furthest-neighbors method with the naive method. This + * Test the single-tree furthest-neighbors method with the exact method. This * uses only a reference dataset. * * Errors are produced if the results are not according to relative error. */ -BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) +BOOST_AUTO_TEST_CASE(SingleTreeVsExact) { arma::mat dataset; if (!data::Load("test_data_3_1000.csv", dataset)) BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); - KFN naive(dataset, true); - arma::Mat neighborsNaive; - arma::mat distancesNaive; - naive.Search(15, neighborsNaive, distancesNaive); + KFN exact(dataset); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(15, neighborsExact, distancesExact); - KFN kfn(dataset, false, true, 0.05); - arma::Mat neighborsTree; - arma::mat distancesTree; - kfn.Search(15, neighborsTree, distancesTree); + KFN akfn(dataset, false, true, 0.05); + arma::Mat neighborsAprox; + arma::mat distancesAprox; + akfn.Search(15, neighborsAprox, distancesAprox); - for (size_t i = 0; i < neighborsTree.n_elem; i++) - REQUIRE_RELATIVE_ERR(distancesTree[i], distancesNaive[i], 0.05); + for (size_t i = 0; i < neighborsAprox.n_elem; i++) + REQUIRE_RELATIVE_ERR(distancesAprox[i], distancesExact[i], 0.05); } /** - * Test the cover tree single-tree furthest-neighbors method against the naive + * Test the cover tree single-tree furthest-neighbors method against the exact * method. This uses only a random reference dataset. * * Errors are produced if the results are not according to relative error. */ BOOST_AUTO_TEST_CASE(SingleCoverTreeTest) { - arma::mat data; - data.randu(75, 1000); // 75 dimensional, 1000 points. + arma::mat dataset; + dataset.randu(75, 1000); // 75 dimensional, 1000 points. - KFN naive(data, true); - arma::Mat naiveNeighbors; - arma::mat naiveDistances; - naive.Search(data, 15, naiveNeighbors, naiveDistances); + KFN exact(dataset); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(dataset, 15, neighborsExact, distancesExact); StandardCoverTree, - arma::mat> tree(data); + arma::mat> tree(dataset); NeighborSearch, arma::mat, StandardCoverTree> coverTreeSearch(&tree, true, 0.05); - arma::Mat coverTreeNeighbors; - arma::mat coverTreeDistances; - coverTreeSearch.Search(data, 15, coverTreeNeighbors, coverTreeDistances); + arma::Mat neighborsCoverTree; + arma::mat distancesCoverTree; + coverTreeSearch.Search(dataset, 15, neighborsCoverTree, distancesCoverTree); - for (size_t i = 0; i < coverTreeNeighbors.n_elem; ++i) - REQUIRE_RELATIVE_ERR(coverTreeDistances[i], naiveDistances[i], 0.05); + for (size_t i = 0; i < neighborsCoverTree.n_elem; ++i) + REQUIRE_RELATIVE_ERR(distancesCoverTree[i], distancesExact[i], 0.05); } /** - * Test the cover tree dual-tree furthest neighbors method against the naive + * Test the cover tree dual-tree furthest neighbors method against the exact * method. * * Errors are produced if the results are not according to relative error. @@ -166,10 +165,10 @@ BOOST_AUTO_TEST_CASE(DualCoverTreeTest) arma::mat dataset; data::Load("test_data_3_1000.csv", dataset); - KFN naive(dataset, true); - arma::Mat naiveNeighbors; - arma::mat naiveDistances; - naive.Search(dataset, 15, naiveNeighbors, naiveDistances); + KFN exact(dataset); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(dataset, 15, neighborsExact, distancesExact); StandardCoverTree, arma::mat> referenceTree(dataset); @@ -177,43 +176,43 @@ BOOST_AUTO_TEST_CASE(DualCoverTreeTest) NeighborSearch, arma::mat, StandardCoverTree> coverTreeSearch(&referenceTree, false, 0.05); - arma::Mat coverTreeNeighbors; - arma::mat coverTreeDistances; - coverTreeSearch.Search(dataset, 15, coverTreeNeighbors, coverTreeDistances); + arma::Mat neighborsCoverTree; + arma::mat distancesCoverTree; + coverTreeSearch.Search(dataset, 15, neighborsCoverTree, distancesCoverTree); - for (size_t i = 0; i < coverTreeNeighbors.n_elem; ++i) - REQUIRE_RELATIVE_ERR(coverTreeDistances[i], naiveDistances[i], 0.05); + for (size_t i = 0; i < neighborsCoverTree.n_elem; ++i) + REQUIRE_RELATIVE_ERR(distancesCoverTree[i], distancesExact[i], 0.05); } /** - * Test the ball tree single-tree furthest-neighbors method against the naive + * Test the ball tree single-tree furthest-neighbors method against the exact * method. This uses only a random reference dataset. * * Errors are produced if the results are not according to relative error. */ BOOST_AUTO_TEST_CASE(SingleBallTreeTest) { - arma::mat data; - data.randu(75, 1000); // 75 dimensional, 1000 points. + arma::mat dataset; + dataset.randu(75, 1000); // 75 dimensional, 1000 points. - KFN naive(data, true); - arma::Mat naiveNeighbors; - arma::mat naiveDistances; - naive.Search(data, 15, naiveNeighbors, naiveDistances); + KFN exact(dataset); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(dataset, 15, neighborsExact, distancesExact); NeighborSearch - ballTreeSearch(data, false, true, 0.05); + ballTreeSearch(dataset, false, true, 0.05); - arma::Mat ballNeighbors; - arma::mat ballDistances; - ballTreeSearch.Search(data, 15, ballNeighbors, ballDistances); + arma::Mat neighborsBallTree; + arma::mat distancesBallTree; + ballTreeSearch.Search(dataset, 15, neighborsBallTree, distancesBallTree); - for (size_t i = 0; i < ballNeighbors.n_elem; ++i) - REQUIRE_RELATIVE_ERR(ballDistances(i), naiveDistances(i), 0.05); + for (size_t i = 0; i < neighborsBallTree.n_elem; ++i) + REQUIRE_RELATIVE_ERR(distancesBallTree(i), distancesExact(i), 0.05); } /** - * Test the ball tree dual-tree furthest neighbors method against the naive + * Test the ball tree dual-tree furthest neighbors method against the exact * method. * * Errors are produced if the results are not according to relative error. @@ -223,19 +222,19 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest) arma::mat dataset; data::Load("test_data_3_1000.csv", dataset); - KFN naive(dataset, true); - arma::Mat naiveNeighbors; - arma::mat naiveDistances; - naive.Search(15, naiveNeighbors, naiveDistances); + KFN exact(dataset); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(15, neighborsExact, distancesExact); NeighborSearch ballTreeSearch(dataset, false, false, 0.05); - arma::Mat ballNeighbors; - arma::mat ballDistances; - ballTreeSearch.Search(15, ballNeighbors, ballDistances); + arma::Mat neighborsBallTree; + arma::mat distancesBallTree; + ballTreeSearch.Search(15, neighborsBallTree, distancesBallTree); - for (size_t i = 0; i < ballNeighbors.n_elem; ++i) - REQUIRE_RELATIVE_ERR(ballDistances(i), naiveDistances(i), 0.05); + for (size_t i = 0; i < neighborsBallTree.n_elem; ++i) + REQUIRE_RELATIVE_ERR(distancesBallTree(i), distancesExact(i), 0.05); } BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/aknn_test.cpp b/src/mlpack/tests/aknn_test.cpp index 70abcc8c05..23c7c9fda5 100644 --- a/src/mlpack/tests/aknn_test.cpp +++ b/src/mlpack/tests/aknn_test.cpp @@ -26,21 +26,21 @@ BOOST_AUTO_TEST_SUITE(AKNNTest); * * Errors are produced if the results are not according to relative error. */ -BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) +BOOST_AUTO_TEST_CASE(AproxVsExact1) { arma::mat dataset; if (!data::Load("test_data_3_1000.csv", dataset)) BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); - KNN naive(dataset, true); - arma::Mat neighborsNaive; - arma::mat distancesNaive; - naive.Search(dataset, 15, neighborsNaive, distancesNaive); + KNN exact(dataset); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(dataset, 15, neighborsExact, distancesExact); for (size_t c = 0; c < 4; c++) { - KNN* knn; + KNN* aknn; double epsilon; switch (c) @@ -59,107 +59,106 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) break; } - knn = new KNN(dataset, false, false, epsilon); - // Now perform the actual calculation. - arma::Mat neighborsTree; - arma::mat distancesTree; - knn->Search(dataset, 15, neighborsTree, distancesTree); + aknn = new KNN(dataset, false, false, epsilon); + arma::Mat neighborsAprox; + arma::mat distancesAprox; + aknn->Search(dataset, 15, neighborsAprox, distancesAprox); - for (size_t i = 0; i < neighborsTree.n_elem; i++) - REQUIRE_RELATIVE_ERR(distancesTree(i), distancesNaive(i), epsilon); + for (size_t i = 0; i < neighborsAprox.n_elem; i++) + REQUIRE_RELATIVE_ERR(distancesAprox(i), distancesExact(i), epsilon); // Clean the memory. - delete knn; + delete aknn; } } /** - * Test the dual-tree nearest-neighbors method with the naive method. This uses + * Test the dual-tree nearest-neighbors method with the exact method. This uses * only a reference dataset. * * Errors are produced if the results are not according to relative error. */ -BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) +BOOST_AUTO_TEST_CASE(AproxVsExact2) { arma::mat dataset; if (!data::Load("test_data_3_1000.csv", dataset)) BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); - KNN naive(dataset, true); - arma::Mat neighborsNaive; - arma::mat distancesNaive; - naive.Search(15, neighborsNaive, distancesNaive); + KNN exact(dataset); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(15, neighborsExact, distancesExact); - KNN knn(dataset, false, false, 0.05); - arma::Mat neighborsTree; - arma::mat distancesTree; - knn.Search(15, neighborsTree, distancesTree); + KNN aknn(dataset, false, false, 0.05); + arma::Mat neighborsAprox; + arma::mat distancesAprox; + aknn.Search(15, neighborsAprox, distancesAprox); - for (size_t i = 0; i < neighborsTree.n_elem; i++) - REQUIRE_RELATIVE_ERR(distancesTree(i), distancesNaive(i), 0.05); + for (size_t i = 0; i < neighborsAprox.n_elem; i++) + REQUIRE_RELATIVE_ERR(distancesAprox(i), distancesExact(i), 0.05); } /** - * Test the single-tree nearest-neighbors method with the naive method. This + * Test the single-tree nearest-neighbors method with the exact method. This * uses only a reference dataset. * * Errors are produced if the results are not according to relative error. */ -BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) +BOOST_AUTO_TEST_CASE(SingleTreeAproxVsExact) { arma::mat dataset; if (!data::Load("test_data_3_1000.csv", dataset)) BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); - KNN naive(dataset, true); - arma::Mat neighborsNaive; - arma::mat distancesNaive; - naive.Search(15, neighborsNaive, distancesNaive); + KNN exact(dataset); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(15, neighborsExact, distancesExact); - KNN knn(dataset, false, true, 0.05); - arma::Mat neighborsTree; - arma::mat distancesTree; - knn.Search(15, neighborsTree, distancesTree); + KNN aknn(dataset, false, true, 0.05); + arma::Mat neighborsAprox; + arma::mat distancesAprox; + aknn.Search(15, neighborsAprox, distancesAprox); - for (size_t i = 0; i < neighborsTree.n_elem; i++) - REQUIRE_RELATIVE_ERR(distancesTree[i], distancesNaive[i], 0.05); + for (size_t i = 0; i < neighborsAprox.n_elem; i++) + REQUIRE_RELATIVE_ERR(distancesAprox[i], distancesExact[i], 0.05); } /** - * Test the cover tree single-tree nearest-neighbors method against the naive + * Test the cover tree single-tree nearest-neighbors method against the exact * method. This uses only a random reference dataset. * * Errors are produced if the results are not according to relative error. */ BOOST_AUTO_TEST_CASE(SingleCoverTreeTest) { - arma::mat data; - data.randu(75, 1000); // 75 dimensional, 1000 points. + arma::mat dataset; + dataset.randu(75, 1000); // 75 dimensional, 1000 points. - KNN naive(data, true); - arma::Mat naiveNeighbors; - arma::mat naiveDistances; - naive.Search(data, 15, naiveNeighbors, naiveDistances); + KNN exact(dataset); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(dataset, 15, neighborsExact, distancesExact); StandardCoverTree, - arma::mat> tree(data); + arma::mat> tree(dataset); NeighborSearch, arma::mat, StandardCoverTree> coverTreeSearch(&tree, true, 0.05); - arma::Mat coverTreeNeighbors; - arma::mat coverTreeDistances; - coverTreeSearch.Search(data, 15, coverTreeNeighbors, coverTreeDistances); + arma::Mat neighborsCoverTree; + arma::mat distancesCoverTree; + coverTreeSearch.Search(dataset, 15, neighborsCoverTree, distancesCoverTree); - for (size_t i = 0; i < coverTreeNeighbors.n_elem; ++i) - REQUIRE_RELATIVE_ERR(coverTreeDistances[i], naiveDistances[i], 0.05); + for (size_t i = 0; i < neighborsCoverTree.n_elem; ++i) + REQUIRE_RELATIVE_ERR(distancesCoverTree[i], distancesExact[i], 0.05); } /** - * Test the cover tree dual-tree nearest neighbors method against the naive + * Test the cover tree dual-tree nearest neighbors method against the exact * method. * * Errors are produced if the results are not according to relative error. @@ -169,10 +168,10 @@ BOOST_AUTO_TEST_CASE(DualCoverTreeTest) arma::mat dataset; data::Load("test_data_3_1000.csv", dataset); - KNN naive(dataset, true); - arma::Mat naiveNeighbors; - arma::mat naiveDistances; - naive.Search(dataset, 15, naiveNeighbors, naiveDistances); + KNN exact(dataset); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(dataset, 15, neighborsExact, distancesExact); StandardCoverTree, arma::mat> referenceTree(dataset); @@ -180,43 +179,44 @@ BOOST_AUTO_TEST_CASE(DualCoverTreeTest) NeighborSearch coverTreeSearch(&referenceTree, false, 0.05); - arma::Mat coverNeighbors; - arma::mat coverDistances; - coverTreeSearch.Search(&referenceTree, 15, coverNeighbors, coverDistances); + arma::Mat neighborsCoverTree; + arma::mat distancesCoverTree; + coverTreeSearch.Search(&referenceTree, 15, neighborsCoverTree, + distancesCoverTree); - for (size_t i = 0; i < coverNeighbors.n_elem; ++i) - REQUIRE_RELATIVE_ERR(coverDistances[i], naiveDistances[i], 0.05); + for (size_t i = 0; i < neighborsCoverTree.n_elem; ++i) + REQUIRE_RELATIVE_ERR(distancesCoverTree[i], distancesExact[i], 0.05); } /** - * Test the ball tree single-tree nearest-neighbors method against the naive + * Test the ball tree single-tree nearest-neighbors method against the exact * method. This uses only a random reference dataset. * * Errors are produced if the results are not according to relative error. */ BOOST_AUTO_TEST_CASE(SingleBallTreeTest) { - arma::mat data; - data.randu(50, 300); // 50 dimensional, 300 points. + arma::mat dataset; + dataset.randu(50, 300); // 50 dimensional, 300 points. - KNN naive(data, true); - arma::Mat naiveNeighbors; - arma::mat naiveDistances; - naive.Search(data, 15, naiveNeighbors, naiveDistances); + KNN exact(dataset); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(dataset, 15, neighborsExact, distancesExact); NeighborSearch - ballTreeSearch(data, false, true, 0.05); + ballTreeSearch(dataset, false, true, 0.05); - arma::Mat ballNeighbors; - arma::mat ballDistances; - ballTreeSearch.Search(data, 15, ballNeighbors, ballDistances); + arma::Mat neighborsBallTree; + arma::mat distancesBallTree; + ballTreeSearch.Search(dataset, 15, neighborsBallTree, distancesBallTree); - for (size_t i = 0; i < ballNeighbors.n_elem; ++i) - REQUIRE_RELATIVE_ERR(ballDistances(i), naiveDistances(i), 0.05); + for (size_t i = 0; i < neighborsBallTree.n_elem; ++i) + REQUIRE_RELATIVE_ERR(distancesBallTree(i), distancesExact(i), 0.05); } /** - * Test the ball tree dual-tree nearest neighbors method against the naive + * Test the ball tree dual-tree nearest neighbors method against the exact * method. * * Errors are produced if the results are not according to relative error. @@ -226,19 +226,19 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest) arma::mat dataset; data::Load("test_data_3_1000.csv", dataset); - KNN naive(dataset, true); - arma::Mat naiveNeighbors; - arma::mat naiveDistances; - naive.Search(15, naiveNeighbors, naiveDistances); + KNN exact(dataset); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(15, neighborsExact, distancesExact); NeighborSearch ballTreeSearch(dataset, false, false, 0.05); - arma::Mat ballNeighbors; - arma::mat ballDistances; - ballTreeSearch.Search(15, ballNeighbors, ballDistances); + arma::Mat neighborsBallTree; + arma::mat distancesBallTree; + ballTreeSearch.Search(15, neighborsBallTree, distancesBallTree); - for (size_t i = 0; i < ballNeighbors.n_elem; ++i) - REQUIRE_RELATIVE_ERR(ballDistances(i), naiveDistances(i), 0.05); + for (size_t i = 0; i < neighborsBallTree.n_elem; ++i) + REQUIRE_RELATIVE_ERR(distancesBallTree(i), distancesExact(i), 0.05); } /** @@ -260,20 +260,19 @@ BOOST_AUTO_TEST_CASE(SparseKNNKDTreeTest) typedef NeighborSearch SparseKNN; - SparseKNN a(referenceDataset, false, false, 0.05); - KNN naive(denseReference, true); + SparseKNN aknn(referenceDataset, false, false, 0.05); + arma::mat distancesSparse; + arma::Mat neighborsSparse; + aknn.Search(queryDataset, 10, neighborsSparse, distancesSparse); - arma::mat sparseDistances; - arma::Mat sparseNeighbors; - a.Search(queryDataset, 10, sparseNeighbors, sparseDistances); + KNN exact(denseReference); + arma::mat distancesExact; + arma::Mat neighborsExact; + exact.Search(denseQuery, 10, neighborsExact, distancesExact); - arma::mat naiveDistances; - arma::Mat naiveNeighbors; - naive.Search(denseQuery, 10, naiveNeighbors, naiveDistances); - - for (size_t i = 0; i < naiveNeighbors.n_cols; ++i) - for (size_t j = 0; j < naiveNeighbors.n_rows; ++j) - REQUIRE_RELATIVE_ERR(sparseDistances(j, i), naiveDistances(j, i), 0.05); + for (size_t i = 0; i < neighborsExact.n_cols; ++i) + for (size_t j = 0; j < neighborsExact.n_rows; ++j) + REQUIRE_RELATIVE_ERR(distancesSparse(j, i), distancesExact(j, i), 0.05); } /** @@ -305,10 +304,10 @@ BOOST_AUTO_TEST_CASE(KNNModelTest) for (size_t j = 0; j < 3; ++j) { // Get a baseline. - KNN knn(referenceData); - arma::Mat baselineNeighbors; - arma::mat baselineDistances; - knn.Search(queryData, 3, baselineNeighbors, baselineDistances); + KNN aknn(referenceData); + arma::Mat neighborsExact; + arma::mat distancesExact; + aknn.Search(queryData, 3, neighborsExact, distancesExact); for (size_t i = 0; i < 12; ++i) { @@ -322,19 +321,19 @@ BOOST_AUTO_TEST_CASE(KNNModelTest) if (j == 2) models[i].BuildModel(std::move(referenceCopy), 20, true, false); - arma::Mat neighbors; - arma::mat distances; + arma::Mat neighborsAprox; + arma::mat distancesAprox; - models[i].Search(std::move(queryCopy), 3, neighbors, distances); + models[i].Search(std::move(queryCopy), 3, neighborsAprox, distancesAprox); - BOOST_REQUIRE_EQUAL(neighbors.n_rows, baselineNeighbors.n_rows); - BOOST_REQUIRE_EQUAL(neighbors.n_cols, baselineNeighbors.n_cols); - BOOST_REQUIRE_EQUAL(neighbors.n_elem, baselineNeighbors.n_elem); - BOOST_REQUIRE_EQUAL(distances.n_rows, baselineDistances.n_rows); - BOOST_REQUIRE_EQUAL(distances.n_cols, baselineDistances.n_cols); - BOOST_REQUIRE_EQUAL(distances.n_elem, baselineDistances.n_elem); - for (size_t k = 0; k < distances.n_elem; ++k) - REQUIRE_RELATIVE_ERR(distances[k], baselineDistances[k], 0.05); + BOOST_REQUIRE_EQUAL(neighborsAprox.n_rows, neighborsExact.n_rows); + BOOST_REQUIRE_EQUAL(neighborsAprox.n_cols, neighborsExact.n_cols); + BOOST_REQUIRE_EQUAL(neighborsAprox.n_elem, neighborsExact.n_elem); + BOOST_REQUIRE_EQUAL(distancesAprox.n_rows, distancesExact.n_rows); + BOOST_REQUIRE_EQUAL(distancesAprox.n_cols, distancesExact.n_cols); + BOOST_REQUIRE_EQUAL(distancesAprox.n_elem, distancesExact.n_elem); + for (size_t k = 0; k < distancesAprox.n_elem; ++k) + REQUIRE_RELATIVE_ERR(distancesAprox[k], distancesExact[k], 0.05); } } } @@ -364,13 +363,13 @@ BOOST_AUTO_TEST_CASE(KNNModelMonochromaticTest) models[10] = KNNModel(KNNModel::TreeTypes::BALL_TREE, true); models[11] = KNNModel(KNNModel::TreeTypes::BALL_TREE, false); - for (size_t j = 0; j < 3; ++j) + for (size_t j = 0; j < 2; ++j) { // Get a baseline. - KNN knn(referenceData); - arma::Mat baselineNeighbors; - arma::mat baselineDistances; - knn.Search(3, baselineNeighbors, baselineDistances); + KNN exact(referenceData); + arma::Mat neighborsExact; + arma::mat distancesExact; + exact.Search(3, neighborsExact, distancesExact); for (size_t i = 0; i < 12; ++i) { @@ -380,22 +379,20 @@ BOOST_AUTO_TEST_CASE(KNNModelMonochromaticTest) models[i].BuildModel(std::move(referenceCopy), 20, false, false, 0.05); if (j == 1) models[i].BuildModel(std::move(referenceCopy), 20, false, true, 0.05); - if (j == 2) - models[i].BuildModel(std::move(referenceCopy), 20, true, false); - arma::Mat neighbors; - arma::mat distances; + arma::Mat neighborsAprox; + arma::mat distancesAprox; - models[i].Search(3, neighbors, distances); + models[i].Search(3, neighborsAprox, distancesAprox); - BOOST_REQUIRE_EQUAL(neighbors.n_rows, baselineNeighbors.n_rows); - BOOST_REQUIRE_EQUAL(neighbors.n_cols, baselineNeighbors.n_cols); - BOOST_REQUIRE_EQUAL(neighbors.n_elem, baselineNeighbors.n_elem); - BOOST_REQUIRE_EQUAL(distances.n_rows, baselineDistances.n_rows); - BOOST_REQUIRE_EQUAL(distances.n_cols, baselineDistances.n_cols); - BOOST_REQUIRE_EQUAL(distances.n_elem, baselineDistances.n_elem); - for (size_t k = 0; k < distances.n_elem; ++k) - REQUIRE_RELATIVE_ERR(distances[k], baselineDistances[k], 0.05); + BOOST_REQUIRE_EQUAL(neighborsAprox.n_rows, neighborsExact.n_rows); + BOOST_REQUIRE_EQUAL(neighborsAprox.n_cols, neighborsExact.n_cols); + BOOST_REQUIRE_EQUAL(neighborsAprox.n_elem, neighborsExact.n_elem); + BOOST_REQUIRE_EQUAL(distancesAprox.n_rows, distancesExact.n_rows); + BOOST_REQUIRE_EQUAL(distancesAprox.n_cols, distancesExact.n_cols); + BOOST_REQUIRE_EQUAL(distancesAprox.n_elem, distancesExact.n_elem); + for (size_t k = 0; k < distancesAprox.n_elem; ++k) + REQUIRE_RELATIVE_ERR(distancesAprox[k], distancesExact[k], 0.05); } } } From 74648fa7f17cbe70f4215f5c6c93efbc1d3553a1 Mon Sep 17 00:00:00 2001 From: MarcosPividori Date: Mon, 13 Jun 2016 15:19:51 -0300 Subject: [PATCH 09/13] Replace epsilon by percentage in kfn. --- .../methods/neighbor_search/kfn_main.cpp | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/mlpack/methods/neighbor_search/kfn_main.cpp b/src/mlpack/methods/neighbor_search/kfn_main.cpp index a2fbf2eba9..3a4e4b7dd2 100644 --- a/src/mlpack/methods/neighbor_search/kfn_main.cpp +++ b/src/mlpack/methods/neighbor_search/kfn_main.cpp @@ -72,8 +72,10 @@ 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.", "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.", + "p", 1); // Convenience typedef. typedef NSModel KFNModel; @@ -140,11 +142,11 @@ int main(int argc, char *argv[]) Log::Fatal << "Invalid leaf size: " << lsInt << ". Must be greater than 0." << endl; - // Sanity check on epsilon. - const double epsilon = CLI::GetParam("epsilon"); - if (epsilon < 0) - Log::Fatal << "Invalid epsilon: " << epsilon << ". Must be non-negative. " - << endl; + // Sanity check on percentage. + const double percentage = CLI::GetParam("percentage"); + if (percentage <= 0 || percentage > 1) + Log::Fatal << "Invalid percentage: " << percentage + << ". Must be in the range (0,1] (decimal form)."<< endl; // We either have to load the reference data, or we have to load the model. NSModel kfn; @@ -184,7 +186,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, - epsilon); + 1 - percentage); } else { @@ -200,7 +202,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() = epsilon; + kfn.Epsilon() = 1 - percentage; } // Perform search, if desired. From 7f68a278d9a69de9d0564cea6d54c7db8c95a49a Mon Sep 17 00:00:00 2001 From: MarcosPividori Date: Tue, 14 Jun 2016 10:57:57 -0300 Subject: [PATCH 10/13] Add epsilon for kfn (both epsilon and percentage). --- .../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 3a4e4b7dd2..163e8ed741 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("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("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 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. From 7f4dfd005a8aa71afa703012ab613a3afc08785a Mon Sep 17 00:00:00 2001 From: MarcosPividori Date: Tue, 14 Jun 2016 11:44:18 -0300 Subject: [PATCH 11/13] Use absolute value when considering relative error. --- src/mlpack/tests/test_tools.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/tests/test_tools.hpp b/src/mlpack/tests/test_tools.hpp index 2d4e56e235..77fd1c189b 100644 --- a/src/mlpack/tests/test_tools.hpp +++ b/src/mlpack/tests/test_tools.hpp @@ -37,6 +37,6 @@ // Require the approximation L to be within a relative error of E respect to the // actual value R. #define REQUIRE_RELATIVE_ERR( L, R, E ) \ - BOOST_REQUIRE_LE( abs((R) - (L)), (E) * (R)) + BOOST_REQUIRE_LE( abs((R) - (L)), (E) * abs(R)) #endif From 49822ef4179f31123e1e7e27be40d76f8e0804e0 Mon Sep 17 00:00:00 2001 From: MarcosPividori Date: Wed, 22 Jun 2016 12:44:37 -0300 Subject: [PATCH 12/13] Improve log message. --- .../methods/neighbor_search/ns_model_impl.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mlpack/methods/neighbor_search/ns_model_impl.hpp b/src/mlpack/methods/neighbor_search/ns_model_impl.hpp index 0a705626a6..075306bece 100644 --- a/src/mlpack/methods/neighbor_search/ns_model_impl.hpp +++ b/src/mlpack/methods/neighbor_search/ns_model_impl.hpp @@ -414,16 +414,16 @@ void NSModel::Search(arma::mat&& querySet, if (randomBasis) querySet = q * querySet; - Log::Info << "Searching for " << k; - if (Epsilon() != 0) - Log::Info << " approximate (e=" << Epsilon() << ")"; - Log::Info << " neighbors with "; + Log::Info << "Searching for " << k << " neighbors with "; if (!Naive() && !SingleMode()) Log::Info << "dual-tree " << TreeName() << " search..." << std::endl; else if (!Naive()) Log::Info << "single-tree " << TreeName() << " search..." << std::endl; else Log::Info << "brute-force (naive) search..." << std::endl; + if (Epsilon() != 0 && !Naive()) + Log::Info << "Maximum of " << Epsilon() * 100 << "% relative error." + << std::endl; BiSearchVisitor search(querySet, k, neighbors, distances, leafSize); @@ -436,16 +436,16 @@ void NSModel::Search(const size_t k, arma::Mat& neighbors, arma::mat& distances) { - Log::Info << "Searching for " << k; - if (Epsilon() != 0) - Log::Info << " approximate (e=" << Epsilon() << ")"; - Log::Info << " neighbors with "; + Log::Info << "Searching for " << k << " neighbors with "; if (!Naive() && !SingleMode()) Log::Info << "dual-tree " << TreeName() << " search..." << std::endl; else if (!Naive()) Log::Info << "single-tree " << TreeName() << " search..." << std::endl; else Log::Info << "brute-force (naive) search..." << std::endl; + if (Epsilon() != 0 && !Naive()) + Log::Info << "Maximum of " << Epsilon() * 100 << "% relative error." + << std::endl; MonoSearchVisitor search(k, neighbors, distances); boost::apply_visitor(search, nSearch); From fd33fd5ca64fb9f6a82168dc259e66fcec55ae4b Mon Sep 17 00:00:00 2001 From: MarcosPividori Date: Wed, 22 Jun 2016 14:33:26 -0300 Subject: [PATCH 13/13] Move constructor to header, to avoid linking problems (MonoSearchVisitor is not a template class). --- src/mlpack/methods/neighbor_search/ns_model.hpp | 6 +++++- src/mlpack/methods/neighbor_search/ns_model_impl.hpp | 9 --------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/mlpack/methods/neighbor_search/ns_model.hpp b/src/mlpack/methods/neighbor_search/ns_model.hpp index db3331a3e4..711d640703 100644 --- a/src/mlpack/methods/neighbor_search/ns_model.hpp +++ b/src/mlpack/methods/neighbor_search/ns_model.hpp @@ -69,7 +69,11 @@ class MonoSearchVisitor : public boost::static_visitor MonoSearchVisitor(const size_t k, arma::Mat& neighbors, - arma::mat& distances); + arma::mat& distances) : + k(k), + neighbors(neighbors), + distances(distances) + {}; }; /** diff --git a/src/mlpack/methods/neighbor_search/ns_model_impl.hpp b/src/mlpack/methods/neighbor_search/ns_model_impl.hpp index 075306bece..da8ab07f98 100644 --- a/src/mlpack/methods/neighbor_search/ns_model_impl.hpp +++ b/src/mlpack/methods/neighbor_search/ns_model_impl.hpp @@ -18,15 +18,6 @@ namespace mlpack { namespace neighbor { -//! Save parameters for monochromatic neighbor search. -MonoSearchVisitor::MonoSearchVisitor(const size_t k, - arma::Mat& neighbors, - arma::mat& distances) : - k(k), - neighbors(neighbors), - distances(distances) -{} - //! Monochromatic neighbor search on the given NSType instance. template void MonoSearchVisitor::operator()(NSType *ns) const