From 8f18aeaf6973f33efc92e7cb9fc2dd075c3f6617 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Thu, 1 Oct 2020 22:30:28 +0530 Subject: [PATCH 01/11] range_search_test to catch2 --- src/mlpack/tests/CMakeLists.txt | 4 +- src/mlpack/tests/range_search_test.cpp | 835 ++++++++++++------------- 2 files changed, 418 insertions(+), 421 deletions(-) diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index ce9ef730da..483f650a25 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -55,7 +55,6 @@ add_executable(mlpack_test radical_test.cpp random_forest_test.cpp random_test.cpp - range_search_test.cpp rectangle_tree_test.cpp reward_clipping_test.cpp rl_components_test.cpp @@ -105,7 +104,6 @@ add_executable(mlpack_test main_tests/perceptron_test.cpp main_tests/radical_test.cpp main_tests/random_forest_test.cpp - main_tests/range_search_test.cpp main_tests/test_helper.hpp ) @@ -146,6 +144,7 @@ add_executable(mlpack_catch_test one_hot_encoding_test.cpp quic_svd_test.cpp randomized_svd_test.cpp + range_search_test.cpp rbm_network_test.cpp recurrent_network_test.cpp regularized_svd_test.cpp @@ -179,6 +178,7 @@ add_executable(mlpack_catch_test main_tests/preprocess_split_test.cpp main_tests/softmax_regression_test.cpp main_tests/sparse_coding_test.cpp + main_tests/range_search_test.cpp main_tests/test_helper.hpp ) diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index 33dd5c56ca..b9e3f47c1c 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -13,8 +13,9 @@ #include #include #include -#include -#include "test_tools.hpp" + +#include "catch.hpp" +#include "test_catch_tools.hpp" using namespace mlpack; using namespace mlpack::range; @@ -24,8 +25,6 @@ using namespace mlpack::bound; using namespace mlpack::metric; using namespace std; -BOOST_AUTO_TEST_SUITE(RangeSearchTest); - // Get our results into a sorted format, so we can actually then test for // correctness. void SortResults(const vector>& neighbors, @@ -62,7 +61,7 @@ void CleanTree(TreeType& node) * dataset is in one dimension for simplicity -- the correct functionality of * distance functions is not tested here. */ -BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) +TEST_CASE("ExhaustiveSyntheticTest", "[RangeSearchTest]") { // Set up our data. arma::mat data(1, 11); @@ -111,109 +110,109 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) vector>> sortedOutput; SortResults(neighbors, distances, sortedOutput); - BOOST_REQUIRE(sortedOutput[newFromOld[0]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][0].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][0].first, 0.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][1].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][1].first, 0.27, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][2].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][2].first, 0.30, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][3].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][3].first, 0.40, 1e-5); + REQUIRE(sortedOutput[newFromOld[0]].size() == 4); + REQUIRE(sortedOutput[newFromOld[0]][0].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[0]][0].first == Approx(0.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[0]][1].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[0]][1].first == Approx(0.27).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[0]][2].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[0]][2].first == Approx(0.30).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[0]][3].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[0]][3].first == Approx(0.40).epsilon(1e-7)); // Neighbors of point 1. - BOOST_REQUIRE(sortedOutput[newFromOld[1]].size() == 6); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][0].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][0].first, 0.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][1].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][1].first, 0.20, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][2].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][2].first, 0.30, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][3].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][3].first, 0.55, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][4].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][4].first, 0.57, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][5].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][5].first, 0.65, 1e-5); + REQUIRE(sortedOutput[newFromOld[1]].size() == 6); + REQUIRE(sortedOutput[newFromOld[1]][0].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[1]][0].first == Approx(0.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[1]][1].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[1]][1].first == Approx(0.20).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[1]][2].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[1]][2].first == Approx(0.30).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[1]][3].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[1]][3].first == Approx(0.55).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[1]][4].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[1]][4].first == Approx(0.57).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[1]][5].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[1]][5].first == Approx(0.65).epsilon(1e-7)); // Neighbors of point 2. - BOOST_REQUIRE(sortedOutput[newFromOld[2]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][0].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][0].first, 0.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][1].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][1].first, 0.20, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][2].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][2].first, 0.30, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][3].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][3].first, 0.37, 1e-5); + REQUIRE(sortedOutput[newFromOld[2]].size() == 4); + REQUIRE(sortedOutput[newFromOld[2]][0].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[2]][0].first == Approx(0.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[2]][1].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[2]][1].first == Approx(0.20).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[2]][2].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[2]][2].first == Approx(0.30).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[2]][3].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[2]][3].first == Approx(0.37).epsilon(1e-7)); // Neighbors of point 3. - BOOST_REQUIRE(sortedOutput[newFromOld[3]].size() == 2); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][0].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][0].first, 0.25, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][1].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][1].first, 0.35, 1e-5); + REQUIRE(sortedOutput[newFromOld[3]].size() == 2); + REQUIRE(sortedOutput[newFromOld[3]][0].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[3]][0].first == Approx(0.25).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[3]][1].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[3]][1].first == Approx(0.35).epsilon(1e-7)); // Neighbors of point 4. - BOOST_REQUIRE(sortedOutput[newFromOld[4]].size() == 0); + REQUIRE(sortedOutput[newFromOld[4]].size() == 0); // Neighbors of point 5. - BOOST_REQUIRE(sortedOutput[newFromOld[5]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][0].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][0].first, 0.27, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][1].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][1].first, 0.37, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][2].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][2].first, 0.57, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][3].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][3].first, 0.67, 1e-5); + REQUIRE(sortedOutput[newFromOld[5]].size() == 4); + REQUIRE(sortedOutput[newFromOld[5]][0].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[5]][0].first == Approx(0.27).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][1].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[5]][1].first == Approx(0.37).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][2].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[5]][2].first == Approx(0.57).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][3].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[5]][3].first == Approx(0.67).epsilon(1e-7)); // Neighbors of point 6. - BOOST_REQUIRE(sortedOutput[newFromOld[6]].size() == 1); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][0].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][0].first, 0.70, 1e-5); + REQUIRE(sortedOutput[newFromOld[6]].size() == 1); + REQUIRE(sortedOutput[newFromOld[6]][0].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[6]][0].first == Approx(0.70).epsilon(1e-7)); // Neighbors of point 7. - BOOST_REQUIRE(sortedOutput[newFromOld[7]].size() == 1); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][0].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][0].first, 0.70, 1e-5); + REQUIRE(sortedOutput[newFromOld[7]].size() == 1); + REQUIRE(sortedOutput[newFromOld[7]][0].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[7]][0].first == Approx(0.70).epsilon(1e-7)); // Neighbors of point 8. - BOOST_REQUIRE(sortedOutput[newFromOld[8]].size() == 6); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][0].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][0].first, 0.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][1].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][1].first, 0.30, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][2].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][2].first, 0.40, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][3].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][3].first, 0.45, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][4].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][4].first, 0.55, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][5].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][5].first, 0.67, 1e-5); + REQUIRE(sortedOutput[newFromOld[8]].size() == 6); + REQUIRE(sortedOutput[newFromOld[8]][0].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[8]][0].first == Approx(0.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[8]][1].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[8]][1].first == Approx(0.30).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[8]][2].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[8]][2].first == Approx(0.40).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[8]][3].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[8]][3].first == Approx(0.45).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[8]][4].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[8]][4].first == Approx(0.55).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[8]][5].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[8]][5].first == Approx(0.67).epsilon(1e-7)); // Neighbors of point 9. - BOOST_REQUIRE(sortedOutput[newFromOld[9]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][0].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][0].first, 0.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][1].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][1].first, 0.35, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][2].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][2].first, 0.45, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][3].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][3].first, 0.55, 1e-5); + REQUIRE(sortedOutput[newFromOld[9]].size() == 4); + REQUIRE(sortedOutput[newFromOld[9]][0].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[9]][0].first == Approx(0.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[9]][1].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[9]][1].first == Approx(0.35).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[9]][2].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[9]][2].first == Approx(0.45).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[9]][3].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[9]][3].first == Approx(0.55).epsilon(1e-7)); // Neighbors of point 10. - BOOST_REQUIRE(sortedOutput[newFromOld[10]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][0].first, 0.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][1].first, 0.25, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][2].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][2].first, 0.55, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][3].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][3].first, 0.65, 1e-5); + REQUIRE(sortedOutput[newFromOld[10]].size() == 4); + REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[10]][0].first == Approx(0.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[10]][1].first == Approx(0.25).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][2].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[10]][2].first == Approx(0.55).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][3].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[10]][3].first == Approx(0.65).epsilon(1e-7)); // Now do it again with a different range: [sqrt(0.5) 1.0]. if (rs->ReferenceTree()) @@ -222,61 +221,61 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) SortResults(neighbors, distances, sortedOutput); // Neighbors of point 0. - BOOST_REQUIRE(sortedOutput[newFromOld[0]].size() == 2); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][0].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][0].first, 0.85, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][1].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][1].first, 0.95, 1e-5); + REQUIRE(sortedOutput[newFromOld[0]].size() == 2); + REQUIRE(sortedOutput[newFromOld[0]][0].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[0]][0].first == Approx(0.85).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[0]][1].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[0]][1].first == Approx(0.95).epsilon(1e-7)); // Neighbors of point 1. - BOOST_REQUIRE(sortedOutput[newFromOld[1]].size() == 1); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][0].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][0].first, 0.90, 1e-5); + REQUIRE(sortedOutput[newFromOld[1]].size() == 1); + REQUIRE(sortedOutput[newFromOld[1]][0].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[1]][0].first == Approx(0.90).epsilon(1e-7)); // Neighbors of point 2. - BOOST_REQUIRE(sortedOutput[newFromOld[2]].size() == 2); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][0].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][0].first, 0.75, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][1].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][1].first, 0.85, 1e-5); + REQUIRE(sortedOutput[newFromOld[2]].size() == 2); + REQUIRE(sortedOutput[newFromOld[2]][0].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[2]][0].first == Approx(0.75).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[2]][1].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[2]][1].first == Approx(0.85).epsilon(1e-7)); // Neighbors of point 3. - BOOST_REQUIRE(sortedOutput[newFromOld[3]].size() == 2); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][0].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][0].first, 0.80, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][1].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][1].first, 0.90, 1e-5); + REQUIRE(sortedOutput[newFromOld[3]].size() == 2); + REQUIRE(sortedOutput[newFromOld[3]][0].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[3]][0].first == Approx(0.80).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[3]][1].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[3]][1].first == Approx(0.90).epsilon(1e-7)); // Neighbors of point 4. - BOOST_REQUIRE(sortedOutput[newFromOld[4]].size() == 0); + REQUIRE(sortedOutput[newFromOld[4]].size() == 0); // Neighbors of point 5. - BOOST_REQUIRE(sortedOutput[newFromOld[5]].size() == 0); + REQUIRE(sortedOutput[newFromOld[5]].size() == 0); // Neighbors of point 6. - BOOST_REQUIRE(sortedOutput[newFromOld[6]].size() == 0); + REQUIRE(sortedOutput[newFromOld[6]].size() == 0); // Neighbors of point 7. - BOOST_REQUIRE(sortedOutput[newFromOld[7]].size() == 0); + REQUIRE(sortedOutput[newFromOld[7]].size() == 0); // Neighbors of point 8. - BOOST_REQUIRE(sortedOutput[newFromOld[8]].size() == 1); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][0].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][0].first, 0.80, 1e-5); + REQUIRE(sortedOutput[newFromOld[8]].size() == 1); + REQUIRE(sortedOutput[newFromOld[8]][0].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[8]][0].first == Approx(0.80).epsilon(1e-7)); // Neighbors of point 9. - BOOST_REQUIRE(sortedOutput[newFromOld[9]].size() == 2); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][0].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][0].first, 0.75, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][1].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][1].first, 0.85, 1e-5); + REQUIRE(sortedOutput[newFromOld[9]].size() == 2); + REQUIRE(sortedOutput[newFromOld[9]][0].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[9]][0].first == Approx(0.75).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[9]][1].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[9]][1].first == Approx(0.85).epsilon(1e-7)); // Neighbors of point 10. - BOOST_REQUIRE(sortedOutput[newFromOld[10]].size() == 2); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][0].first, 0.85, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][1].first, 0.95, 1e-5); + REQUIRE(sortedOutput[newFromOld[10]].size() == 2); + REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[10]][0].first == Approx(0.85).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[10]][1].first == Approx(0.95).epsilon(1e-7)); // Now do it again with a different range: [1.0 inf]. if (rs->ReferenceTree()) @@ -286,161 +285,161 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) SortResults(neighbors, distances, sortedOutput); // Neighbors of point 0. - BOOST_REQUIRE(sortedOutput[newFromOld[0]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][0].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][0].first, 1.20, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][1].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][1].first, 1.35, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][2].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][2].first, 2.05, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[0]][3].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[0]][3].first, 5.00, 1e-5); + REQUIRE(sortedOutput[newFromOld[0]].size() == 4); + REQUIRE(sortedOutput[newFromOld[0]][0].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[0]][0].first == Approx(1.20).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[0]][1].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[0]][1].first == Approx(1.35).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[0]][2].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[0]][2].first == Approx(2.05).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[0]][3].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[0]][3].first == Approx(5.00).epsilon(1e-7)); // Neighbors of point 1. - BOOST_REQUIRE(sortedOutput[newFromOld[1]].size() == 3); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][0].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][0].first, 1.65, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][1].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][1].first, 2.35, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[1]][2].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[1]][2].first, 4.70, 1e-5); + REQUIRE(sortedOutput[newFromOld[1]].size() == 3); + REQUIRE(sortedOutput[newFromOld[1]][0].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[1]][0].first == Approx(1.65).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[1]][1].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[1]][1].first == Approx(2.35).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[1]][2].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[1]][2].first == Approx(4.70).epsilon(1e-7)); // Neighbors of point 2. - BOOST_REQUIRE(sortedOutput[newFromOld[2]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][0].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][0].first, 1.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][1].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][1].first, 1.45, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][2].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][2].first, 2.15, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[2]][3].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[2]][3].first, 4.90, 1e-5); + REQUIRE(sortedOutput[newFromOld[2]].size() == 4); + REQUIRE(sortedOutput[newFromOld[2]][0].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[2]][0].first == Approx(1.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[2]][1].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[2]][1].first == Approx(1.45).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[2]][2].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[2]][2].first == Approx(2.15).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[2]][3].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[2]][3].first == Approx(4.90).epsilon(1e-7)); // Neighbors of point 3. - BOOST_REQUIRE(sortedOutput[newFromOld[3]].size() == 6); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][0].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][0].first, 1.10, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][1].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][1].first, 1.20, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][2].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][2].first, 1.47, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][3].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][3].first, 2.55, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][4].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][4].first, 3.25, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[3]][5].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[3]][5].first, 3.80, 1e-5); + REQUIRE(sortedOutput[newFromOld[3]].size() == 6); + REQUIRE(sortedOutput[newFromOld[3]][0].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[3]][0].first == Approx(1.10).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[3]][1].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[3]][1].first == Approx(1.20).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[3]][2].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[3]][2].first == Approx(1.47).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[3]][3].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[3]][3].first == Approx(2.55).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[3]][4].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[3]][4].first == Approx(3.25).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[3]][5].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[3]][5].first == Approx(3.80).epsilon(1e-7)); // Neighbors of point 4. - BOOST_REQUIRE(sortedOutput[newFromOld[4]].size() == 10); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][0].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][0].first, 3.80, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][1].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][1].first, 4.05, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][2].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][2].first, 4.15, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][3].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][3].first, 4.60, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][4].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][4].first, 4.70, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][5].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][5].first, 4.90, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][6].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][6].first, 5.00, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][7].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][7].first, 5.27, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][8].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][8].first, 6.35, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[4]][9].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[4]][9].first, 7.05, 1e-5); + REQUIRE(sortedOutput[newFromOld[4]].size() == 10); + REQUIRE(sortedOutput[newFromOld[4]][0].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[4]][0].first == Approx(3.80).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][1].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[4]][1].first == Approx(4.05).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][2].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[4]][2].first == Approx(4.15).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][3].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[4]][3].first == Approx(4.60).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][4].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[4]][4].first == Approx(4.70).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][5].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[4]][5].first == Approx(4.90).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][6].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[4]][6].first == Approx(5.00).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][7].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[4]][7].first == Approx(5.27).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][8].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[4]][8].first == Approx(6.35).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[4]][9].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[4]][9].first == Approx(7.05).epsilon(1e-7)); // Neighbors of point 5. - BOOST_REQUIRE(sortedOutput[newFromOld[5]].size() == 6); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][0].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][0].first, 1.08, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][1].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][1].first, 1.12, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][2].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][2].first, 1.22, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][3].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][3].first, 1.47, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][4].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][4].first, 1.78, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[5]][5].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[5]][5].first, 5.27, 1e-5); + REQUIRE(sortedOutput[newFromOld[5]].size() == 6); + REQUIRE(sortedOutput[newFromOld[5]][0].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[5]][0].first == Approx(1.08).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][1].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[5]][1].first == Approx(1.12).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][2].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[5]][2].first == Approx(1.22).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][3].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[5]][3].first == Approx(1.47).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][4].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[5]][4].first == Approx(1.78).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[5]][5].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[5]][5].first == Approx(5.27).epsilon(1e-7)); // Neighbors of point 6. - BOOST_REQUIRE(sortedOutput[newFromOld[6]].size() == 9); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][0].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][0].first, 1.78, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][1].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][1].first, 2.05, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][2].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][2].first, 2.15, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][3].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][3].first, 2.35, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][4].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][4].first, 2.45, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][5].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][5].first, 2.90, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][6].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][6].first, 3.00, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][7].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][7].first, 3.25, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[6]][8].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[6]][8].first, 7.05, 1e-5); + REQUIRE(sortedOutput[newFromOld[6]].size() == 9); + REQUIRE(sortedOutput[newFromOld[6]][0].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[6]][0].first == Approx(1.78).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][1].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[6]][1].first == Approx(2.05).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][2].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[6]][2].first == Approx(2.15).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][3].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[6]][3].first == Approx(2.35).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][4].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[6]][4].first == Approx(2.45).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][5].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[6]][5].first == Approx(2.90).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][6].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[6]][6].first == Approx(3.00).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][7].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[6]][7].first == Approx(3.25).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[6]][8].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[6]][8].first == Approx(7.05).epsilon(1e-7)); // Neighbors of point 7. - BOOST_REQUIRE(sortedOutput[newFromOld[7]].size() == 9); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][0].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][0].first, 1.08, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][1].second == newFromOld[0]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][1].first, 1.35, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][2].second == newFromOld[2]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][2].first, 1.45, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][3].second == newFromOld[1]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][3].first, 1.65, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][4].second == newFromOld[8]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][4].first, 1.75, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][5].second == newFromOld[9]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][5].first, 2.20, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][6].second == newFromOld[10]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][6].first, 2.30, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][7].second == newFromOld[3]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][7].first, 2.55, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[7]][8].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[7]][8].first, 6.35, 1e-5); + REQUIRE(sortedOutput[newFromOld[7]].size() == 9); + REQUIRE(sortedOutput[newFromOld[7]][0].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[7]][0].first == Approx(1.08).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][1].second == newFromOld[0]); + REQUIRE(sortedOutput[newFromOld[7]][1].first == Approx(1.35).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][2].second == newFromOld[2]); + REQUIRE(sortedOutput[newFromOld[7]][2].first == Approx(1.45).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][3].second == newFromOld[1]); + REQUIRE(sortedOutput[newFromOld[7]][3].first == Approx(1.65).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][4].second == newFromOld[8]); + REQUIRE(sortedOutput[newFromOld[7]][4].first == Approx(1.75).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][5].second == newFromOld[9]); + REQUIRE(sortedOutput[newFromOld[7]][5].first == Approx(2.20).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][6].second == newFromOld[10]); + REQUIRE(sortedOutput[newFromOld[7]][6].first == Approx(2.30).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][7].second == newFromOld[3]); + REQUIRE(sortedOutput[newFromOld[7]][7].first == Approx(2.55).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[7]][8].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[7]][8].first == Approx(6.35).epsilon(1e-7)); // Neighbors of point 8. - BOOST_REQUIRE(sortedOutput[newFromOld[8]].size() == 3); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][0].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][0].first, 1.75, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][1].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][1].first, 2.45, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[8]][2].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[8]][2].first, 4.60, 1e-5); + REQUIRE(sortedOutput[newFromOld[8]].size() == 3); + REQUIRE(sortedOutput[newFromOld[8]][0].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[8]][0].first == Approx(1.75).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[8]][1].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[8]][1].first == Approx(2.45).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[8]][2].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[8]][2].first == Approx(4.60).epsilon(1e-7)); // Neighbors of point 9. - BOOST_REQUIRE(sortedOutput[newFromOld[9]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][0].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][0].first, 1.12, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][1].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][1].first, 2.20, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][2].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][2].first, 2.90, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[9]][3].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[9]][3].first, 4.15, 1e-5); + REQUIRE(sortedOutput[newFromOld[9]].size() == 4); + REQUIRE(sortedOutput[newFromOld[9]][0].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[9]][0].first == Approx(1.12).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[9]][1].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[9]][1].first == Approx(2.20).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[9]][2].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[9]][2].first == Approx(2.90).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[9]][3].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[9]][3].first == Approx(4.15).epsilon(1e-7)); // Neighbors of point 10. - BOOST_REQUIRE(sortedOutput[newFromOld[10]].size() == 4); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[5]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][0].first, 1.22, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[7]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][1].first, 2.30, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][2].second == newFromOld[6]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][2].first, 3.00, 1e-5); - BOOST_REQUIRE(sortedOutput[newFromOld[10]][3].second == newFromOld[4]); - BOOST_REQUIRE_CLOSE(sortedOutput[newFromOld[10]][3].first, 4.05, 1e-5); + REQUIRE(sortedOutput[newFromOld[10]].size() == 4); + REQUIRE(sortedOutput[newFromOld[10]][0].second == newFromOld[5]); + REQUIRE(sortedOutput[newFromOld[10]][0].first == Approx(1.22).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][1].second == newFromOld[7]); + REQUIRE(sortedOutput[newFromOld[10]][1].first == Approx(2.30).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][2].second == newFromOld[6]); + REQUIRE(sortedOutput[newFromOld[10]][2].first == Approx(3.00).epsilon(1e-7)); + REQUIRE(sortedOutput[newFromOld[10]][3].second == newFromOld[4]); + REQUIRE(sortedOutput[newFromOld[10]][3].first == Approx(4.05).epsilon(1e-7)); // Clean the memory. delete rs; @@ -455,13 +454,13 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) * * Errors are produced if the results are not identical. */ -BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) +TEST_CASE("DualTreeVsNaive1", "[RangeSearchTest]") { arma::mat dataForTree; // Hard-coded filename: bad! if (!data::Load("test_data_3_1000.csv", dataForTree)) - BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); + FAIL("Cannot load test dataset test_data_3_1000.csv!"); // Set up matrices to work with. arma::mat dualQuery(dataForTree); @@ -487,13 +486,13 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) for (size_t i = 0; i < sortedTree.size(); ++i) { - BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); + REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); for (size_t j = 0; j < sortedTree[i].size(); ++j) { - BOOST_REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); - BOOST_REQUIRE_CLOSE(sortedTree[i][j].first, sortedNaive[i][j].first, - 1e-5); + REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); + REQUIRE(sortedTree[i][j].first == Approx(sortedNaive[i][j].first).epsilon + (1e-5)); } } } @@ -504,14 +503,14 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) * * Errors are produced if the results are not identical. */ -BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) +TEST_CASE("DualTreeVsNaive2", "[RangeSearchTest]") { arma::mat dataForTree; // Hard-coded filename: bad! // Code duplication: also bad! if (!data::Load("test_data_3_1000.csv", dataForTree)) - BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); + FAIL("Cannot load test dataset test_data_3_1000.csv!"); // Set up matrices to work with. arma::mat dualQuery(dataForTree); @@ -536,13 +535,13 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) for (size_t i = 0; i < sortedTree.size(); ++i) { - BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); + REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); for (size_t j = 0; j < sortedTree[i].size(); ++j) { - BOOST_REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); - BOOST_REQUIRE_CLOSE(sortedTree[i][j].first, sortedNaive[i][j].first, - 1e-5); + REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); + REQUIRE(sortedTree[i][j].first == Approx(sortedNaive[i][j].first).epsilon + (1e-5)); } } } @@ -553,14 +552,14 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) * * Errors are produced if the results are not identical. */ -BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) +TEST_CASE("SingleTreeVsNaive", "[RangeSearchTest]") { arma::mat dataForTree; // Hard-coded filename: bad! // Code duplication: also bad! if (!data::Load("test_data_3_1000.csv", dataForTree)) - BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!"); + FAIL("Cannot load test dataset test_data_3_1000.csv!"); // Set up matrices to work with (may not be necessary with no ALIAS_MATRIX?). arma::mat singleQuery(dataForTree); @@ -585,13 +584,13 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) for (size_t i = 0; i < sortedTree.size(); ++i) { - BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); + REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); for (size_t j = 0; j < sortedTree[i].size(); ++j) { - BOOST_REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); - BOOST_REQUIRE_CLOSE(sortedTree[i][j].first, sortedNaive[i][j].first, - 1e-5); + REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); + REQUIRE(sortedTree[i][j].first == Approx(sortedNaive[i][j].first).epsilon + (1e-5)); } } } @@ -600,7 +599,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) * Ensure that dual tree range search with cover trees works by comparing * with the kd-tree implementation. */ -BOOST_AUTO_TEST_CASE(CoverTreeTest) +TEST_CASE("CoverTreeTest", "[RangeSearchTest]") { arma::mat data; data.randu(8, 1000); // 1000 points in 8 dimensions. @@ -662,11 +661,11 @@ BOOST_AUTO_TEST_CASE(CoverTreeTest) { for (size_t j = 0; j < kdSorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(kdSorted[i][j].second, coverSorted[i][j].second); - BOOST_REQUIRE_CLOSE(kdSorted[i][j].first, coverSorted[i][j].first, - 1e-5); + REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); + REQUIRE(kdSorted[i][j].first == Approx(coverSorted[i][j].first).epsilon + (1e-7)); } - BOOST_REQUIRE_EQUAL(kdSorted[i].size(), coverSorted[i].size()); + REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } } } @@ -675,7 +674,7 @@ BOOST_AUTO_TEST_CASE(CoverTreeTest) * Ensure that dual tree range search with cover trees works when using * two datasets. */ -BOOST_AUTO_TEST_CASE(CoverTreeTwoDatasetsTest) +TEST_CASE("CoverTreeTwoDatasetsTest", "[RangeSearchTest]") { arma::mat data; data.randu(8, 1000); // 1000 points in 8 dimensions. @@ -740,11 +739,11 @@ BOOST_AUTO_TEST_CASE(CoverTreeTwoDatasetsTest) { for (size_t j = 0; j < kdSorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(kdSorted[i][j].second, coverSorted[i][j].second); - BOOST_REQUIRE_CLOSE(kdSorted[i][j].first, coverSorted[i][j].first, - 1e-5); + REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); + REQUIRE(kdSorted[i][j].first == Approx(coverSorted[i][j].first).epsilon + (1e-7)); } - BOOST_REQUIRE_EQUAL(kdSorted[i].size(), coverSorted[i].size()); + REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } } } @@ -752,7 +751,7 @@ BOOST_AUTO_TEST_CASE(CoverTreeTwoDatasetsTest) /** * Ensure that single-tree cover tree range search works. */ -BOOST_AUTO_TEST_CASE(CoverTreeSingleTreeTest) +TEST_CASE("CoverTreeSingleTreeTest", "[RangeSearchTest]") { arma::mat data; data.randu(8, 1000); // 1000 points in 8 dimensions. @@ -814,11 +813,11 @@ BOOST_AUTO_TEST_CASE(CoverTreeSingleTreeTest) { for (size_t j = 0; j < kdSorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(kdSorted[i][j].second, coverSorted[i][j].second); - BOOST_REQUIRE_CLOSE(kdSorted[i][j].first, coverSorted[i][j].first, - 1e-5); + REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); + REQUIRE(kdSorted[i][j].first == Approx(coverSorted[i][j].first).epsilon + (1e-7)); } - BOOST_REQUIRE_EQUAL(kdSorted[i].size(), coverSorted[i].size()); + REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } } } @@ -826,7 +825,7 @@ BOOST_AUTO_TEST_CASE(CoverTreeSingleTreeTest) /** * Ensure that single-tree ball tree range search works. */ -BOOST_AUTO_TEST_CASE(SingleBallTreeTest) +TEST_CASE("SingleBallTreeTest", "[RangeSearchTest]") { arma::mat data; data.randu(8, 1000); // 1000 points in 8 dimensions. @@ -888,11 +887,11 @@ BOOST_AUTO_TEST_CASE(SingleBallTreeTest) { for (size_t j = 0; j < kdSorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(kdSorted[i][j].second, ballSorted[i][j].second); - BOOST_REQUIRE_CLOSE(kdSorted[i][j].first, ballSorted[i][j].first, - 1e-5); + REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); + REQUIRE(kdSorted[i][j].first == Approx(ballSorted[i][j].first).epsilon + (1e-7)); } - BOOST_REQUIRE_EQUAL(kdSorted[i].size(), ballSorted[i].size()); + REQUIRE(kdSorted[i].size() == ballSorted[i].size()); } } } @@ -901,7 +900,7 @@ BOOST_AUTO_TEST_CASE(SingleBallTreeTest) * Ensure that dual tree range search with ball trees works by comparing * with the kd-tree implementation. */ -BOOST_AUTO_TEST_CASE(DualBallTreeTest) +TEST_CASE("DualBallTreeTest", "[RangeSearchTest]") { arma::mat data; data.randu(8, 1000); // 1000 points in 8 dimensions. @@ -962,11 +961,11 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest) { for (size_t j = 0; j < kdSorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(kdSorted[i][j].second, ballSorted[i][j].second); - BOOST_REQUIRE_CLOSE(kdSorted[i][j].first, ballSorted[i][j].first, - 1e-5); + REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); + REQUIRE(kdSorted[i][j].first == Approx(ballSorted[i][j].first).epsilon + (1e-7)); } - BOOST_REQUIRE_EQUAL(kdSorted[i].size(), ballSorted[i].size()); + REQUIRE(kdSorted[i].size() == ballSorted[i].size()); } } } @@ -975,7 +974,7 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest) * Ensure that dual tree range search with ball trees works when using * two datasets. */ -BOOST_AUTO_TEST_CASE(DualBallTreeTest2) +TEST_CASE("DualBallTreeTest2", "[RangeSearchTest]") { arma::mat data; data.randu(8, 1000); // 1000 points in 8 dimensions. @@ -1038,12 +1037,12 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest2) // Now compare the results. for (size_t i = 0; i < kdSorted.size(); ++i) { - BOOST_REQUIRE_EQUAL(kdSorted[i].size(), ballSorted[i].size()); + REQUIRE(kdSorted[i].size() == ballSorted[i].size()); for (size_t j = 0; j < kdSorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(kdSorted[i][j].second, ballSorted[i][j].second); - BOOST_REQUIRE_CLOSE(kdSorted[i][j].first, ballSorted[i][j].first, - 1e-5); + REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); + REQUIRE(kdSorted[i][j].first == Approx(ballSorted[i][j].first).epsilon + (1e-7)); } } } @@ -1053,7 +1052,7 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest2) * Make sure that no results are returned when we build a range search object * with no reference set. */ -BOOST_AUTO_TEST_CASE(EmptySearchTest) +TEST_CASE("EmptySearchTest", "[RangeSearchTest]") { RangeSearch rs; @@ -1062,20 +1061,20 @@ BOOST_AUTO_TEST_CASE(EmptySearchTest) rs.Search(math::Range(0.0, 10.0), neighbors, distances); - BOOST_REQUIRE_EQUAL(neighbors.size(), 0); - BOOST_REQUIRE_EQUAL(distances.size(), 0); + REQUIRE(neighbors.size() == 0); + REQUIRE(distances.size() == 0); // Now check with a query set. arma::mat querySet = arma::randu(3, 100); - BOOST_REQUIRE_THROW(rs.Search(querySet, math::Range(0.0, 10.0), neighbors, + REQUIRE_THROWS_AS(rs.Search(querySet, math::Range(0.0, 10.0), neighbors, distances), std::invalid_argument); } /** * Make sure things work right after Train() is called. */ -BOOST_AUTO_TEST_CASE(TrainTest) +TEST_CASE("TrainTest", "[RangeSearchTest]") { RangeSearch<> empty; @@ -1090,8 +1089,8 @@ BOOST_AUTO_TEST_CASE(TrainTest) empty.Search(math::Range(0.5, 0.7), neighbors, distances); baseline.Search(math::Range(0.5, 0.7), baselineNeighbors, baselineDistances); - BOOST_REQUIRE_EQUAL(neighbors.size(), baselineNeighbors.size()); - BOOST_REQUIRE_EQUAL(distances.size(), baselineDistances.size()); + REQUIRE(neighbors.size() == baselineNeighbors.size()); + REQUIRE(distances.size() == baselineDistances.size()); // Sort the results before comparing. vector>> sorted; @@ -1101,11 +1100,11 @@ BOOST_AUTO_TEST_CASE(TrainTest) for (size_t i = 0; i < sorted.size(); ++i) { - BOOST_REQUIRE_EQUAL(sorted[i].size(), baselineSorted[i].size()); + REQUIRE(sorted[i].size() == baselineSorted[i].size()); for (size_t j = 0; j < sorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(sorted[i][j].second, baselineSorted[i][j].second); - BOOST_REQUIRE_CLOSE(sorted[i][j].first, baselineSorted[i][j].first, 1e-5); + REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); + REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon(1e-7)); } } } @@ -1113,7 +1112,7 @@ BOOST_AUTO_TEST_CASE(TrainTest) /** * Test training when a tree is given. */ -BOOST_AUTO_TEST_CASE(TrainTreeTest) +TEST_CASE("TrainTreeTest", "[RangeSearchTest]") { // Avoid mappings by using the cover tree. typedef RangeSearch RSType; @@ -1131,8 +1130,8 @@ BOOST_AUTO_TEST_CASE(TrainTreeTest) empty.Search(math::Range(0.5, 0.7), neighbors, distances); baseline.Search(math::Range(0.5, 0.7), baselineNeighbors, baselineDistances); - BOOST_REQUIRE_EQUAL(neighbors.size(), baselineNeighbors.size()); - BOOST_REQUIRE_EQUAL(distances.size(), baselineDistances.size()); + REQUIRE(neighbors.size() == baselineNeighbors.size()); + REQUIRE(distances.size() == baselineDistances.size()); // Sort the results before comparing. vector>> sorted; @@ -1142,11 +1141,11 @@ BOOST_AUTO_TEST_CASE(TrainTreeTest) for (size_t i = 0; i < sorted.size(); ++i) { - BOOST_REQUIRE_EQUAL(sorted[i].size(), baselineSorted[i].size()); + REQUIRE(sorted[i].size() == baselineSorted[i].size()); for (size_t j = 0; j < sorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(sorted[i][j].second, baselineSorted[i][j].second); - BOOST_REQUIRE_CLOSE(sorted[i][j].first, baselineSorted[i][j].first, 1e-5); + REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); + REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon(1e-7)); } } } @@ -1154,20 +1153,20 @@ BOOST_AUTO_TEST_CASE(TrainTreeTest) /** * Test that training with a tree throws an exception when in naive mode. */ -BOOST_AUTO_TEST_CASE(NaiveTrainTreeTest) +TEST_CASE("NaiveTrainTreeTest", "[RangeSearchTest]") { RangeSearch<> empty(true); arma::mat dataset = arma::randu(5, 100); RangeSearch<>::Tree tree(dataset); - BOOST_REQUIRE_THROW(empty.Train(&tree), std::invalid_argument); + REQUIRE_THROWS_AS(empty.Train(&tree), std::invalid_argument); } /** * Test that the move constructor works. */ -BOOST_AUTO_TEST_CASE(MoveConstructorMatrixTest) +TEST_CASE("MoveConstructorMatrixTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(3, 100); arma::mat copy(dataset); @@ -1175,9 +1174,9 @@ BOOST_AUTO_TEST_CASE(MoveConstructorMatrixTest) RangeSearch<> movers(std::move(copy)); RangeSearch<> rs(dataset); - BOOST_REQUIRE_EQUAL(copy.n_elem, 0); - BOOST_REQUIRE_EQUAL(movers.ReferenceSet().n_rows, 3); - BOOST_REQUIRE_EQUAL(movers.ReferenceSet().n_cols, 100); + REQUIRE(copy.n_elem == 0); + REQUIRE(movers.ReferenceSet().n_rows == 3); + REQUIRE(movers.ReferenceSet().n_cols == 100); vector> moveNeighbors, neighbors; vector> moveDistances, distances; @@ -1185,8 +1184,8 @@ BOOST_AUTO_TEST_CASE(MoveConstructorMatrixTest) movers.Search(math::Range(0.5, 0.7), moveNeighbors, moveDistances); rs.Search(math::Range(0.5, 0.7), neighbors, distances); - BOOST_REQUIRE_EQUAL(neighbors.size(), moveNeighbors.size()); - BOOST_REQUIRE_EQUAL(distances.size(), moveDistances.size()); + REQUIRE(neighbors.size() == moveNeighbors.size()); + REQUIRE(distances.size() == moveDistances.size()); // Sort the results before comparing. vector>> sorted; @@ -1196,11 +1195,11 @@ BOOST_AUTO_TEST_CASE(MoveConstructorMatrixTest) for (size_t i = 0; i < sorted.size(); ++i) { - BOOST_REQUIRE_EQUAL(sorted[i].size(), moveSorted[i].size()); + REQUIRE(sorted[i].size() == moveSorted[i].size()); for (size_t j = 0; j < sorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(sorted[i][j].second, moveSorted[i][j].second); - BOOST_REQUIRE_CLOSE(sorted[i][j].first, moveSorted[i][j].first, 1e-5); + REQUIRE(sorted[i][j].second == moveSorted[i][j].second); + REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon(1e-7)); } } } @@ -1208,7 +1207,7 @@ BOOST_AUTO_TEST_CASE(MoveConstructorMatrixTest) /** * Test that the std::move() Train() function works. */ -BOOST_AUTO_TEST_CASE(MoveTrainTest) +TEST_CASE("MoveTrainTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(3, 100); arma::mat copy(dataset); @@ -1217,9 +1216,9 @@ BOOST_AUTO_TEST_CASE(MoveTrainTest) movers.Train(std::move(copy)); RangeSearch<> rs(dataset); - BOOST_REQUIRE_EQUAL(copy.n_elem, 0); - BOOST_REQUIRE_EQUAL(movers.ReferenceSet().n_rows, 3); - BOOST_REQUIRE_EQUAL(movers.ReferenceSet().n_cols, 100); + REQUIRE(copy.n_elem == 0); + REQUIRE(movers.ReferenceSet().n_rows == 3); + REQUIRE(movers.ReferenceSet().n_cols == 100); vector> moveNeighbors, neighbors; vector> moveDistances, distances; @@ -1227,8 +1226,8 @@ BOOST_AUTO_TEST_CASE(MoveTrainTest) movers.Search(math::Range(0.5, 0.7), moveNeighbors, moveDistances); rs.Search(math::Range(0.5, 0.7), neighbors, distances); - BOOST_REQUIRE_EQUAL(neighbors.size(), moveNeighbors.size()); - BOOST_REQUIRE_EQUAL(distances.size(), moveDistances.size()); + REQUIRE(neighbors.size() == moveNeighbors.size()); + REQUIRE(distances.size() == moveDistances.size()); // Sort the results before comparing. vector>> sorted; @@ -1238,16 +1237,16 @@ BOOST_AUTO_TEST_CASE(MoveTrainTest) for (size_t i = 0; i < sorted.size(); ++i) { - BOOST_REQUIRE_EQUAL(sorted[i].size(), moveSorted[i].size()); + REQUIRE(sorted[i].size() == moveSorted[i].size()); for (size_t j = 0; j < sorted[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(sorted[i][j].second, moveSorted[i][j].second); - BOOST_REQUIRE_CLOSE(sorted[i][j].first, moveSorted[i][j].first, 1e-5); + REQUIRE(sorted[i][j].second == moveSorted[i][j].second); + REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon(1e-7)); } } } -BOOST_AUTO_TEST_CASE(RSModelTest) +TEST_CASE("RSModelTest", "[RangeSearchTest]") { // Ensure that we can build an RSModel and get correct results. arma::mat queryData = arma::randu(10, 50); @@ -1314,27 +1313,27 @@ BOOST_AUTO_TEST_CASE(RSModelTest) models[i].Search(std::move(queryCopy), math::Range(0.25, 0.75), neighbors, distances); - BOOST_REQUIRE_EQUAL(neighbors.size(), baselineNeighbors.size()); - BOOST_REQUIRE_EQUAL(distances.size(), baselineDistances.size()); + REQUIRE(neighbors.size() == baselineNeighbors.size()); + REQUIRE(distances.size() == baselineDistances.size()); vector>> sorted; SortResults(neighbors, distances, sorted); for (size_t k = 0; k < sorted.size(); ++k) { - BOOST_REQUIRE_EQUAL(sorted[k].size(), baselineSorted[k].size()); + REQUIRE(sorted[k].size() == baselineSorted[k].size()); for (size_t l = 0; l < sorted[k].size(); ++l) { - BOOST_REQUIRE_EQUAL(sorted[k][l].second, baselineSorted[k][l].second); - BOOST_REQUIRE_CLOSE(sorted[k][l].first, baselineSorted[k][l].first, - 1e-5); + REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); + REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first).epsilon + (1e-7)); } } } } } -BOOST_AUTO_TEST_CASE(RSModelMonochromaticTest) +TEST_CASE("RSModelMonochromaticTest", "[RangeSearchTest]") { // Ensure that we can build an RSModel and get correct results. arma::mat referenceData = arma::randu(10, 200); @@ -1397,20 +1396,20 @@ BOOST_AUTO_TEST_CASE(RSModelMonochromaticTest) models[i].Search(math::Range(0.25, 0.5), neighbors, distances); - BOOST_REQUIRE_EQUAL(neighbors.size(), baselineNeighbors.size()); - BOOST_REQUIRE_EQUAL(distances.size(), baselineDistances.size()); + REQUIRE(neighbors.size() == baselineNeighbors.size()); + REQUIRE(distances.size() == baselineDistances.size()); vector>> sorted; SortResults(neighbors, distances, sorted); for (size_t k = 0; k < sorted.size(); ++k) { - BOOST_REQUIRE_EQUAL(sorted[k].size(), baselineSorted[k].size()); + REQUIRE(sorted[k].size() == baselineSorted[k].size()); for (size_t l = 0; l < sorted[k].size(); ++l) { - BOOST_REQUIRE_EQUAL(sorted[k][l].second, baselineSorted[k][l].second); - BOOST_REQUIRE_CLOSE(sorted[k][l].first, baselineSorted[k][l].first, - 1e-5); + REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); + REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first).epsilon + (1e-7)); } } } @@ -1421,7 +1420,7 @@ BOOST_AUTO_TEST_CASE(RSModelMonochromaticTest) * Make sure that the neighborPtr matrix isn't accidentally deleted. * See issue #478. */ -BOOST_AUTO_TEST_CASE(NeighborPtrDeleteTest) +TEST_CASE("NeighborPtrDeleteTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 100); @@ -1438,14 +1437,14 @@ BOOST_AUTO_TEST_CASE(NeighborPtrDeleteTest) // These will (hopefully) fail is either the neighbors or the distances matrix // has been accidentally deleted. - BOOST_REQUIRE_EQUAL(neighbors.size(), 50); - BOOST_REQUIRE_EQUAL(distances.size(), 50); + REQUIRE(neighbors.size() == 50); + REQUIRE(distances.size() == 50); } /** * Test copy constructor and copy operator. */ -BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest) +TEST_CASE("CopyConstructorAndOperatorTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<> rs(std::move(dataset)); @@ -1463,26 +1462,26 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest) rs3.Search(math::Range(0.2, 0.3), neighbors3, distances3); // Check results. - BOOST_REQUIRE_EQUAL(distances.size(), distances2.size()); - BOOST_REQUIRE_EQUAL(distances.size(), distances3.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors2.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors3.size()); + REQUIRE(distances.size() == distances2.size()); + REQUIRE(distances.size() == distances3.size()); + REQUIRE(neighbors.size() == neighbors2.size()); + REQUIRE(neighbors.size() == neighbors3.size()); for (size_t i = 0; i < neighbors.size(); ++i) { - BOOST_REQUIRE_EQUAL(distances[i].size(), distances2[i].size()); - BOOST_REQUIRE_EQUAL(distances[i].size(), distances3[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors2[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors3[i].size()); + REQUIRE(distances[i].size() == distances2[i].size()); + REQUIRE(distances[i].size() == distances3[i].size()); + REQUIRE(neighbors[i].size() == neighbors2[i].size()); + REQUIRE(neighbors[i].size() == neighbors3[i].size()); for (size_t j = 0; j < neighbors[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors2[i][j]); - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors3[i][j]); + REQUIRE(neighbors[i][j] == neighbors2[i][j]); + REQUIRE(neighbors[i][j] == neighbors3[i][j]); // Distances will always be between 0.2 and 0.3. - BOOST_REQUIRE_CLOSE(distances[i][j], distances2[i][j], 1e-5); - BOOST_REQUIRE_CLOSE(distances[i][j], distances3[i][j], 1e-5); + REQUIRE(distances[i][j] == Approx(distances2[i][j]).epsilon(1e-7)); + REQUIRE(distances[i][j] == Approx(distances3[i][j]).epsilon(1e-7)); } } } @@ -1490,7 +1489,7 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest) /** * Test move constructor. */ -BOOST_AUTO_TEST_CASE(MoveConstructorTest) +TEST_CASE("MoveConstructorTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<>* rs = new RangeSearch<>(std::move(dataset)); @@ -1508,20 +1507,20 @@ BOOST_AUTO_TEST_CASE(MoveConstructorTest) rs2.Search(math::Range(0.2, 0.3), neighbors2, distances2); // Check results. - BOOST_REQUIRE_EQUAL(distances.size(), distances2.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors2.size()); + REQUIRE(distances.size() == distances2.size()); + REQUIRE(neighbors.size() == neighbors2.size()); for (size_t i = 0; i < neighbors.size(); ++i) { - BOOST_REQUIRE_EQUAL(distances[i].size(), distances2[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors2[i].size()); + REQUIRE(distances[i].size() == distances2[i].size()); + REQUIRE(neighbors[i].size() == neighbors2[i].size()); for (size_t j = 0; j < neighbors[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors2[i][j]); + REQUIRE(neighbors[i][j] == neighbors2[i][j]); // Distances will always be between 0.2 and 0.3. - BOOST_REQUIRE_CLOSE(distances[i][j], distances2[i][j], 1e-5); + REQUIRE(distances[i][j] == Approx(distances2[i][j]).epsilon(1e-7)); } } } @@ -1529,7 +1528,7 @@ BOOST_AUTO_TEST_CASE(MoveConstructorTest) /** * Test move operator. */ -BOOST_AUTO_TEST_CASE(MoveOperatorTest) +TEST_CASE("MoveOperatorTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<>* rs = new RangeSearch<>(std::move(dataset)); @@ -1547,20 +1546,20 @@ BOOST_AUTO_TEST_CASE(MoveOperatorTest) rs2.Search(math::Range(0.2, 0.3), neighbors2, distances2); // Check results. - BOOST_REQUIRE_EQUAL(distances.size(), distances2.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors2.size()); + REQUIRE(distances.size() == distances2.size()); + REQUIRE(neighbors.size() == neighbors2.size()); for (size_t i = 0; i < neighbors.size(); ++i) { - BOOST_REQUIRE_EQUAL(distances[i].size(), distances2[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors2[i].size()); + REQUIRE(distances[i].size() == distances2[i].size()); + REQUIRE(neighbors[i].size() == neighbors2[i].size()); for (size_t j = 0; j < neighbors[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors2[i][j]); + REQUIRE(neighbors[i][j] == neighbors2[i][j]); // Distances will always be between 0.2 and 0.3. - BOOST_REQUIRE_CLOSE(distances[i][j], distances2[i][j], 1e-5); + REQUIRE(distances[i][j] == Approx(distances2[i][j]).epsilon(1e-7)); } } } @@ -1569,7 +1568,7 @@ BOOST_AUTO_TEST_CASE(MoveOperatorTest) * Test copy constructor and copy operator in naive mode (so there are no * trees). */ -BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorNaiveTest) +TEST_CASE("CopyConstructorAndOperatorNaiveTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<> rs(std::move(dataset), true); @@ -1578,8 +1577,8 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorNaiveTest) RangeSearch<> rs2(rs); RangeSearch<> rs3 = rs; - BOOST_REQUIRE_EQUAL(rs2.Naive(), true); - BOOST_REQUIRE_EQUAL(rs3.Naive(), true); + REQUIRE(rs2.Naive() == true); + REQUIRE(rs3.Naive() == true); // Get results. vector> distances, distances2, distances3; @@ -1590,26 +1589,26 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorNaiveTest) rs3.Search(math::Range(0.2, 0.3), neighbors3, distances3); // Check results. - BOOST_REQUIRE_EQUAL(distances.size(), distances2.size()); - BOOST_REQUIRE_EQUAL(distances.size(), distances3.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors2.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors3.size()); + REQUIRE(distances.size() == distances2.size()); + REQUIRE(distances.size() == distances3.size()); + REQUIRE(neighbors.size() == neighbors2.size()); + REQUIRE(neighbors.size() == neighbors3.size()); for (size_t i = 0; i < neighbors.size(); ++i) { - BOOST_REQUIRE_EQUAL(distances[i].size(), distances2[i].size()); - BOOST_REQUIRE_EQUAL(distances[i].size(), distances3[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors2[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors3[i].size()); + REQUIRE(distances[i].size() == distances2[i].size()); + REQUIRE(distances[i].size() == distances3[i].size()); + REQUIRE(neighbors[i].size() == neighbors2[i].size()); + REQUIRE(neighbors[i].size() == neighbors3[i].size()); for (size_t j = 0; j < neighbors[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors2[i][j]); - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors3[i][j]); + REQUIRE(neighbors[i][j] == neighbors2[i][j]); + REQUIRE(neighbors[i][j] == neighbors3[i][j]); // Distances will always be between 0.2 and 0.3. - BOOST_REQUIRE_CLOSE(distances[i][j], distances2[i][j], 1e-5); - BOOST_REQUIRE_CLOSE(distances[i][j], distances3[i][j], 1e-5); + REQUIRE(distances[i][j] == Approx(distances2[i][j]).epsilon(1e-7)); + REQUIRE(distances[i][j] == Approx(distances3[i][j]).epsilon(1e-7)); } } } @@ -1617,7 +1616,7 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorNaiveTest) /** * Test move constructor. */ -BOOST_AUTO_TEST_CASE(MoveConstructorNaiveTest) +TEST_CASE("MoveConstructorNaiveTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<>* rs = new RangeSearch<>(std::move(dataset), true); @@ -1630,27 +1629,27 @@ BOOST_AUTO_TEST_CASE(MoveConstructorNaiveTest) RangeSearch<> rs2(std::move(*rs)); - BOOST_REQUIRE_EQUAL(rs2.Naive(), true); + REQUIRE(rs2.Naive() == true); delete rs; rs2.Search(math::Range(0.2, 0.3), neighbors2, distances2); // Check results. - BOOST_REQUIRE_EQUAL(distances.size(), distances2.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors2.size()); + REQUIRE(distances.size() == distances2.size()); + REQUIRE(neighbors.size() == neighbors2.size()); for (size_t i = 0; i < neighbors.size(); ++i) { - BOOST_REQUIRE_EQUAL(distances[i].size(), distances2[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors2[i].size()); + REQUIRE(distances[i].size() == distances2[i].size()); + REQUIRE(neighbors[i].size() == neighbors2[i].size()); for (size_t j = 0; j < neighbors[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors2[i][j]); + REQUIRE(neighbors[i][j] == neighbors2[i][j]); // Distances will always be between 0.2 and 0.3. - BOOST_REQUIRE_CLOSE(distances[i][j], distances2[i][j], 1e-5); + REQUIRE(distances[i][j] == Approx(distances2[i][j]).epsilon(1e-7)); } } } @@ -1658,7 +1657,7 @@ BOOST_AUTO_TEST_CASE(MoveConstructorNaiveTest) /** * Test move operator. */ -BOOST_AUTO_TEST_CASE(MoveOperatorNaiveTest) +TEST_CASE("MoveOperatorNaiveTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<>* rs = new RangeSearch<>(std::move(dataset), true); @@ -1671,29 +1670,27 @@ BOOST_AUTO_TEST_CASE(MoveOperatorNaiveTest) RangeSearch<> rs2 = std::move(*rs); - BOOST_REQUIRE_EQUAL(rs2.Naive(), true); + REQUIRE(rs2.Naive() == true); delete rs; rs2.Search(math::Range(0.2, 0.3), neighbors2, distances2); // Check results. - BOOST_REQUIRE_EQUAL(distances.size(), distances2.size()); - BOOST_REQUIRE_EQUAL(neighbors.size(), neighbors2.size()); + REQUIRE(distances.size() == distances2.size()); + REQUIRE(neighbors.size() == neighbors2.size()); for (size_t i = 0; i < neighbors.size(); ++i) { - BOOST_REQUIRE_EQUAL(distances[i].size(), distances2[i].size()); - BOOST_REQUIRE_EQUAL(neighbors[i].size(), neighbors2[i].size()); + REQUIRE(distances[i].size() == distances2[i].size()); + REQUIRE(neighbors[i].size() == neighbors2[i].size()); for (size_t j = 0; j < neighbors[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(neighbors[i][j], neighbors2[i][j]); + REQUIRE(neighbors[i][j] == neighbors2[i][j]); // Distances will always be between 0.2 and 0.3. - BOOST_REQUIRE_CLOSE(distances[i][j], distances2[i][j], 1e-5); + REQUIRE(distances[i][j] == Approx(distances2[i][j]).epsilon(1e-7)); } } } - -BOOST_AUTO_TEST_SUITE_END(); From b54e84f8d0a9bf40d5704334b245160961d74fe6 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Thu, 1 Oct 2020 22:43:43 +0530 Subject: [PATCH 02/11] main_tests/range_search_test to catch2 --- .../tests/main_tests/range_search_test.cpp | 101 ++++++++++-------- .../tests/main_tests/range_search_utils.hpp | 14 +-- 2 files changed, 62 insertions(+), 53 deletions(-) diff --git a/src/mlpack/tests/main_tests/range_search_test.cpp b/src/mlpack/tests/main_tests/range_search_test.cpp index 8102aae4e9..552ff4eba4 100644 --- a/src/mlpack/tests/main_tests/range_search_test.cpp +++ b/src/mlpack/tests/main_tests/range_search_test.cpp @@ -17,7 +17,7 @@ static const std::string testName = "RangeSearchMain"; #include "test_helper.hpp" #include #include "range_search_utils.hpp" -#include +#include "../catch.hpp" using namespace mlpack; @@ -37,34 +37,35 @@ struct RangeSearchTestFixture } }; -BOOST_FIXTURE_TEST_SUITE(RangeSearchMainTest, RangeSearchTestFixture); - /** * Check that we have to specify a reference set or input model. */ -BOOST_AUTO_TEST_CASE(RangeSearchNoReference) +TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchNoReference", + "[RangeSearchMainTest][BindingTests]" { Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; } /** * Check that we cannot pass an incorrect parameter. */ -BOOST_AUTO_TEST_CASE(RangeSearchWrongParameter) +TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchWrongParameter", + "[RangeSearchMainTest][BindingTests]" { string wrongString = "abc"; Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(SetInputParam("RST", wrongString), std::runtime_error); + REQUIRE_THROWS_AS(SetInputParam("RST", wrongString), std::runtime_error); Log::Fatal.ignoreInput = false; } /** * Check that we have to specify a query if an input model is specified. */ -BOOST_AUTO_TEST_CASE(RangeSearchInputModelNoQuery) +TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchInputModelNoQuery", + "[RangeSearchMainTest][BindingTests]" { arma::mat inputData; double minVal = 0, maxVal = 3; @@ -72,7 +73,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchInputModelNoQuery) string neighborsFile = "neighbors.csv"; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); SetInputParam("reference", move(inputData)); SetInputParam("min", minVal); @@ -86,7 +87,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchInputModelNoQuery) SetInputParam("input_model", move(IO::GetParam("output_model"))); Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; remove(neighborsFile.c_str()); @@ -96,7 +97,8 @@ BOOST_AUTO_TEST_CASE(RangeSearchInputModelNoQuery) /** * Check that we cannot specify a tree type which is not available or wrong. */ -BOOST_AUTO_TEST_CASE(RangeSearchDifferentTree) +TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchDifferentTree", + "[RangeSearchMainTest][BindingTests]" { arma::mat inputData; double minVal = 0, maxVal = 3; @@ -104,7 +106,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchDifferentTree) string neighborsFile = "neighbors.csv"; string wrongTreeType = "RST"; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); SetInputParam("reference", move(inputData)); SetInputParam("min", minVal); @@ -114,7 +116,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchDifferentTree) SetInputParam("tree_type", wrongTreeType); Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; remove(neighborsFile.c_str()); @@ -124,7 +126,8 @@ BOOST_AUTO_TEST_CASE(RangeSearchDifferentTree) /** * Check that we cannot specify both a reference set and input model. */ -BOOST_AUTO_TEST_CASE(RangeSearchBothReferenceAndModel) +TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchBothReferenceAndModel", + "[RangeSearchMainTest][BindingTests]" { arma::mat inputData, queryData; double minVal = 0, maxVal = 3; @@ -132,9 +135,9 @@ BOOST_AUTO_TEST_CASE(RangeSearchBothReferenceAndModel) string neighborsFile = "neighbors.csv"; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); if (!data::Load("iris_test.csv", queryData)) - BOOST_FAIL("Unable to load dataset iris_test.csv!"); + FAIL("Unable to load dataset iris_test.csv!"); SetInputParam("reference", move(inputData)); SetInputParam("min", minVal); @@ -149,7 +152,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchBothReferenceAndModel) SetInputParam("query", move(queryData)); Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; remove(neighborsFile.c_str()); @@ -161,7 +164,8 @@ BOOST_AUTO_TEST_CASE(RangeSearchBothReferenceAndModel) * by comparing with pre-calculated neighbor and distance values, when no query * set is specified. */ -BOOST_AUTO_TEST_CASE(RangeSearchTest) +TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchTest", + "[RangeSearchMainTest][BindingTests]" { arma::mat x = {{0, 3, 3, 4, 3, 1}, {4, 4, 4, 5, 5, 2}, @@ -208,7 +212,8 @@ BOOST_AUTO_TEST_CASE(RangeSearchTest) * Check that the correct output is returned for a small synthetic input case, * when a query set is provided. */ -BOOST_AUTO_TEST_CASE(RangeSeachTestwithQuery) +TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSeachTestwithQuery", + "[RangeSearchMainTest][BindingTests]" { arma::mat queryData = {{5, 3, 1}, {4, 2, 4}, {3, 1, 7}}; arma::mat x = {{0, 3, 3, 4, 3, 1}, @@ -252,7 +257,8 @@ BOOST_AUTO_TEST_CASE(RangeSeachTestwithQuery) * Train a model using a synthetic dataset and then output the model, and ensure * it can be used again. */ -BOOST_AUTO_TEST_CASE(ModelCheck) +TEST_CASE_METHOD(RangeSearchTestFixture, "ModelCheck", + "[RangeSearchMainTest][BindingTests]" { arma::mat inputData, queryData; double minVal = 0, maxVal = 3; @@ -262,9 +268,9 @@ BOOST_AUTO_TEST_CASE(ModelCheck) vector> distances, distancetemp; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); if (!data::Load("iris_test.csv", queryData)) - BOOST_FAIL("Unable to load dataset iris_test.csv!"); + FAIL("Unable to load dataset iris_test.csv!"); SetInputParam("reference", move(inputData)); SetInputParam("min", minVal); @@ -292,7 +298,7 @@ BOOST_AUTO_TEST_CASE(ModelCheck) CheckMatrices(neighbors, neighborsTemp); CheckMatrices(distances, distancetemp); - BOOST_REQUIRE_EQUAL(ModelToString(outputModel), + REQUIRE(ModelToString(outputModel) == ModelToString(IO::GetParam("output_model"))); remove(neighborsFile.c_str()); @@ -303,11 +309,12 @@ BOOST_AUTO_TEST_CASE(ModelCheck) * Check that the models are different but the results are the same for three * different leaf size parameters. */ -BOOST_AUTO_TEST_CASE(LeafValueTesting) +TEST_CASE_METHOD(RangeSearchTestFixture, "LeafValueTesting", + "[RangeSearchMainTest][BindingTests]" { arma::mat inputData; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -349,7 +356,7 @@ BOOST_AUTO_TEST_CASE(LeafValueTesting) CheckMatrices(neighbors, neighborsTemp); CheckMatrices(distances, distancestemp); - BOOST_REQUIRE_NE(ModelToString(outputModel1), + REQUIRE(ModelToString(outputModel1) != ModelToString(IO::GetParam("output_model"))); if (i != leafSizes.size() - 1) @@ -367,7 +374,8 @@ BOOST_AUTO_TEST_CASE(LeafValueTesting) * different tree types. We use the default kd-tree as the base model to * compare against. */ -BOOST_AUTO_TEST_CASE(TreeTypeTesting) +TEST_CASE_METHOD(RangeSearchTestFixture, "TreeTypeTesting", + "[RangeSearchMainTest][BindingTests]" { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -381,9 +389,9 @@ BOOST_AUTO_TEST_CASE(TreeTypeTesting) "max-rp", "ub", "oct"}; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); if (!data::Load("iris_test.csv", queryData)) - BOOST_FAIL("Unable to load dataset iris_test.csv!"); + FAIL("Unable to load dataset iris_test.csv!"); // Define base parameters with the kd-tree. SetInputParam("tree_type", trees[0]); @@ -403,9 +411,9 @@ BOOST_AUTO_TEST_CASE(TreeTypeTesting) for (size_t i = 1; i < trees.size(); ++i) { if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); if (!data::Load("iris_test.csv", queryData)) - BOOST_FAIL("Unable to load dataset iris_test.csv!"); + FAIL("Unable to load dataset iris_test.csv!"); SetInputParam("min", minVal); SetInputParam("max", maxVal); @@ -422,7 +430,7 @@ BOOST_AUTO_TEST_CASE(TreeTypeTesting) CheckMatrices(neighbors, neighborsTemp); CheckMatrices(distances, distancestemp); - BOOST_REQUIRE_NE(ModelToString(outputModel1), + REQUIRE(ModelToString(outputModel1) != ModelToString(IO::GetParam("output_model"))); if (i != trees.size() - 1) @@ -439,7 +447,8 @@ BOOST_AUTO_TEST_CASE(TreeTypeTesting) * Project the data onto a random basis and ensure that this gives identical * results to non-projected data but different models. */ -BOOST_AUTO_TEST_CASE(RandomBasisTesting) +TEST_CASE_METHOD(RangeSearchTestFixture, "RandomBasisTesting", + "[RangeSearchMainTest][BindingTests]" { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -447,9 +456,9 @@ BOOST_AUTO_TEST_CASE(RandomBasisTesting) arma::mat queryData, inputData; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); if (!data::Load("iris_test.csv", queryData)) - BOOST_FAIL("Unable to load dataset iris_test.csv!"); + FAIL("Unable to load dataset iris_test.csv!"); SetInputParam("min", minVal); SetInputParam("max", maxVal); @@ -470,7 +479,7 @@ BOOST_AUTO_TEST_CASE(RandomBasisTesting) mlpackMain(); - BOOST_REQUIRE_NE(ModelToString(outputModel), + REQUIRE(ModelToString(outputModel) != ModelToString(IO::GetParam("output_model"))); delete outputModel; @@ -482,7 +491,8 @@ BOOST_AUTO_TEST_CASE(RandomBasisTesting) /** * Ensure that naive mode gives the same result, but different models. */ -BOOST_AUTO_TEST_CASE(NaiveModeTest) +TEST_CASE_METHOD(RangeSearchTestFixture, "NaiveModeTest", + "[RangeSearchMainTest][BindingTests]" { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -493,9 +503,9 @@ BOOST_AUTO_TEST_CASE(NaiveModeTest) vector> distances, distancestemp; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); if (!data::Load("iris_test.csv", queryData)) - BOOST_FAIL("Unable to load dataset iris_test.csv!"); + FAIL("Unable to load dataset iris_test.csv!"); SetInputParam("min", minVal); SetInputParam("max", maxVal); @@ -524,7 +534,7 @@ BOOST_AUTO_TEST_CASE(NaiveModeTest) CheckMatrices(neighbors, neighborsTemp); CheckMatrices(distances, distancestemp); - BOOST_REQUIRE_NE(ModelToString(outputModel), + REQUIRE(ModelToString(outputModel) != ModelToString(IO::GetParam("output_model"))); delete outputModel; @@ -536,7 +546,8 @@ BOOST_AUTO_TEST_CASE(NaiveModeTest) /** * Ensure that single-tree mode gives the same result but different models. */ -BOOST_AUTO_TEST_CASE(SingleModeTest) +TEST_CASE_METHOD(RangeSearchTestFixture, "SingleModeTest", + "[RangeSearchMainTest][BindingTests]" { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -547,9 +558,9 @@ BOOST_AUTO_TEST_CASE(SingleModeTest) vector> distances, distancestemp; if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Unable to load dataset iris.csv!"); + FAIL("Unable to load dataset iris.csv!"); if (!data::Load("iris_test.csv", queryData)) - BOOST_FAIL("Unable to load dataset iris_test.csv!"); + FAIL("Unable to load dataset iris_test.csv!"); SetInputParam("min", minVal); SetInputParam("max", maxVal); @@ -577,7 +588,7 @@ BOOST_AUTO_TEST_CASE(SingleModeTest) CheckMatrices(neighbors, neighborsTemp); CheckMatrices(distances, distancestemp); - BOOST_REQUIRE_NE(ModelToString(outputModel), + REQUIRE(ModelToString(outputModel) != ModelToString(IO::GetParam("output_model"))); delete outputModel; @@ -585,5 +596,3 @@ BOOST_AUTO_TEST_CASE(SingleModeTest) remove(neighborsFile.c_str()); remove(distanceFile.c_str()); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/main_tests/range_search_utils.hpp b/src/mlpack/tests/main_tests/range_search_utils.hpp index 8f1385eafb..f628b741ff 100644 --- a/src/mlpack/tests/main_tests/range_search_utils.hpp +++ b/src/mlpack/tests/main_tests/range_search_utils.hpp @@ -12,10 +12,10 @@ #ifndef MLPACK_TESTS_MAIN_TESTS_RANGE_SEARCH_TEST_UTILS_HPP #define MLPACK_TESTS_MAIN_TESTS_RANGE_SEARCH_TEST_UTILS_HPP -#include #include #include #include +#include "../catch.hpp" /** * Convert a model to a string using the text_oarchive of boost::serialization. @@ -42,15 +42,15 @@ inline void CheckMatrices(std::vector>& vec1, std::vector>& vec2, const double tolerance = 1e-3) { - BOOST_REQUIRE_EQUAL(vec1.size() , vec2.size()); + REQUIRE(vec1.size() == vec2.size()); for (size_t i = 0; i < vec1.size(); ++i) { - BOOST_REQUIRE_EQUAL(vec1[i].size(), vec2[i].size()); + REQUIRE(vec1[i].size() == vec2[i].size()); std::sort(vec1[i].begin(), vec1[i].end()); std::sort(vec2[i].begin(), vec2[i].end()); for (size_t j = 0 ; j < vec1[i].size(); ++j) { - BOOST_REQUIRE_CLOSE(vec1[i][j], vec2[i][j], tolerance); + REQUIRE(vec1[i][j] == Approx(vec2[i][j]).epsilon(tolerance)); } } } @@ -64,15 +64,15 @@ inline void CheckMatrices(std::vector>& vec1, inline void CheckMatrices(std::vector>& vec1, std::vector>& vec2) { - BOOST_REQUIRE_EQUAL(vec1.size() , vec2.size()); + REQUIRE(vec1.size() == vec2.size()); for (size_t i = 0; i < vec1.size(); ++i) { - BOOST_REQUIRE_EQUAL(vec1[i].size(), vec2[i].size()); + REQUIRE(vec1[i].size() == vec2[i].size()); std::sort(vec1[i].begin(), vec1[i].end()); std::sort(vec2[i].begin(), vec2[i].end()); for (size_t j = 0; j < vec1[i].size(); ++j) { - BOOST_REQUIRE_EQUAL(vec1[i][j], vec2[i][j]); + REQUIRE(vec1[i][j] == vec2[i][j]); } } } From 256aabf6c3ced749952e37c5c2090c0f5b9b64b4 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Thu, 1 Oct 2020 23:15:52 +0530 Subject: [PATCH 03/11] errors fixed --- .../tests/main_tests/range_search_test.cpp | 26 +++++++++---------- src/mlpack/tests/range_search_test.cpp | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/mlpack/tests/main_tests/range_search_test.cpp b/src/mlpack/tests/main_tests/range_search_test.cpp index 552ff4eba4..b32478da23 100644 --- a/src/mlpack/tests/main_tests/range_search_test.cpp +++ b/src/mlpack/tests/main_tests/range_search_test.cpp @@ -41,7 +41,7 @@ struct RangeSearchTestFixture * Check that we have to specify a reference set or input model. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchNoReference", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { Log::Fatal.ignoreInput = true; REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error); @@ -52,7 +52,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchNoReference", * Check that we cannot pass an incorrect parameter. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchWrongParameter", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { string wrongString = "abc"; @@ -65,7 +65,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchWrongParameter", * Check that we have to specify a query if an input model is specified. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchInputModelNoQuery", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { arma::mat inputData; double minVal = 0, maxVal = 3; @@ -98,7 +98,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchInputModelNoQuery", * Check that we cannot specify a tree type which is not available or wrong. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchDifferentTree", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { arma::mat inputData; double minVal = 0, maxVal = 3; @@ -127,7 +127,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchDifferentTree", * Check that we cannot specify both a reference set and input model. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchBothReferenceAndModel", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { arma::mat inputData, queryData; double minVal = 0, maxVal = 3; @@ -165,7 +165,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchBothReferenceAndModel", * set is specified. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchTest", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { arma::mat x = {{0, 3, 3, 4, 3, 1}, {4, 4, 4, 5, 5, 2}, @@ -213,7 +213,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchTest", * when a query set is provided. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSeachTestwithQuery", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { arma::mat queryData = {{5, 3, 1}, {4, 2, 4}, {3, 1, 7}}; arma::mat x = {{0, 3, 3, 4, 3, 1}, @@ -258,7 +258,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSeachTestwithQuery", * it can be used again. */ TEST_CASE_METHOD(RangeSearchTestFixture, "ModelCheck", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { arma::mat inputData, queryData; double minVal = 0, maxVal = 3; @@ -310,7 +310,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "ModelCheck", * different leaf size parameters. */ TEST_CASE_METHOD(RangeSearchTestFixture, "LeafValueTesting", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { arma::mat inputData; if (!data::Load("iris.csv", inputData)) @@ -375,7 +375,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "LeafValueTesting", * compare against. */ TEST_CASE_METHOD(RangeSearchTestFixture, "TreeTypeTesting", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -448,7 +448,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "TreeTypeTesting", * results to non-projected data but different models. */ TEST_CASE_METHOD(RangeSearchTestFixture, "RandomBasisTesting", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -492,7 +492,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RandomBasisTesting", * Ensure that naive mode gives the same result, but different models. */ TEST_CASE_METHOD(RangeSearchTestFixture, "NaiveModeTest", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; @@ -547,7 +547,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "NaiveModeTest", * Ensure that single-tree mode gives the same result but different models. */ TEST_CASE_METHOD(RangeSearchTestFixture, "SingleModeTest", - "[RangeSearchMainTest][BindingTests]" + "[RangeSearchMainTest][BindingTests]") { string distanceFile = "distances.csv"; string neighborsFile = "neighbors.csv"; diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index b9e3f47c1c..2f40600405 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -1074,7 +1074,7 @@ TEST_CASE("EmptySearchTest", "[RangeSearchTest]") /** * Make sure things work right after Train() is called. */ -TEST_CASE("TrainTest", "[RangeSearchTest]") +TEST_CASE("RangeTrainTest", "[RangeSearchTest]") { RangeSearch<> empty; From d4c74c74ce4bd99748c99468339d3b742024a7d6 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Mon, 5 Oct 2020 00:24:05 +0530 Subject: [PATCH 04/11] fixed static code check --- src/mlpack/tests/range_search_test.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index 2f40600405..41185f7a8a 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -1104,7 +1104,8 @@ TEST_CASE("RangeTrainTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon(1e-7)); + REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon + (1e-7)); } } } @@ -1145,7 +1146,8 @@ TEST_CASE("TrainTreeTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon(1e-7)); + REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon + (1e-7)); } } } @@ -1199,7 +1201,8 @@ TEST_CASE("MoveConstructorMatrixTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == moveSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon(1e-7)); + REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon + (1e-7)); } } } @@ -1241,7 +1244,8 @@ TEST_CASE("MoveTrainTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == moveSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon(1e-7)); + REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon + (1e-7)); } } } @@ -1283,7 +1287,7 @@ TEST_CASE("RSModelTest", "[RangeSearchTest]") models[26] = RSModel(RSModel::TreeTypes::OCTREE, true); models[27] = RSModel(RSModel::TreeTypes::OCTREE, false); - for (size_t j = 0; j < 2; ++j) + for (size_t j = 0; j != 2; ++j) { // Get a baseline. RangeSearch<> rs(referenceData); @@ -1325,8 +1329,8 @@ TEST_CASE("RSModelTest", "[RangeSearchTest]") for (size_t l = 0; l < sorted[k].size(); ++l) { REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); - REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first).epsilon - (1e-7)); + REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first). + epsilon(1e-7)); } } } @@ -1369,7 +1373,7 @@ TEST_CASE("RSModelMonochromaticTest", "[RangeSearchTest]") models[26] = RSModel(RSModel::TreeTypes::OCTREE, true); models[27] = RSModel(RSModel::TreeTypes::OCTREE, false); - for (size_t j = 0; j < 2; ++j) + for (size_t j = 0; j != 2; ++j) { // Get a baseline. RangeSearch<> rs(referenceData); @@ -1408,8 +1412,8 @@ TEST_CASE("RSModelMonochromaticTest", "[RangeSearchTest]") for (size_t l = 0; l < sorted[k].size(); ++l) { REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); - REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first).epsilon - (1e-7)); + REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first). + epsilon(1e-7)); } } } From 403b11ebbe8ccbdcc1c651296224bc2341e2b7b4 Mon Sep 17 00:00:00 2001 From: Aakash kaushik Date: Tue, 6 Oct 2020 00:41:50 +0530 Subject: [PATCH 05/11] updating range_search_test with mlpack/master (#7) * softmin activation function added * shift added * shift changed for inputmax to inputmin * Test added for softmin forward function * errors fixed * suggested changes * forward function fixed * added softmin to HISTORY.md * forward result calculation source changed * space added in comment * backward function added * backward test function added, values left * Added WeightSize() to linear.hpp atrous_convolution.hpp add.hpp. * tests made similar to softmax * conflict fix * fixed HISTORY.md conflict * tests made similar to softmax * Update activation_functions_test.cpp * Removed header iostream * Apply suggestions from code review Co-authored-by: Marcus Edel Co-authored-by: Ryan Curtin Include bias term in linear layer. * catch2 for mean_shift_test.cpp * fixed backward function * reverted changes to main/mean_shift_test.cpp * corrected the test cases * main/mean_shift_test.cpp from boost to catch2 * migrated mean_shift_test from boost to catch2 * tests changed * tests changed * Test for WeightSetVisitor and WeightSizeVisitor * Fix common failures by increasing threshold * Typo fix * Auto Cancel build on new push and enable cache for build. * Windows fix. * Install R-bindings dependencies separately. * rcmdcheck doesn't for building mlpack_r_tarball. * Install roxygen2. * Specify platform in windows build. * Stop github actions running on a forked repo. * softmin activation function added shift added shift changed for inputmax to inputmin Test added for softmin forward function errors fixed suggested changes forward function fixed added softmin to HISTORY.md forward result calculation source changed space added in comment backward function added backward test function added, values left tests made similar to softmax conflict fix fixed HISTORY.md conflict tests made similar to softmax Update activation_functions_test.cpp Removed header iostream fixed backward function reverted changes to main/mean_shift_test.cpp corrected the test cases tests changed tests changed * Fix static issues * All static issue fixed (hopefully) * Migrate det and distribution test to catch2 Co-authored-by: Utkarsh Rai Co-authored-by: kartikdutt18 Co-authored-by: Yashwant Co-authored-by: Ryan Curtin Co-authored-by: kartikdutt18 <39593019+kartikdutt18@users.noreply.github.com> Co-authored-by: Ryan Birmingham Co-authored-by: jeffin143 --- .ci/windows-steps.yaml | 1 + .github/workflows/main.yml | 66 +- HISTORY.md | 2 + src/mlpack/methods/ann/layer/CMakeLists.txt | 2 + src/mlpack/methods/ann/layer/add.hpp | 3 + .../methods/ann/layer/atrous_convolution.hpp | 6 + src/mlpack/methods/ann/layer/layer.hpp | 1 + src/mlpack/methods/ann/layer/linear.hpp | 6 + src/mlpack/methods/ann/layer/softmin.hpp | 97 +++ src/mlpack/methods/ann/layer/softmin_impl.hpp | 61 ++ src/mlpack/tests/CMakeLists.txt | 8 +- .../tests/activation_functions_test.cpp | 72 ++ src/mlpack/tests/ann_layer_test.cpp | 201 +++--- src/mlpack/tests/ann_visitor_test.cpp | 34 + src/mlpack/tests/det_test.cpp | 469 ++++++------- src/mlpack/tests/distribution_test.cpp | 618 +++++++++--------- src/mlpack/tests/feedforward_network_test.cpp | 10 +- .../tests/main_tests/mean_shift_test.cpp | 69 +- src/mlpack/tests/mean_shift_test.cpp | 26 +- src/mlpack/tests/random_forest_test.cpp | 3 +- 20 files changed, 1055 insertions(+), 700 deletions(-) create mode 100644 src/mlpack/methods/ann/layer/softmin.hpp create mode 100644 src/mlpack/methods/ann/layer/softmin_impl.hpp diff --git a/.ci/windows-steps.yaml b/.ci/windows-steps.yaml index 069c6c5b46..69a33520a3 100644 --- a/.ci/windows-steps.yaml +++ b/.ci/windows-steps.yaml @@ -78,6 +78,7 @@ steps: msbuildVersion: $(MSBuildVersion) configuration: 'Release' msbuildArchitecture: 'x64' + platform: 'x64' msbuildArguments: /m /p:BuildInParallel=true maximumCpuCount: false clean: false diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8a4790897d..8640c26471 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,13 +8,31 @@ on: - master release: types: [published, created, edited] +name: R CMD check mlpack jobs: + cancel: + name: 'Cancel Previous Builds' + if: ${{ github.event_name == 'pull_request' && github.repository == 'mlpack/mlpack' }} + runs-on: ubuntu-latest + timeout-minutes: 3 + steps: + - name: Get all workflow ids and set to env variable + run: echo ::set-env name=WORKFLOW_IDS_TO_CANCEL::$(curl https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows -s | jq -r '.workflows | map(.id|tostring) | join(",")') + + - uses: styfle/cancel-workflow-action@0.5.0 + with: + workflow_id: ${{ env.WORKFLOW_IDS_TO_CANCEL }} + access_token: ${{ secrets.GITHUB_TOKEN }} + jobR: - name: mlpack-R + name: Build mlpack_r_tarball + if: ${{ github.repository == 'mlpack/mlpack' }} runs-on: ubuntu-20.04 + outputs: r_bindings: ${{ steps.mlpack_version.outputs.mlpack_r_package }} + steps: - uses: actions/checkout@v2 @@ -27,16 +45,35 @@ jobs: MLPACK_VERSION_VALUE=${MLPACK_VERSION_MAJOR}.${MLPACK_VERSION_MINOR}.${MLPACK_VERSION_PATCH} echo ::set-output name=mlpack_r_package::$(echo mlpack_"$MLPACK_VERSION_VALUE".tar.gz) + - uses: r-lib/actions/setup-r@master + with: + r-version: release + + - name: Query dependencies + run: | + cp src/mlpack/bindings/R/mlpack/DESCRIPTION.in DESCRIPTION + Rscript -e "install.packages('remotes')" -e "saveRDS(remotes::dev_package_deps(dependencies = TRUE), 'depends.Rds')" + + - name: Cache R packages + if: runner.os != 'Windows' + uses: actions/cache@v1 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-r-release-${{ hashFiles('depends.Rds') }} + restore-keys: ${{ runner.os }}-r-release- + - name: Install Build Dependencies run: | sudo apt-get update sudo apt-get install -y --allow-unauthenticated libopenblas-dev liblapack-dev g++ libboost-all-dev curl https://data.kurg.org/armadillo-8.400.0.tar.xz | tar -xvJ && cd armadillo* cmake . && make && sudo make install && cd .. - sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran40/' - sudo apt-get -y update - sudo apt-get install -y r-base-core - sudo Rscript -e "install.packages(c('Rcpp', 'RcppArmadillo', 'RcppEnsmallen', 'BH', 'roxygen2', 'testthat'))" + + - name: Install R-bindings dependencies + run: | + remotes::install_deps(dependencies = TRUE) + remotes::install_cran("roxygen2") + shell: Rscript {0} - name: CMake run: | @@ -58,6 +95,7 @@ jobs: runs-on: ${{ matrix.config.os }} name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + if: ${{ github.repository == 'mlpack/mlpack' }} strategy: fail-fast: false @@ -74,6 +112,8 @@ jobs: R_CHECK_ARGS: "--no-build-vignettes" _R_CHECK_FORCE_SUGGESTS: 0 R_REMOTES_NO_ERRORS_FROM_WARNINGS: true + RSPM: ${{ matrix.config.rspm }} + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/download-artifact@v2 @@ -86,10 +126,22 @@ jobs: - uses: r-lib/actions/setup-pandoc@master + - name: Query dependencies + run: Rscript -e "install.packages('remotes')" -e "saveRDS(remotes::dev_package_deps('${{ needs.jobR.outputs.r_bindings }}', dependencies = TRUE), 'depends.Rds')" + + - name: Cache R packages + if: runner.os != 'Windows' + uses: actions/cache@v1 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{ hashFiles('depends.Rds') }} + restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}- + - name: Install dependencies run: | - Rscript -e "install.packages('remotes')" -e "remotes::install_cran('rcmdcheck')" - Rscript -e "install.packages(c('Rcpp', 'RcppArmadillo', 'RcppEnsmallen', 'BH', 'roxygen2', 'testthat'))" + remotes::install_deps('${{ needs.jobR.outputs.r_bindings }}', dependencies = TRUE) + remotes::install_cran("rcmdcheck") + shell: Rscript {0} - name: Check run: Rscript -e "rcmdcheck::rcmdcheck('${{ needs.jobR.outputs.r_bindings }}', args = c('--no-manual','--as-cran'), error_on = 'warning', check_dir = 'check')" diff --git a/HISTORY.md b/HISTORY.md index d7a2437e9e..5acdedcb4f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,8 @@ ###### ????-??-?? * Added Mean Absolute Percentage Error. + * Added Softmin activation function as layer in ann/layer. + ### mlpack 3.4.1 ###### 2020-09-07 * Fix incorrect parsing of required matrix/model parameters for command-line diff --git a/src/mlpack/methods/ann/layer/CMakeLists.txt b/src/mlpack/methods/ann/layer/CMakeLists.txt index 34ea03c6a7..b4726b0c6f 100644 --- a/src/mlpack/methods/ann/layer/CMakeLists.txt +++ b/src/mlpack/methods/ann/layer/CMakeLists.txt @@ -116,6 +116,8 @@ set(SOURCES celu_impl.hpp softshrink.hpp softshrink_impl.hpp + softmin.hpp + softmin_impl.hpp ) # Add directory name to sources. diff --git a/src/mlpack/methods/ann/layer/add.hpp b/src/mlpack/methods/ann/layer/add.hpp index b3f95dbbcc..42b27809b8 100644 --- a/src/mlpack/methods/ann/layer/add.hpp +++ b/src/mlpack/methods/ann/layer/add.hpp @@ -100,6 +100,9 @@ class Add //! Get the output size. size_t OutputSize() const { return outSize; } + //! Get the size of weights. + size_t WeightSize() const { return outSize; } + /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/atrous_convolution.hpp b/src/mlpack/methods/ann/layer/atrous_convolution.hpp index b2a8f497e6..b3dfd1ce85 100644 --- a/src/mlpack/methods/ann/layer/atrous_convolution.hpp +++ b/src/mlpack/methods/ann/layer/atrous_convolution.hpp @@ -257,6 +257,12 @@ class AtrousConvolution //! Modify the internal Padding layer. ann::Padding<>& Padding() { return padding; } + //! Get size of the weight matrix. + size_t WeightSize() const + { + return (outSize * inSize * kernelWidth * kernelHeight) + outSize; + } + /** * Serialize the layer. */ diff --git a/src/mlpack/methods/ann/layer/layer.hpp b/src/mlpack/methods/ann/layer/layer.hpp index d005d1eb42..947395fd6b 100644 --- a/src/mlpack/methods/ann/layer/layer.hpp +++ b/src/mlpack/methods/ann/layer/layer.hpp @@ -66,6 +66,7 @@ #include "sequential.hpp" #include "softshrink.hpp" #include "softmax.hpp" +#include "softmin.hpp" #include "spatial_dropout.hpp" #include "subview.hpp" #include "transposed_convolution.hpp" diff --git a/src/mlpack/methods/ann/layer/linear.hpp b/src/mlpack/methods/ann/layer/linear.hpp index 1930181654..6dfd719d5f 100644 --- a/src/mlpack/methods/ann/layer/linear.hpp +++ b/src/mlpack/methods/ann/layer/linear.hpp @@ -146,6 +146,12 @@ class Linear //! Modify the bias weights of the layer. OutputDataType& Bias() { return bias; } + //! Get the size of the weights. + size_t WeightSize() const + { + return (inSize * outSize) + outSize; + } + /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/softmin.hpp b/src/mlpack/methods/ann/layer/softmin.hpp new file mode 100644 index 0000000000..a7b882c942 --- /dev/null +++ b/src/mlpack/methods/ann/layer/softmin.hpp @@ -0,0 +1,97 @@ +/** + * @file methods/ann/layer/softmin.hpp + * @author Aakash Kaushik + * + * Definition of the Softmin class. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ + +#ifndef MLPACK_METHODS_ANN_LAYER_SOFTMIN_HPP +#define MLPACK_METHODS_ANN_LAYER_SOFTMIN_HPP + +#include + +namespace mlpack { +namespace ann /** Artificial Neural Network. */ { + +/** + * Implementation of the Softmin layer. The Softmin function takes as a input + * a vector of K real numbers, rescaling them so that the elements of the + * K-dimensional output vector lie in the range [0, 1] and sum to 1. + * + * @tparam InputDataType Type of the input data (arma::colvec, arma::mat, + * arma::sp_mat or arma::cube). + * @tparam OutputDataType Type of the output data (arma::colvec, arma::mat, + * arma::sp_mat or arma::cube). + */ +template < + typename InputDataType = arma::mat, + typename OutputDataType = arma::mat +> +class Softmin +{ + public: + /** + * Create the Softmin object. + */ + Softmin(); + + /** + * Ordinary feed forward pass of a neural network, evaluating the function + * f(x) by propagating the activity forward through f. + * + * @param input Input data used for evaluating the specified function. + * @param output Resulting output activation. + */ + template + void Forward(const InputType& input, OutputType& output); + + /** + * Ordinary feed backward pass of a neural network, calculating the function + * f(x) by propagating x backwards through f. Using the results from the feed + * forward pass. + * + * @param input The propagated input activation. + * @param gy The backpropagated error. + * @param g The calculated gradient. + */ + template + void Backward(const arma::Mat& input, + const arma::Mat& gy, + arma::Mat& g); + + //! Get the output parameter. + OutputDataType& OutputParameter() const { return outputParameter; } + //! Modify the output parameter. + OutputDataType& OutputParameter() { return outputParameter; } + + //! Get the delta. + InputDataType& Delta() const { return delta; } + //! Modify the delta. + InputDataType& Delta() { return delta; } + + /** + * Serialize the layer. + */ + template + void serialize(Archive& /* ar */, const unsigned int /* version */); + + private: + //! Locally-stored delta object. + OutputDataType delta; + + //! Locally stored output parameter object. + OutputDataType outputParameter; +}; // class Softmin + +} // namespace ann +} // namespace mlpack + +// Include implementation. +#include "softmin_impl.hpp" + +#endif diff --git a/src/mlpack/methods/ann/layer/softmin_impl.hpp b/src/mlpack/methods/ann/layer/softmin_impl.hpp new file mode 100644 index 0000000000..7693ca11dd --- /dev/null +++ b/src/mlpack/methods/ann/layer/softmin_impl.hpp @@ -0,0 +1,61 @@ +/** + * @file methods/ann/layer/softmin_impl.hpp + * @author Aakash Kaushik + * + * Implementation of the Softmin class. + * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. + */ +#ifndef MLPACK_METHODS_ANN_LAYER_SOFTMIN_IMPL_HPP +#define MLPACK_METHODS_ANN_LAYER_SOFTMIN_IMPL_HPP + +// In case it hasn't yet been included. +#include "softmin.hpp" + +namespace mlpack { +namespace ann /** Artificial Neural Network. */ { + +template +Softmin::Softmin() +{ + // Nothing to do here. +} + +template +template +void Softmin::Forward( + const InputType& input, + OutputType& output) +{ + InputType inputMin = arma::repmat(arma::min(input,0), input.n_rows, 1); + output = arma::repmat(arma::log(arma::sum( + arma::exp(-(input - inputMin)),0)), input.n_rows, 1); + output = arma::exp(-(input - inputMin) - output); +} + +template +template +void Softmin::Backward( + const arma::Mat& input, + const arma::Mat& gy, + arma::Mat& g) +{ + g = input % (gy - arma::repmat(arma::sum(gy % input), input.n_rows, 1)); +} + +template +template +void Softmin::serialize( + Archive& /* ar */, + const unsigned int /* version */) +{ + // Nothing to do here. +} + +} // namespace ann +} // namespace mlpack + +#endif diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index fae84ae9a8..b273dd3e4e 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -8,8 +8,6 @@ add_executable(mlpack_test io_test.cpp cosine_tree_test.cpp dcgan_test.cpp - det_test.cpp - distribution_test.cpp drusilla_select_test.cpp emst_test.cpp fastmks_test.cpp @@ -36,7 +34,6 @@ add_executable(mlpack_test math_test.cpp matrix_completion_test.cpp maximal_inputs_test.cpp - mean_shift_test.cpp metric_test.cpp mlpack_test.cpp mock_categorical_data.hpp @@ -92,7 +89,6 @@ add_executable(mlpack_test main_tests/local_coordinate_coding_test.cpp main_tests/logistic_regression_test.cpp main_tests/lsh_test.cpp - main_tests/mean_shift_test.cpp main_tests/nbc_test.cpp main_tests/nmf_test.cpp main_tests/perceptron_test.cpp @@ -122,6 +118,8 @@ add_executable(mlpack_catch_test dbscan_test.cpp decision_stump_test.cpp decision_tree_test.cpp + det_test.cpp + distribution_test.cpp feedforward_network_test.cpp image_load_test.cpp imputation_test.cpp @@ -135,6 +133,7 @@ add_executable(mlpack_catch_test load_save_test.cpp loss_functions_test.cpp main.cpp + mean_shift_test.cpp nca_test.cpp one_hot_encoding_test.cpp pca_test.cpp @@ -168,6 +167,7 @@ add_executable(mlpack_catch_test main_tests/kmeans_test.cpp main_tests/knn_test.cpp main_tests/linear_regression_test.cpp + main_tests/mean_shift_test.cpp main_tests/nca_test.cpp main_tests/pca_test.cpp main_tests/preprocess_binarize_test.cpp diff --git a/src/mlpack/tests/activation_functions_test.cpp b/src/mlpack/tests/activation_functions_test.cpp index 2c1fe63398..9ee1ebcaf9 100644 --- a/src/mlpack/tests/activation_functions_test.cpp +++ b/src/mlpack/tests/activation_functions_test.cpp @@ -558,6 +558,58 @@ void CheckCELUDerivativeCorrect(const arma::colvec input, } } +/** + * Implementation of the Softmin activation function test. The function is + * implemented as Softmin layer in the file softmin.hpp. + * + * @param input Input data used for evaluating the Softmin activation function. + * @param target Target data used to evaluate the Softmin activation. + */ +void CheckSoftminActivationCorrect(const arma::colvec input, + const arma::colvec target) +{ + // Initialize Softmin object. + Softmin<> softmin; + + // Test the activation function using the entire vector as input. + arma::colvec activations; + softmin.Forward(input,activations); + for (size_t i = 0; i < activations.n_elem; ++i) + { + REQUIRE(activations.at(i) == Approx(target.at(i)).epsilon(1e-5)); + } +} + +/** + * Implementation of the Softmin activation function derivative test. + * The function is implemented as Softmin layer in the file softmin.hpp. + * + * @param input Input data used for evaluating the Softmin activation function. + * @param target Target data used to evaluate the Softmin activation. + */ +void CheckSoftminDerivativeCorrect(const arma::colvec input, + const arma::colvec target) +{ + // Initialize Softmin object. + Softmin<> softmin; + + // Test the calculation of the derivatives using the entire vector as input. + arma::colvec derivatives, activations; + + // This error vector will be set to [[1.0],[0.0],[1.0],[0.0]] + // to get the derivatives. + arma::colvec error = arma::ones(input.n_elem); + error(1) = 0.0; + error(3) = 0.0; + softmin.Forward(input, activations); + softmin.Backward(activations, error, derivatives); + for (size_t i = 0; i < derivatives.n_elem; ++i) + { + REQUIRE(derivatives.at(i) == Approx(target.at(i)).epsilon(1e-5)); + } + +} + /** * Basic test of the tanh function. */ @@ -1063,3 +1115,23 @@ TEST_CASE("GaussianFunctionTest", "[ActivationFunctionsTest]") CheckDerivativeCorrect(desiredActivations, desiredDerivatives); } + +/** + * Basic test of the Softmin function. + */ +TEST_CASE("SoftminFunctionTest", "[ActivationFunctionsTest]") +{ + const arma::colvec activationData("4.2 2.4 7.0 6.4"); + + // Hand-calculated Values. + const arma::colvec desiredActivations("0.1384799751 0.8377550303 \ + 0.008420976 0.0153440186"); + + const arma::colvec desiredDerivatives("0.1181371351 -0.12306701070 \ + 0.0071839266 -0.0022540509"); + + CheckSoftminActivationCorrect(activationData, + desiredActivations); + CheckSoftminDerivativeCorrect(activationData, + desiredDerivatives); +} diff --git a/src/mlpack/tests/ann_layer_test.cpp b/src/mlpack/tests/ann_layer_test.cpp index dfd1ecf091..37a5a5b192 100644 --- a/src/mlpack/tests/ann_layer_test.cpp +++ b/src/mlpack/tests/ann_layer_test.cpp @@ -87,11 +87,10 @@ TEST_CASE("GradientAddLayerTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -416,11 +415,10 @@ TEST_CASE("GradientLinearLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -508,13 +506,12 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + inSize(4), + outSize(1), + nPoints(2), + batchSize(4) { - const size_t inSize = 4; - const size_t outSize = 1; - const size_t nPoints = 2; - const size_t batchSize = 4; - input = arma::randu(inSize * nPoints, batchSize); target = arma::zeros(outSize * nPoints, batchSize); target(0, 0) = 1; @@ -545,6 +542,10 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]") FFN, RandomInitialization>* model; arma::mat input, target; + const size_t inSize; + const size_t outSize; + const size_t nPoints; + const size_t batchSize; } function; REQUIRE(CheckGradient(function) <= 1e-7); @@ -591,11 +592,10 @@ TEST_CASE("GradientNoisyLinearLayerTest", "[ANNLayerTest]") // Noisy linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -695,11 +695,10 @@ TEST_CASE("GradientLinearNoBiasLayerTest", "[ANNLayerTest]") // LinearNoBias function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -797,11 +796,10 @@ TEST_CASE("GradientFlexibleReLULayerTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(2, 1)), + target(arma::mat("1")) { - input = arma::randu(2, 1); - target = arma::mat("1"); - model = new FFN, RandomInitialization>( NegativeLogLikelihood<>(), RandomInitialization(0.1, 0.5)); @@ -1017,10 +1015,10 @@ TEST_CASE("GradientLSTMLayerTest", "[ANNLayerTest]") // LSTM function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(1, 1, 5)), + target(arma::ones(1, 1, 5)) { - input = arma::randu(1, 1, 5); - target.ones(1, 1, 5); const size_t rho = 5; model = new RNN >(rho); @@ -1122,10 +1120,10 @@ TEST_CASE("GradientFastLSTMLayerTest", "[ANNLayerTest]") // Fast LSTM function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(1, 1, 5)), + target(arma::ones(1, 1, 5)) { - input = arma::randu(1, 1, 5); - target = arma::ones(1, 1, 5); const size_t rho = 5; model = new RNN >(rho); @@ -1391,10 +1389,10 @@ TEST_CASE("GradientGRULayerTest", "[ANNLayerTest]") // GRU function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(1, 1, 5)), + target(arma::ones(1, 1, 5)) { - input = arma::randu(1, 1, 5); - target = arma::ones(1, 1, 5); const size_t rho = 5; model = new RNN >(rho); @@ -1631,11 +1629,10 @@ TEST_CASE("GradientConcatLayerTest", "[ANNLayerTest]") // Concat function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -1700,11 +1697,10 @@ TEST_CASE("GradientConcatenateLayerTest", "[ANNLayerTest]") // Concatenate function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -1905,11 +1901,10 @@ TEST_CASE("GradientSoftmaxTest", "[ANNLayerTest]") // Softmax function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1; 0")) { - input = arma::randu(10, 1); - target = arma::mat("1; 0"); - model = new FFN, RandomInitialization>; model->Predictors() = input; model->Responses() = target; @@ -2109,12 +2104,10 @@ TEST_CASE("GradientBatchNormTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randn(32, 2048)), + target(arma::ones(1, 2048)) { - input = arma::randn(32, 2048); - arma::mat target; - target.ones(1, 2048); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2184,12 +2177,11 @@ TEST_CASE("GradientVirtualBatchNormTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randn(5, 256)), + target(arma::ones(1, 256)) { - input = arma::randn(5, 256); arma::mat referenceBatch = arma::mat(input.memptr(), input.n_rows, 16); - arma::mat target; - target.ones(1, 256); model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; @@ -2247,12 +2239,10 @@ TEST_CASE("MiniBatchDiscriminationTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randn(5, 4)), + target(arma::ones(1, 4)) { - input = arma::randn(5, 4); - arma::mat target; - target.ones(1, 4); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2427,11 +2417,10 @@ TEST_CASE("GradientTransposedConvolutionLayerTest", "[ANNLayerTest]") { struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::linspace(0, 35, 36)), + target(arma::mat("1")) { - input = arma::linspace(0, 35, 36); - target = arma::mat("1"); - model = new FFN, RandomInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2544,11 +2533,10 @@ TEST_CASE("GradientAtrousConvolutionLayerTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::linspace(0, 35, 36)), + target(arma::mat("1")) { - input = arma::linspace(0, 35, 36); - target = arma::mat("1"); - model = new FFN, RandomInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2575,7 +2563,7 @@ TEST_CASE("GradientAtrousConvolutionLayerTest", "[ANNLayerTest]") arma::mat input, target; } function; - // TODO: this tolerance seems far higher than necessary. The implementation + // TODO: this tolerance seems far higher than necessary. The implementation // should be checked. REQUIRE(CheckGradient(function) <= 0.2); } @@ -2726,12 +2714,10 @@ TEST_CASE("GradientLayerNormTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randn(10, 256)), + target(arma::ones(1, 256)) { - input = arma::randn(10, 256); - arma::mat target; - target.ones(1, 256); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3048,11 +3034,10 @@ TEST_CASE("GradientReparametrizationLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3092,11 +3077,10 @@ TEST_CASE("GradientReparametrizationLayerBetaTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 2)), + target(arma::mat("1 1")) { - input = arma::randu(10, 2); - target = arma::mat("1 1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3248,11 +3232,10 @@ TEST_CASE("GradientHighwayLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(5, 1)), + target(arma::mat("1")) { - input = arma::randu(5, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3300,11 +3283,10 @@ TEST_CASE("GradientSequentialLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3351,11 +3333,10 @@ TEST_CASE("GradientWeightNormLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randu(10, 1)), + target(arma::mat("1")) { - input = arma::randu(10, 1); - target = arma::mat("1"); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -4185,12 +4166,10 @@ TEST_CASE("GradientBatchNormWithMiniBatchesTest", "[ANNLayerTest]") { struct GradientFunction { - GradientFunction() + GradientFunction() : + input(arma::randn(16, 1024)), + target(arma::ones(1, 1024)) { - input = arma::randn(16, 1024); - arma::mat target; - target.ones(1, 1024); - model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -4683,7 +4662,13 @@ TEST_CASE("GradientMultiheadAttentionTest", "[ANNLayerTest]") { struct GradientFunction { - GradientFunction() + GradientFunction() : + tgtSeqLen(2), + srcSeqLen(2), + embedDim(4), + nHeads(2), + vocabSize(5), + batchSize(2) { input = arma::randu(embedDim * (tgtSeqLen + 2 * srcSeqLen), batchSize); target = arma::zeros(vocabSize, batchSize); @@ -4736,13 +4721,13 @@ TEST_CASE("GradientMultiheadAttentionTest", "[ANNLayerTest]") MultiheadAttention<>* attnModule; arma::mat input, target, attnMask, keyPaddingMask; - const size_t tgtSeqLen = 2; - const size_t srcSeqLen = 2; - const size_t embedDim = 4; - const size_t nHeads = 2; - const size_t vocabSize = 5; - const size_t batchSize = 2; + const size_t tgtSeqLen; + const size_t srcSeqLen; + const size_t embedDim; + const size_t nHeads; + const size_t vocabSize; + const size_t batchSize; } function; - REQUIRE(CheckGradient(function) <= 2e-06); + REQUIRE(CheckGradient(function) <= 3e-06); } diff --git a/src/mlpack/tests/ann_visitor_test.cpp b/src/mlpack/tests/ann_visitor_test.cpp index 1b01308ff3..ccf3cca35f 100644 --- a/src/mlpack/tests/ann_visitor_test.cpp +++ b/src/mlpack/tests/ann_visitor_test.cpp @@ -52,3 +52,37 @@ TEST_CASE("BiasSetVisitorTest", "[ANNVisitorTest]") boost::apply_visitor(DeleteVisitor(), linear); } + +/** + * Test that WeightSetVisitor works properly. + */ +TEST_CASE("WeightSetVisitorTest", "[ANNVisitorTest]") +{ + size_t randomSize = arma::randi(arma::distr_param(1, 100)); + + LayerTypes<> linear = new Linear<>(randomSize, randomSize); + + arma::mat layerWeights(randomSize * randomSize + randomSize, 1); + layerWeights.zeros(); + + size_t setWeights = boost::apply_visitor(WeightSetVisitor(layerWeights, 0), + linear); + + REQUIRE(setWeights == randomSize * randomSize + randomSize); +} + +/** + * Test that WeightSizeVisitor works properly. + */ +TEST_CASE("WeightSizeVisitorTest", "[ANNVisitorTest]") +{ + size_t randomSize = arma::randi(arma::distr_param(1, 100)); + + LayerTypes<> linear = new Linear<>(randomSize, randomSize); + + size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), + linear); + + REQUIRE(weightSize == randomSize * randomSize + randomSize); +} + diff --git a/src/mlpack/tests/det_test.cpp b/src/mlpack/tests/det_test.cpp index 4a16bbd060..c0989768eb 100644 --- a/src/mlpack/tests/det_test.cpp +++ b/src/mlpack/tests/det_test.cpp @@ -11,8 +11,7 @@ * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #include -#include -#include "test_tools.hpp" +#include "catch.hpp" // This trick does not work on Windows. We will have to comment out the tests // that depend on it. @@ -33,13 +32,11 @@ using namespace mlpack; using namespace mlpack::det; using namespace std; -BOOST_AUTO_TEST_SUITE(DETTest); - // Tests for the private functions. We cannot perform these if we are on // Windows because we cannot make private functions accessible using the macro // trick above. #ifndef _WIN32 -BOOST_AUTO_TEST_CASE(TestGetMaxMinVals) +TEST_CASE("TestGetMaxMinVals", "[DETTest]") { arma::mat testData(3, 5); @@ -49,15 +46,15 @@ BOOST_AUTO_TEST_CASE(TestGetMaxMinVals) DTree tree(testData); - BOOST_REQUIRE_EQUAL(tree.MaxVals()[0], 7); - BOOST_REQUIRE_EQUAL(tree.MinVals()[0], 3); - BOOST_REQUIRE_EQUAL(tree.MaxVals()[1], 7); - BOOST_REQUIRE_EQUAL(tree.MinVals()[1], 0); - BOOST_REQUIRE_EQUAL(tree.MaxVals()[2], 8); - BOOST_REQUIRE_EQUAL(tree.MinVals()[2], 1); + REQUIRE(tree.MaxVals()[0] == 7); + REQUIRE(tree.MinVals()[0] == 3); + REQUIRE(tree.MaxVals()[1] == 7); + REQUIRE(tree.MinVals()[1] == 0); + REQUIRE(tree.MaxVals()[2] == 8); + REQUIRE(tree.MinVals()[2] == 1); } -BOOST_AUTO_TEST_CASE(TestComputeNodeError) +TEST_CASE("TestComputeNodeError", "[DETTest]") { arma::vec maxVals("7 7 8"); arma::vec minVals("3 0 1"); @@ -65,17 +62,18 @@ BOOST_AUTO_TEST_CASE(TestComputeNodeError) DTree testDTree(maxVals, minVals, 5); double trueNodeError = -log(4.0) - log(7.0) - log(7.0); - BOOST_REQUIRE_CLOSE((double) testDTree.logNegError, trueNodeError, 1e-10); + REQUIRE((double) testDTree.logNegError == + Approx(trueNodeError).epsilon(1e-12)); testDTree.start = 3; testDTree.end = 5; double nodeError = testDTree.LogNegativeError(5); trueNodeError = 2 * log(2.0 / 5.0) - log(4.0) - log(7.0) - log(7.0); - BOOST_REQUIRE_CLOSE(nodeError, trueNodeError, 1e-10); + REQUIRE(nodeError == Approx(trueNodeError).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestWithinRange) +TEST_CASE("TestWithinRange", "[DETTest]") { arma::vec maxVals("7 7 8"); arma::vec minVals("3 0 1"); @@ -85,14 +83,14 @@ BOOST_AUTO_TEST_CASE(TestWithinRange) arma::vec testQuery(3); testQuery << 4.5 << 2.5 << 2; - BOOST_REQUIRE_EQUAL(testDTree.WithinRange(testQuery), true); + REQUIRE(testDTree.WithinRange(testQuery) == true); testQuery << 8.5 << 2.5 << 2; - BOOST_REQUIRE_EQUAL(testDTree.WithinRange(testQuery), false); + REQUIRE(testDTree.WithinRange(testQuery) == false); } -BOOST_AUTO_TEST_CASE(TestFindSplit) +TEST_CASE("TestFindSplit", "[DETTest]") { arma::mat testData(3, 5); @@ -108,20 +106,21 @@ BOOST_AUTO_TEST_CASE(TestFindSplit) size_t trueDim = 2; double trueSplit = 5.5; double trueLeftError = 2 * log(2.0 / 5.0) - (log(7.0) + log(4.0) + log(4.5)); - double trueRightError = 2 * log(3.0 / 5.0) - (log(7.0) + log(4.0) + log(2.5)); + double trueRightError = 2 * log(3.0 / 5.0) - (log(7.0) + log(4.0) + + log(2.5)); testDTree.logVolume = log(7.0) + log(4.0) + log(7.0); - BOOST_REQUIRE(testDTree.FindSplit( + REQUIRE(testDTree.FindSplit( testData, obDim, obSplit, obLeftError, obRightError, 1)); - BOOST_REQUIRE(trueDim == obDim); - BOOST_REQUIRE_CLOSE(trueSplit, obSplit, 1e-10); + REQUIRE(trueDim == obDim); + REQUIRE(trueSplit == Approx(obSplit).epsilon(1e-12)); - BOOST_REQUIRE_CLOSE(trueLeftError, obLeftError, 1e-10); - BOOST_REQUIRE_CLOSE(trueRightError, obRightError, 1e-10); + REQUIRE(trueLeftError == Approx(obLeftError).epsilon(1e-12)); + REQUIRE(trueRightError == Approx(obRightError).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestSplitData) +TEST_CASE("TestSplitData", "[DETTest]") { arma::mat testData(3, 5); @@ -140,16 +139,16 @@ BOOST_AUTO_TEST_CASE(TestSplitData) size_t splitInd = testDTree.SplitData( testData, splitDim, trueSplitVal, oTest); - BOOST_REQUIRE_EQUAL(splitInd, 2); // 2 points on left side. + REQUIRE(splitInd == 2); // 2 points on left side. - BOOST_REQUIRE_EQUAL(oTest[0], 1); - BOOST_REQUIRE_EQUAL(oTest[1], 4); - BOOST_REQUIRE_EQUAL(oTest[2], 3); - BOOST_REQUIRE_EQUAL(oTest[3], 2); - BOOST_REQUIRE_EQUAL(oTest[4], 5); + REQUIRE(oTest[0] == 1); + REQUIRE(oTest[1] == 4); + REQUIRE(oTest[2] == 3); + REQUIRE(oTest[3] == 2); + REQUIRE(oTest[4] == 5); } -BOOST_AUTO_TEST_CASE(TestSparseFindSplit) +TEST_CASE("TestSparseFindSplit", "[DETTest]") { arma::mat realData(4, 7); @@ -173,17 +172,17 @@ BOOST_AUTO_TEST_CASE(TestSparseFindSplit) (log(7.0) + log(6.5) + log(8.0) + log(6.0)); testDTree.logVolume = log(7.0) + log(7.0) + log(8.0) + log(6.0); - BOOST_REQUIRE(testDTree.FindSplit( + REQUIRE(testDTree.FindSplit( testData, obDim, obSplit, obLeftError, obRightError, 1)); - BOOST_REQUIRE(trueDim == obDim); - BOOST_REQUIRE_CLOSE(trueSplit, obSplit, 1e-10); + REQUIRE(trueDim == obDim); + REQUIRE(trueSplit == Approx(obSplit).epsilon(1e-12)); - BOOST_REQUIRE_CLOSE(trueLeftError, obLeftError, 1e-10); - BOOST_REQUIRE_CLOSE(trueRightError, obRightError, 1e-10); + REQUIRE(trueLeftError == Approx(obLeftError).epsilon(1e-12)); + REQUIRE(trueRightError == Approx(obRightError).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestSparseSplitData) +TEST_CASE("TestSparseSplitData", "[DETTest]") { arma::mat realData(4, 7); @@ -205,22 +204,22 @@ BOOST_AUTO_TEST_CASE(TestSparseSplitData) size_t splitInd = testDTree.SplitData( testData, splitDim, trueSplitVal, oTest); - BOOST_REQUIRE_EQUAL(splitInd, 3); // 2 points on left side. + REQUIRE(splitInd == 3); // 2 points on left side. - BOOST_REQUIRE_EQUAL(oTest[0], 1); - BOOST_REQUIRE_EQUAL(oTest[1], 4); - BOOST_REQUIRE_EQUAL(oTest[2], 3); - BOOST_REQUIRE_EQUAL(oTest[3], 2); - BOOST_REQUIRE_EQUAL(oTest[4], 5); - BOOST_REQUIRE_EQUAL(oTest[5], 6); - BOOST_REQUIRE_EQUAL(oTest[6], 7); + REQUIRE(oTest[0] == 1); + REQUIRE(oTest[1] == 4); + REQUIRE(oTest[2] == 3); + REQUIRE(oTest[3] == 2); + REQUIRE(oTest[4] == 5); + REQUIRE(oTest[5] == 6); + REQUIRE(oTest[6] == 7); } #endif // Tests for the public functions. -BOOST_AUTO_TEST_CASE(TestGrow) +TEST_CASE("TestGrow", "[DETTest]") { arma::mat testData(3, 5); @@ -244,34 +243,36 @@ BOOST_AUTO_TEST_CASE(TestGrow) DTree testDTree(testData); double alpha = testDTree.Grow(testData, oTest, false, 2, 1); - BOOST_REQUIRE_EQUAL(oTest[0], 0); - BOOST_REQUIRE_EQUAL(oTest[1], 3); - BOOST_REQUIRE_EQUAL(oTest[2], 1); - BOOST_REQUIRE_EQUAL(oTest[3], 2); - BOOST_REQUIRE_EQUAL(oTest[4], 4); + REQUIRE(oTest[0] == 0); + REQUIRE(oTest[1] == 3); + REQUIRE(oTest[2] == 1); + REQUIRE(oTest[3] == 2); + REQUIRE(oTest[4] == 4); // Test the structure of the tree. - BOOST_REQUIRE(testDTree.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree.Right()->Right()->Right() == NULL); + REQUIRE(testDTree.Left()->Left() == NULL); + REQUIRE(testDTree.Left()->Right() == NULL); + REQUIRE(testDTree.Right()->Left()->Left() == NULL); + REQUIRE(testDTree.Right()->Left()->Right() == NULL); + REQUIRE(testDTree.Right()->Right()->Left() == NULL); + REQUIRE(testDTree.Right()->Right()->Right() == NULL); - BOOST_REQUIRE(testDTree.SubtreeLeaves() == 3); + REQUIRE(testDTree.SubtreeLeaves() == 3); - BOOST_REQUIRE(testDTree.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree.SplitDim() == 2); + REQUIRE(testDTree.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree.Right()->SplitDim() == 1); + REQUIRE(testDTree.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); // Test node errors for every node (these are private functions). #ifndef _WIN32 - BOOST_REQUIRE_CLOSE(testDTree.logNegError, rootError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.Left()->logNegError, lError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.Right()->logNegError, rError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.Right()->Left()->logNegError, rlError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.Right()->Right()->logNegError, rrError, 1e-10); + REQUIRE(testDTree.logNegError == Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.Left()->logNegError == Approx(lError).epsilon(1e-12)); + REQUIRE(testDTree.Right()->logNegError == Approx(rError).epsilon(1e-12)); + REQUIRE(testDTree.Right()->Left()->logNegError == + Approx(rlError).epsilon(1e-12)); + REQUIRE(testDTree.Right()->Right()->logNegError == + Approx(rrError).epsilon(1e-12)); #endif // Test alpha. @@ -281,10 +282,10 @@ BOOST_AUTO_TEST_CASE(TestGrow) rAlpha = std::log(-(std::exp(rError) - (std::exp(rlError) + std::exp(rrError)))); - BOOST_REQUIRE_CLOSE(alpha, min(rootAlpha, rAlpha), 1e-10); + REQUIRE(alpha == Approx(min(rootAlpha, rAlpha)).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestPruneAndUpdate) +TEST_CASE("TestPruneAndUpdate", "[DETTest]") { arma::mat testData(3, 5); @@ -298,18 +299,19 @@ BOOST_AUTO_TEST_CASE(TestPruneAndUpdate) double alpha = testDTree.Grow(testData, oTest, false, 2, 1); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); - BOOST_REQUIRE_CLOSE(alpha, numeric_limits::max(), 1e-10); - BOOST_REQUIRE(testDTree.SubtreeLeaves() == 1); + REQUIRE(alpha == Approx(numeric_limits::max()).epsilon(1e-12)); + REQUIRE(testDTree.SubtreeLeaves() == 1); double rootError = -log(4.0) - log(7.0) - log(7.0); - BOOST_REQUIRE_CLOSE(testDTree.LogNegError(), rootError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.SubtreeLeavesLogNegError(), rootError, 1e-10); - BOOST_REQUIRE(testDTree.Left() == NULL); - BOOST_REQUIRE(testDTree.Right() == NULL); + REQUIRE(testDTree.LogNegError() == Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.SubtreeLeavesLogNegError() == + Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.Left() == NULL); + REQUIRE(testDTree.Right() == NULL); } -BOOST_AUTO_TEST_CASE(TestComputeValue) +TEST_CASE("TestComputeValue", "[DETTest]") { arma::mat testData(3, 5); @@ -334,22 +336,22 @@ BOOST_AUTO_TEST_CASE(TestComputeValue) double d2 = (1.0 / 5.0) / exp(log(4.0) + log(0.5) + log(2.5)); double d3 = (2.0 / 5.0) / exp(log(4.0) + log(6.5) + log(2.5)); - BOOST_REQUIRE_CLOSE(d1, testDTree.ComputeValue(q1), 1e-10); - BOOST_REQUIRE_CLOSE(d2, testDTree.ComputeValue(q2), 1e-10); - BOOST_REQUIRE_CLOSE(d3, testDTree.ComputeValue(q3), 1e-10); - BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); + REQUIRE(d1 == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); + REQUIRE(d2 == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); + REQUIRE(d3 == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); + REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); double d = 1.0 / exp(log(4.0) + log(7.0) + log(7.0)); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q1), 1e-10); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q2), 1e-10); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q3), 1e-10); - BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); + REQUIRE(d == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); + REQUIRE(d == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); + REQUIRE(d == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); + REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestVariableImportance) +TEST_CASE("TestVariableImportance", "[DETTest]") { arma::mat testData(3, 5); @@ -377,12 +379,14 @@ BOOST_AUTO_TEST_CASE(TestVariableImportance) testDTree.ComputeVariableImportance(imps); - BOOST_REQUIRE_CLOSE((double) 0.0, imps[0], 1e-10); - BOOST_REQUIRE_CLOSE((double) (rError - (rlError + rrError)), imps[1], 1e-10); - BOOST_REQUIRE_CLOSE((double) (rootError - (lError + rError)), imps[2], 1e-10); + REQUIRE((double) 0.0 == Approx(imps[0]).epsilon(1e-12)); + REQUIRE((double) (rError - (rlError + rrError)) == + Approx(imps[1]).epsilon(1e-12)); + REQUIRE((double) (rootError - (lError + rError)) == + Approx(imps[2]).epsilon(1e-12)); } -BOOST_AUTO_TEST_CASE(TestSparsePruneAndUpdate) +TEST_CASE("TestSparsePruneAndUpdate", "[DETTest]") { arma::mat realData(3, 5); @@ -399,18 +403,19 @@ BOOST_AUTO_TEST_CASE(TestSparsePruneAndUpdate) double alpha = testDTree.Grow(testData, oTest, false, 2, 1); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); - BOOST_REQUIRE_CLOSE(alpha, numeric_limits::max(), 1e-10); - BOOST_REQUIRE(testDTree.SubtreeLeaves() == 1); + REQUIRE(alpha == Approx(numeric_limits::max()).epsilon(1e-12)); + REQUIRE(testDTree.SubtreeLeaves() == 1); double rootError = -log(4.0) - log(7.0) - log(7.0); - BOOST_REQUIRE_CLOSE(testDTree.LogNegError(), rootError, 1e-10); - BOOST_REQUIRE_CLOSE(testDTree.SubtreeLeavesLogNegError(), rootError, 1e-10); - BOOST_REQUIRE(testDTree.Left() == NULL); - BOOST_REQUIRE(testDTree.Right() == NULL); + REQUIRE(testDTree.LogNegError() == Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.SubtreeLeavesLogNegError() == + Approx(rootError).epsilon(1e-12)); + REQUIRE(testDTree.Left() == NULL); + REQUIRE(testDTree.Right() == NULL); } -BOOST_AUTO_TEST_CASE(TestSparseComputeValue) +TEST_CASE("TestSparseComputeValue", "[DETTest]") { arma::mat realData(3, 5); @@ -438,25 +443,25 @@ BOOST_AUTO_TEST_CASE(TestSparseComputeValue) double d2 = (1.0 / 5.0) / exp(log(4.0) + log(0.5) + log(2.5)); double d3 = (2.0 / 5.0) / exp(log(4.0) + log(6.5) + log(2.5)); - BOOST_REQUIRE_CLOSE(d1, testDTree.ComputeValue(q1), 1e-10); - BOOST_REQUIRE_CLOSE(d2, testDTree.ComputeValue(q2), 1e-10); - BOOST_REQUIRE_CLOSE(d3, testDTree.ComputeValue(q3), 1e-10); - BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); + REQUIRE(d1 == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); + REQUIRE(d2 == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); + REQUIRE(d3 == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); + REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); double d = 1.0 / exp(log(4.0) + log(7.0) + log(7.0)); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q1), 1e-10); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q2), 1e-10); - BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q3), 1e-10); - BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); + REQUIRE(d == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); + REQUIRE(d == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); + REQUIRE(d == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); + REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); } /** * These are not yet implemented. * -BOOST_AUTO_TEST_CASE(TestTagTree) +TEST_CASE("TestTagTree", "[DETTest]") { MatType testData(3, 5); @@ -469,7 +474,7 @@ BOOST_AUTO_TEST_CASE(TestTagTree) delete testDTree; } -BOOST_AUTO_TEST_CASE(TestFindBucket) +TEST_CASE("TestFindBucket", "[DETTest]") { MatType testData(3, 5); @@ -484,24 +489,24 @@ BOOST_AUTO_TEST_CASE(TestFindBucket) // Test functions in dt_utils.hpp -BOOST_AUTO_TEST_CASE(TestTrainer) +TEST_CASE("TestTrainer", "[DETTest]") { } -BOOST_AUTO_TEST_CASE(TestPrintVariableImportance) +TEST_CASE("TestPrintVariableImportance", "[DETTest]") { } -BOOST_AUTO_TEST_CASE(TestPrintLeafMembership) +TEST_CASE("TestPrintLeafMembership", "[DETTest]") { } */ // Test the copy constructor and the copy operator. -BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest) +TEST_CASE("CopyConstructorAndOperatorTest", "[DETTest]") { arma::mat testData(3, 5); @@ -544,76 +549,76 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest) delete testDTree; // Test the data of copied tree (using copy constructor). - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); + REQUIRE(testDTree2.MaxVals()[0] == maxVals0); + REQUIRE(testDTree2.MinVals()[0] == minVals0); + REQUIRE(testDTree2.MaxVals()[1] == maxVals1); + REQUIRE(testDTree2.MinVals()[1] == minVals1); + REQUIRE(testDTree2.MaxVals()[2] == maxVals2); + REQUIRE(testDTree2.MinVals()[2] == minVals2); // Test the data of the copied tree (using the copy operator). - BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[0], maxVals0); - BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[0], minVals0); - BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[1], maxVals1); - BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[1], minVals1); - BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[2], maxVals2); - BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[2], minVals2); + REQUIRE(testDTree3.MaxVals()[0] == maxVals0); + REQUIRE(testDTree3.MinVals()[0] == minVals0); + REQUIRE(testDTree3.MaxVals()[1] == maxVals1); + REQUIRE(testDTree3.MinVals()[1] == minVals1); + REQUIRE(testDTree3.MaxVals()[2] == maxVals2); + REQUIRE(testDTree3.MinVals()[2] == minVals2); // Test the structure of the tree copied using the copy constructor. - BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + REQUIRE(testDTree2.Left()->Left() == NULL); + REQUIRE(testDTree2.Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the structure of the tree copied using the copy operator. - BOOST_REQUIRE(testDTree3.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree3.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree3.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree3.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree3.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree3.Right()->Right()->Right() == NULL); + REQUIRE(testDTree3.Left()->Left() == NULL); + REQUIRE(testDTree3.Left()->Right() == NULL); + REQUIRE(testDTree3.Right()->Left()->Left() == NULL); + REQUIRE(testDTree3.Right()->Left()->Right() == NULL); + REQUIRE(testDTree3.Right()->Right()->Left() == NULL); + REQUIRE(testDTree3.Right()->Right()->Right() == NULL); // Test the data of the tree copied using the copy constructor. - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); - BOOST_REQUIRE(testDTree2.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); + REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); + REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); + REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); + REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); + REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); + REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); + REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); + REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); + REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); + REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); + REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); + REQUIRE(testDTree2.SplitDim() == 2); + REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree2.Right()->SplitDim() == 1); + REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); // Test the data of the tree copied using the copy operator. - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[0], maxValsL0); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[1], maxValsL1); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[2], maxValsL2); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[0], minValsL0); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[1], minValsL1); - BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[2], minValsL2); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[0], maxValsR0); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[1], maxValsR1); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[2], maxValsR2); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[0], minValsR0); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[1], minValsR1); - BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[2], minValsR2); - BOOST_REQUIRE(testDTree3.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree3.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree3.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree3.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree3.Left()->MaxVals()[0] == maxValsL0); + REQUIRE(testDTree3.Left()->MaxVals()[1] == maxValsL1); + REQUIRE(testDTree3.Left()->MaxVals()[2] == maxValsL2); + REQUIRE(testDTree3.Left()->MinVals()[0] == minValsL0); + REQUIRE(testDTree3.Left()->MinVals()[1] == minValsL1); + REQUIRE(testDTree3.Left()->MinVals()[2] == minValsL2); + REQUIRE(testDTree3.Right()->MaxVals()[0] == maxValsR0); + REQUIRE(testDTree3.Right()->MaxVals()[1] == maxValsR1); + REQUIRE(testDTree3.Right()->MaxVals()[2] == maxValsR2); + REQUIRE(testDTree3.Right()->MinVals()[0] == minValsR0); + REQUIRE(testDTree3.Right()->MinVals()[1] == minValsR1); + REQUIRE(testDTree3.Right()->MinVals()[2] == minValsR2); + REQUIRE(testDTree3.SplitDim() == 2); + REQUIRE(testDTree3.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree3.Right()->SplitDim() == 1); + REQUIRE(testDTree3.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); } // Test the move constructor. -BOOST_AUTO_TEST_CASE(MoveConstructorTest) +TEST_CASE("MoveConstructorTest", "[DETTest]") { arma::mat testData(3, 5); @@ -653,50 +658,50 @@ BOOST_AUTO_TEST_CASE(MoveConstructorTest) DTree testDTree2(std::move(*testDTree)); // Check default values of the original tree. - BOOST_REQUIRE_EQUAL(testDTree->LogNegError(), -DBL_MAX); - BOOST_REQUIRE(testDTree->Left() == (DTree*) NULL); - BOOST_REQUIRE(testDTree->Right() == (DTree*) NULL); + REQUIRE(testDTree->LogNegError() == -DBL_MAX); + REQUIRE(testDTree->Left() == (DTree*) NULL); + REQUIRE(testDTree->Right() == (DTree*) NULL); // Delete the original tree. delete testDTree; // Test the data of the moved tree. - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); + REQUIRE(testDTree2.MaxVals()[0] == maxVals0); + REQUIRE(testDTree2.MinVals()[0] == minVals0); + REQUIRE(testDTree2.MaxVals()[1] == maxVals1); + REQUIRE(testDTree2.MinVals()[1] == minVals1); + REQUIRE(testDTree2.MaxVals()[2] == maxVals2); + REQUIRE(testDTree2.MinVals()[2] == minVals2); // Test the structure of the moved tree. - BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + REQUIRE(testDTree2.Left()->Left() == NULL); + REQUIRE(testDTree2.Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the data of the moved tree. - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); - BOOST_REQUIRE(testDTree2.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); + REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); + REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); + REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); + REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); + REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); + REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); + REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); + REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); + REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); + REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); + REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); + REQUIRE(testDTree2.SplitDim() == 2); + REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree2.Right()->SplitDim() == 1); + REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); } // Test the move operator. -BOOST_AUTO_TEST_CASE(MoveOperatorTest) +TEST_CASE("MoveOperatorTest", "[DETTest]") { arma::mat testData(3, 5); @@ -736,46 +741,44 @@ BOOST_AUTO_TEST_CASE(MoveOperatorTest) DTree testDTree2 = std::move(*testDTree); // Check default values of the original tree. - BOOST_REQUIRE_EQUAL(testDTree->LogNegError(), -DBL_MAX); - BOOST_REQUIRE(testDTree->Left() == (DTree*) NULL); - BOOST_REQUIRE(testDTree->Right() == (DTree*) NULL); + REQUIRE(testDTree->LogNegError() == -DBL_MAX); + REQUIRE(testDTree->Left() == (DTree*) NULL); + REQUIRE(testDTree->Right() == (DTree*) NULL); // Delete the original tree. delete testDTree; // Test the data of the moved tree. - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); - BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); - BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); + REQUIRE(testDTree2.MaxVals()[0] == maxVals0); + REQUIRE(testDTree2.MinVals()[0] == minVals0); + REQUIRE(testDTree2.MaxVals()[1] == maxVals1); + REQUIRE(testDTree2.MinVals()[1] == minVals1); + REQUIRE(testDTree2.MaxVals()[2] == maxVals2); + REQUIRE(testDTree2.MinVals()[2] == minVals2); // Test the structure of the moved tree. - BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + REQUIRE(testDTree2.Left()->Left() == NULL); + REQUIRE(testDTree2.Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the data of moved tree. - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); - BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); - BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); - BOOST_REQUIRE(testDTree2.SplitDim() == 2); - BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); - BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); - BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); + REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); + REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); + REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); + REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); + REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); + REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); + REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); + REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); + REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); + REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); + REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); + REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); + REQUIRE(testDTree2.SplitDim() == 2); + REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); + REQUIRE(testDTree2.Right()->SplitDim() == 1); + REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/distribution_test.cpp b/src/mlpack/tests/distribution_test.cpp index 35103130b9..ab7d606a9f 100644 --- a/src/mlpack/tests/distribution_test.cpp +++ b/src/mlpack/tests/distribution_test.cpp @@ -19,17 +19,15 @@ #include #include -#include -#include "test_tools.hpp" -#include "serialization.hpp" +#include "catch.hpp" +#include "serialization_catch.hpp" +#include "test_catch_tools.hpp" using namespace mlpack; using namespace mlpack::distribution; using namespace mlpack::metric; using namespace mlpack::math; -BOOST_AUTO_TEST_SUITE(DistributionTest); - /*********************************/ /** Discrete Distribution Tests **/ /*********************************/ @@ -37,38 +35,38 @@ BOOST_AUTO_TEST_SUITE(DistributionTest); /** * Make sure we initialize correctly. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionConstructorTest) +TEST_CASE("DiscreteDistributionConstructorTest", "[DistributionTest]") { DiscreteDistribution d(5); - BOOST_REQUIRE_EQUAL(d.Probabilities().n_elem, 5); - BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("4"), 0.2, 1e-5); + REQUIRE(d.Probabilities().n_elem == 5); + REQUIRE(d.Probability("0") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("1") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("2") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("3") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("4") == Approx(0.2).epsilon(1e-7)); } /** * Make sure we get the probabilities of observations right. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionProbabilityTest) +TEST_CASE("DiscreteDistributionProbabilityTest", "[DistributionTest]") { DiscreteDistribution d(5); d.Probabilities() = "0.2 0.4 0.1 0.1 0.2"; - BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.2, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.4, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.1, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.1, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("4"), 0.2, 1e-5); + REQUIRE(d.Probability("0") == Approx(0.2).epsilon(1e-7)); + REQUIRE(d.Probability("1") == Approx(0.4).epsilon(1e-7)); + REQUIRE(d.Probability("2") == Approx(0.1).epsilon(1e-7)); + REQUIRE(d.Probability("3") == Approx(0.1).epsilon(1e-7)); + REQUIRE(d.Probability("4") == Approx(0.2).epsilon(1e-7)); } /** * Make sure we get random observations correct. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionRandomTest) +TEST_CASE("DiscreteDistributionRandomTest", "[DistributionTest]") { DiscreteDistribution d(arma::Col("3")); @@ -85,15 +83,15 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionRandomTest) actualProb /= accu(actualProb); // 8% tolerance, because this can be a noisy process. - BOOST_REQUIRE_CLOSE(actualProb(0), 0.3, 8.0); - BOOST_REQUIRE_CLOSE(actualProb(1), 0.6, 8.0); - BOOST_REQUIRE_CLOSE(actualProb(2), 0.1, 8.0); + REQUIRE(actualProb(0) == Approx(0.3).epsilon(0.08)); + REQUIRE(actualProb(1) == Approx(0.6).epsilon(0.08)); + REQUIRE(actualProb(2) == Approx(0.1).epsilon(0.08)); } /** * Make sure we can estimate from observations correctly. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainTest) +TEST_CASE("DiscreteDistributionTrainTest", "[DistributionTest]") { DiscreteDistribution d(4); @@ -101,16 +99,16 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainTest) d.Train(obs); - BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.25, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.25, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.375, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.125, 1e-5); + REQUIRE(d.Probability("0") == Approx(0.25).epsilon(1e-7)); + REQUIRE(d.Probability("1") == Approx(0.25).epsilon(1e-7)); + REQUIRE(d.Probability("2") == Approx(0.375).epsilon(1e-7)); + REQUIRE(d.Probability("3") == Approx(0.125).epsilon(1e-7)); } /** * Estimate from observations with probabilities. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainProbTest) +TEST_CASE("DiscreteDistributionTrainProbTest", "[DistributionTest]") { DiscreteDistribution d(3); @@ -120,15 +118,15 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainProbTest) d.Train(obs, prob); - BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.25, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.25, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.5, 1e-5); + REQUIRE(d.Probability("0") == Approx(0.25).epsilon(1e-7)); + REQUIRE(d.Probability("1") == Approx(0.25).epsilon(1e-7)); + REQUIRE(d.Probability("2") == Approx(0.5).epsilon(1e-7)); } /** * Achieve multidimensional probability distribution. */ -BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProbTest) +TEST_CASE("MultiDiscreteDistributionTrainProbTest", "[DistributionTest]") { DiscreteDistribution d("10 10 10"); @@ -137,29 +135,29 @@ BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProbTest) "0 0 0 1 1 2 2 2 2 2;"); d.Train(obs); - BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.009, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("0 1 2"), 0.015, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.054, 1e-5); + REQUIRE(d.Probability("0 0 0") == Approx(0.009).epsilon(1e-7)); + REQUIRE(d.Probability("0 1 2") == Approx(0.015).epsilon(1e-7)); + REQUIRE(d.Probability("2 1 0") == Approx(0.054).epsilon(1e-7)); } /** * Make sure we initialize multidimensional probability distribution * correctly. */ -BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionConstructorTest) +TEST_CASE("MultiDiscreteDistributionConstructorTest", "[DistributionTest]") { DiscreteDistribution d("4 4 4 4"); - BOOST_REQUIRE_EQUAL(d.Probabilities(0).size(), 4); - BOOST_REQUIRE_EQUAL(d.Dimensionality(), 4); - BOOST_REQUIRE_CLOSE(d.Probability("0 0 0 0"), 0.00390625, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("0 1 2 3"), 0.00390625, 1e-5); + REQUIRE(d.Probabilities(0).size() == 4); + REQUIRE(d.Dimensionality() == 4); + REQUIRE(d.Probability("0 0 0 0") == Approx(0.00390625).epsilon(1e-7)); + REQUIRE(d.Probability("0 1 2 3") == Approx(0.00390625).epsilon(1e-7)); } /** * Achieve multidimensional probability distribution. */ -BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainTest) +TEST_CASE("MultiDiscreteDistributionTrainTest", "[DistributionTest]") { std::vector pro; pro.push_back(arma::vec("0.1, 0.3, 0.6")); @@ -168,16 +166,16 @@ BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainTest) DiscreteDistribution d(pro); - BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.0083333, 1e-3); - BOOST_REQUIRE_CLOSE(d.Probability("0 1 2"), 0.0166666, 1e-3); - BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.05, 1e-5); + REQUIRE(d.Probability("0 0 0") == Approx(0.0083333).epsilon(1e-5)); + REQUIRE(d.Probability("0 1 2") == Approx(0.0166666).epsilon(1e-5)); + REQUIRE(d.Probability("2 1 0") == Approx(0.05).epsilon(1e-7)); } /** * Estimate multidimensional probability distribution from observations with * probabilities. */ -BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProTest) +TEST_CASE("MultiDiscreteDistributionTrainProTest", "[DistributionTest]") { DiscreteDistribution d("5 5 5"); @@ -189,16 +187,16 @@ BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProTest) d.Train(obs, prob); - BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.00390625, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1 0 1"), 0.0078125, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.015625, 1e-5); + REQUIRE(d.Probability("0 0 0") == Approx(0.00390625).epsilon(1e-7)); + REQUIRE(d.Probability("1 0 1") == Approx(0.0078125).epsilon(1e-7)); + REQUIRE(d.Probability("2 1 0") == Approx(0.015625).epsilon(1e-7)); } /** * Test the LogProbability() function, for multiple points in the multivariate * Discrete case. */ -BOOST_AUTO_TEST_CASE(DiscreteLogProbabilityTest) +TEST_CASE("DiscreteLogProbabilityTest", "[DistributionTest]") { // Same case as before. DiscreteDistribution d("5 5"); @@ -210,17 +208,17 @@ BOOST_AUTO_TEST_CASE(DiscreteLogProbabilityTest) d.LogProbability(obs, logProb); - BOOST_REQUIRE_EQUAL(logProb.n_elem, 2); + REQUIRE(logProb.n_elem == 2); - BOOST_REQUIRE_CLOSE(logProb(0), -3.2188758248682, 1e-3); - BOOST_REQUIRE_CLOSE(logProb(1), -3.2188758248682, 1e-3); + REQUIRE(logProb(0) == Approx(-3.2188758248682).epsilon(1e-5)); + REQUIRE(logProb(1) == Approx(-3.2188758248682).epsilon(1e-5)); } /** * Test the Probability() function, for multiple points in the multivariate * Discrete case. */ -BOOST_AUTO_TEST_CASE(DiscreteProbabilityTest) +TEST_CASE("DiscreteProbabilityTest", "[DistributionTest]") { // Same case as before. DiscreteDistribution d("5 5"); @@ -232,10 +230,10 @@ BOOST_AUTO_TEST_CASE(DiscreteProbabilityTest) d.Probability(obs, prob); - BOOST_REQUIRE_EQUAL(prob.n_elem, 2); + REQUIRE(prob.n_elem == 2); - BOOST_REQUIRE_CLOSE(prob(0), 0.0400000000000, 1e-3); - BOOST_REQUIRE_CLOSE(prob(1), 0.0400000000000, 1e-3); + REQUIRE(prob(0) == Approx(0.0400000000000).epsilon(1e-5)); + REQUIRE(prob(1) == Approx(0.0400000000000).epsilon(1e-5)); } /*********************************/ @@ -245,32 +243,33 @@ BOOST_AUTO_TEST_CASE(DiscreteProbabilityTest) /** * Make sure Gaussian distributions are initialized correctly. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionEmptyConstructor) +TEST_CASE("GaussianDistributionEmptyConstructor", "[DistributionTest]") { GaussianDistribution d; - BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 0); - BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 0); + REQUIRE(d.Mean().n_elem == 0); + REQUIRE(d.Covariance().n_elem == 0); } /** * Make sure Gaussian distributions are initialized to the correct * dimensionality. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionDimensionalityConstructor) +TEST_CASE("GaussianDistributionDimensionalityConstructor", + "[DistributionTest]") { GaussianDistribution d(4); - BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 4); - BOOST_REQUIRE_EQUAL(d.Covariance().n_rows, 4); - BOOST_REQUIRE_EQUAL(d.Covariance().n_cols, 4); + REQUIRE(d.Mean().n_elem == 4); + REQUIRE(d.Covariance().n_rows == 4); + REQUIRE(d.Covariance().n_cols == 4); } /** * Make sure Gaussian distributions are initialized correctly when we give a * mean and covariance. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionDistributionConstructor) +TEST_CASE("GaussianDistributionDistributionConstructor", "[DistributionTest]") { arma::vec mean(3); arma::mat covariance(3, 3); @@ -283,17 +282,17 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionDistributionConstructor) GaussianDistribution d(mean, covariance); for (size_t i = 0; i < 3; ++i) - BOOST_REQUIRE_CLOSE(d.Mean()[i], mean[i], 1e-5); + REQUIRE(d.Mean()[i] == Approx(mean[i]).epsilon(1e-7)); for (size_t i = 0; i < 3; ++i) for (size_t j = 0; j < 3; ++j) - BOOST_REQUIRE_CLOSE(d.Covariance()(i, j), covariance(i, j), 1e-5); + REQUIRE(d.Covariance()(i, j) == Approx(covariance(i, j)).epsilon(1e-7)); } /** * Make sure the probability of observations is correct. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionProbabilityTest) +TEST_CASE("GaussianDistributionProbabilityTest", "[DistributionTest]") { arma::vec mean("5 6 3 3 2"); arma::mat cov("6 1 1 1 2;" @@ -304,52 +303,63 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionProbabilityTest) GaussianDistribution d(mean, cov); - BOOST_REQUIRE_CLOSE(d.LogProbability("0 1 2 3 4"), -13.432076798791542, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("3 2 3 7 8"), -15.814880322345738, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("2 2 0 8 1"), -13.754462857772776, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("2 1 5 0 1"), -13.283283233107898, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("3 0 5 1 0"), -13.800326511545279, 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("4 0 6 1 0"), -14.900192463287908, 1e-5); + REQUIRE(d.LogProbability("0 1 2 3 4") == + Approx(-13.432076798791542).epsilon(1e-7)); + REQUIRE(d.LogProbability("3 2 3 7 8") == + Approx(-15.814880322345738).epsilon(1e-7)); + REQUIRE(d.LogProbability("2 2 0 8 1") == + Approx(-13.754462857772776).epsilon(1e-7)); + REQUIRE(d.LogProbability("2 1 5 0 1") == + Approx(-13.283283233107898).epsilon(1e-7)); + REQUIRE(d.LogProbability("3 0 5 1 0") == + Approx(-13.800326511545279).epsilon(1e-7)); + REQUIRE(d.LogProbability("4 0 6 1 0") == + Approx(-14.900192463287908).epsilon(1e-7)); } /** * Test GaussianDistribution::Probability() in the univariate case. */ -BOOST_AUTO_TEST_CASE(GaussianUnivariateProbabilityTest) +TEST_CASE("GaussianUnivariateProbabilityTest", "[DistributionTest]") { GaussianDistribution g(arma::vec("0.0"), arma::mat("1.0")); // Simple case. - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("0.0")), 0.398942280401433, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.241970724519143, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.241970724519143, - 1e-5); + REQUIRE(g.Probability(arma::vec("0.0")) == + Approx(0.398942280401433).epsilon(1e-7)); + REQUIRE(g.Probability(arma::vec("1.0")) == + Approx(0.241970724519143).epsilon(1e-7)); + REQUIRE(g.Probability(arma::vec("-1.0")) == + Approx(0.241970724519143).epsilon(1e-7)); // A few more cases... arma::mat covariance; covariance = 2.0; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("0.0")), 0.282094791773878, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.219695644733861, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.219695644733861, - 1e-5); + REQUIRE(g.Probability(arma::vec("0.0")) == + Approx(0.282094791773878).epsilon(1e-7)); + REQUIRE(g.Probability(arma::vec("1.0")) == + Approx(0.219695644733861).epsilon(1e-7)); + REQUIRE(g.Probability(arma::vec("-1.0")) == + Approx(0.219695644733861).epsilon(1e-7)); g.Mean().fill(1.0); covariance = 1.0; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.398942280401433, 1e-5); + REQUIRE(g.Probability(arma::vec("1.0")) == + Approx(0.398942280401433).epsilon(1e-7)); covariance = 2.0; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.103776874355149, - 1e-5); + REQUIRE(g.Probability(arma::vec("-1.0")) == + Approx(0.103776874355149).epsilon(1e-7)); } /** * Test GaussianDistribution::Probability() in the multivariate case. */ -BOOST_AUTO_TEST_CASE(GaussianMultivariateProbabilityTest) +TEST_CASE("GaussianMultivariateProbabilityTest", "[DistributionTest]") { // Simple case. arma::vec mean = "0 0"; @@ -358,37 +368,37 @@ BOOST_AUTO_TEST_CASE(GaussianMultivariateProbabilityTest) GaussianDistribution g(mean, cov); - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.159154943091895, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.159154943091895).epsilon(1e-7)); arma::mat covariance; covariance = "2 0; 0 2"; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0795774715459477, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.0795774715459477).epsilon(1e-7)); x = "1 1"; - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0482661763150270, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.0482661763150270, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.0482661763150270).epsilon(1e-7)); + REQUIRE(g.Probability(-x) == Approx(0.0482661763150270).epsilon(1e-7)); g.Mean() = "1 1"; - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0795774715459477, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.0795774715459477).epsilon(1e-7)); g.Mean() *= -1; - BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.0795774715459477, 1e-5); + REQUIRE(g.Probability(-x) == Approx(0.0795774715459477).epsilon(1e-7)); g.Mean() = "1 1"; covariance = "2 1.5; 1.5 4"; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.066372199406187285, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.066372199406187285).epsilon(1e-7)); g.Mean() *= -1; - BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.066372199406187285, 1e-5); + REQUIRE(g.Probability(-x) == Approx(0.066372199406187285).epsilon(1e-7)); g.Mean() = "1 1"; x = "-1 4"; - BOOST_REQUIRE_CLOSE(g.Probability(x), 0.00072147262356379415, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.00085851785428674523, 1e-5); + REQUIRE(g.Probability(x) == Approx(0.00072147262356379415).epsilon(1e-7)); + REQUIRE(g.Probability(-x) == Approx(0.00085851785428674523).epsilon(1e-7)); // Higher-dimensional case. x = "0 1 2 3 4"; @@ -401,19 +411,19 @@ BOOST_AUTO_TEST_CASE(GaussianMultivariateProbabilityTest) "2 0 1 0 6"; g.Covariance(std::move(covariance)); - BOOST_REQUIRE_CLOSE(g.Probability(x), 1.4673143531128877e-06, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(-x), 7.7404143494891786e-09, 1e-8); + REQUIRE(g.Probability(x) == Approx(1.4673143531128877e-06).epsilon(1e-7)); + REQUIRE(g.Probability(-x) == Approx(7.7404143494891786e-09).epsilon(1e-10)); g.Mean() *= -1; - BOOST_REQUIRE_CLOSE(g.Probability(-x), 1.4673143531128877e-06, 1e-5); - BOOST_REQUIRE_CLOSE(g.Probability(x), 7.7404143494891786e-09, 1e-8); + REQUIRE(g.Probability(-x) == Approx(1.4673143531128877e-06).epsilon(1e-7)); + REQUIRE(g.Probability(x) == Approx(7.7404143494891786e-09).epsilon(1e-10)); } /** * Test the phi() function, for multiple points in the multivariate Gaussian * case. */ -BOOST_AUTO_TEST_CASE(GaussianMultipointMultivariateProbabilityTest) +TEST_CASE("GaussianMultipointMultivariateProbabilityTest", "[DistributionTest]") { // Same case as before. arma::vec mean = "5 6 3 3 2"; @@ -433,20 +443,20 @@ BOOST_AUTO_TEST_CASE(GaussianMultipointMultivariateProbabilityTest) GaussianDistribution g(mean, cov); g.LogProbability(points, phis); - BOOST_REQUIRE_EQUAL(phis.n_elem, 6); + REQUIRE(phis.n_elem == 6); - BOOST_REQUIRE_CLOSE(phis(0), -13.432076798791542, 1e-5); - BOOST_REQUIRE_CLOSE(phis(1), -15.814880322345738, 1e-5); - BOOST_REQUIRE_CLOSE(phis(2), -13.754462857772776, 1e-5); - BOOST_REQUIRE_CLOSE(phis(3), -13.283283233107898, 1e-5); - BOOST_REQUIRE_CLOSE(phis(4), -13.800326511545279, 1e-5); - BOOST_REQUIRE_CLOSE(phis(5), -14.900192463287908, 1e-5); + REQUIRE(phis(0) == Approx(-13.432076798791542).epsilon(1e-7)); + REQUIRE(phis(1) == Approx(-15.814880322345738).epsilon(1e-7)); + REQUIRE(phis(2) == Approx(-13.754462857772776).epsilon(1e-7)); + REQUIRE(phis(3) == Approx(-13.283283233107898).epsilon(1e-7)); + REQUIRE(phis(4) == Approx(-13.800326511545279).epsilon(1e-7)); + REQUIRE(phis(5) == Approx(-14.900192463287908).epsilon(1e-7)); } /** * Make sure random observations follow the probability distribution correctly. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionRandomTest) +TEST_CASE("GaussianDistributionRandomTest", "[DistributionTest]") { arma::vec mean("1.0 2.25"); arma::mat cov("0.85 0.60;" @@ -464,19 +474,19 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionRandomTest) arma::mat obsCov = mlpack::math::ColumnCovariance(obs); // 10% tolerance because this can be noisy. - BOOST_REQUIRE_CLOSE(obsMean[0], mean[0], 10.0); - BOOST_REQUIRE_CLOSE(obsMean[1], mean[1], 10.0); + REQUIRE(obsMean[0] == Approx(mean[0]).epsilon(0.1)); + REQUIRE(obsMean[1] == Approx(mean[1]).epsilon(0.1)); - BOOST_REQUIRE_CLOSE(obsCov(0, 0), cov(0, 0), 10.0); - BOOST_REQUIRE_CLOSE(obsCov(0, 1), cov(0, 1), 10.0); - BOOST_REQUIRE_CLOSE(obsCov(1, 0), cov(1, 0), 10.0); - BOOST_REQUIRE_CLOSE(obsCov(1, 1), cov(1, 1), 10.0); + REQUIRE(obsCov(0, 0) == Approx(cov(0, 0)).epsilon(0.1)); + REQUIRE(obsCov(0, 1) == Approx(cov(0, 1)).epsilon(0.1)); + REQUIRE(obsCov(1, 0) == Approx(cov(1, 0)).epsilon(0.1)); + REQUIRE(obsCov(1, 1) == Approx(cov(1, 1)).epsilon(0.1)); } /** * Make sure that we can properly estimate from given observations. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionTrainTest) +TEST_CASE("GaussianDistributionTrainTest", "[DistributionTest]") { arma::vec mean("1.0 3.0 0.0 2.5"); arma::mat cov("3.0 0.0 1.0 4.0;" @@ -502,18 +512,22 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainTest) // Check that everything is estimated right. for (size_t i = 0; i < 4; ++i) - BOOST_REQUIRE_SMALL(d.Mean()[i] - actualMean[i], 1e-5); + REQUIRE(d.Mean()[i] - actualMean[i] == Approx(0.0).margin(1e-5)); for (size_t i = 0; i < 4; ++i) for (size_t j = 0; j < 4; ++j) - BOOST_REQUIRE_SMALL(d.Covariance()(i, j) - actualCov(i, j), 1e-5); + { + REQUIRE(d.Covariance()(i, j) - actualCov(i, j) == + Approx(0.0).margin(1e-5)); + } } /** * This test verifies the fitting of GaussianDistribution works properly when * probabilities for each sample is given. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithProbabilitiesTest) +TEST_CASE("GaussianDistributionTrainWithProbabilitiesTest", + "[DistributionTest]") { arma::vec mean = ("5.0"); arma::vec cov = ("2.0"); @@ -538,18 +552,19 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithProbabilitiesTest) GaussianDistribution guDist2; guDist2.Train(rdata); - BOOST_REQUIRE_CLOSE(guDist.Mean()[0], guDist2.Mean()[0], 6); - BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], guDist2.Covariance()[0], 6); + REQUIRE(guDist.Mean()[0] == Approx(guDist2.Mean()[0]).epsilon(0.06)); + REQUIRE(guDist.Covariance()[0] == + Approx(guDist2.Covariance()[0]).epsilon(0.06)); - BOOST_REQUIRE_CLOSE(guDist.Mean()[0], mean[0], 6); - BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], cov[0], 6); + REQUIRE(guDist.Mean()[0] == Approx(mean[0]).epsilon(0.06)); + REQUIRE(guDist.Covariance()[0] == Approx(cov[0]).epsilon(0.06)); } /** * This test ensures that the same result is obtained when trained with * probabilities all set to 1 and with no probabilities at all. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionWithProbabilties1Test) +TEST_CASE("GaussianDistributionWithProbabilties1Test", "[DistributionTest]") { arma::vec mean = ("5.0"); arma::vec cov = ("4.0"); @@ -573,8 +588,9 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionWithProbabilties1Test) GaussianDistribution guDist2; guDist2.Train(rdata, probabilities); - BOOST_REQUIRE_CLOSE(guDist.Mean()[0], guDist2.Mean()[0], 1e-15); - BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], guDist2.Covariance()[0], 1e-2); + REQUIRE(guDist.Mean()[0] == Approx(guDist2.Mean()[0]).epsilon(1e-17)); + REQUIRE(guDist.Covariance()[0] == + Approx(guDist2.Covariance()[0]).epsilon(1e-4)); } /** @@ -585,7 +601,8 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionWithProbabilties1Test) * We expect that the distribution we recover after training to be the same as * the second normal distribution (the one with high probabilities). */ -BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) +TEST_CASE("GaussianDistributionTrainWithTwoDistProbabilitiesTest", + "[DistributionTest]") { arma::vec mean1 = ("5.0"); arma::vec cov1 = ("4.0"); @@ -626,8 +643,8 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) GaussianDistribution guDist; guDist.Train(rdata, probabilities); - BOOST_REQUIRE_CLOSE(guDist.Mean()[0], mean1[0], 5); - BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], cov1[0], 5); + REQUIRE(guDist.Mean()[0] == Approx(mean1[0]).epsilon(0.05)); + REQUIRE(guDist.Covariance()[0] == Approx(cov1[0]).epsilon(0.05)); } /******************************/ @@ -637,7 +654,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) * Make sure that using an object to fit one reference set and then asking * to fit another works properly. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainTest) +TEST_CASE("GammaDistributionTrainTest", "[DistributionTest]") { // Create a gamma distribution random generator. double alphaReal = 5.3; @@ -659,8 +676,8 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTest) gDist.Train(rdata); // Training must estimate d pairs of alpha and beta parameters. - BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d); - BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d); + REQUIRE(gDist.Dimensionality() == d); + REQUIRE(gDist.Dimensionality() == d); // Create a N' x d' gamma distribution, fit results without new object. size_t N2 = 350; @@ -676,15 +693,15 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTest) gDist.Train(rdata2); // Training must estimate d' pairs of alpha and beta parameters. - BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d2); - BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d2); + REQUIRE(gDist.Dimensionality() == d2); + REQUIRE(gDist.Dimensionality() == d2); } /** * This test verifies that the fitting procedure for GammaDistribution works * properly when probabilities for each sample is given. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainWithProbabilitiesTest) +TEST_CASE("GammaDistributionTrainWithProbabilitiesTest", "[DistributionTest]") { double alphaReal = 5.4; double betaReal = 6.7; @@ -711,24 +728,24 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainWithProbabilitiesTest) GammaDistribution gDist2; gDist2.Train(rdata); - BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), gDist.Alpha(0), 1.5); - BOOST_REQUIRE_CLOSE(gDist2.Beta(0), gDist.Beta(0), 1.5); + REQUIRE(gDist2.Alpha(0) == Approx(gDist.Alpha(0)).epsilon(0.015)); + REQUIRE(gDist2.Beta(0) == Approx(gDist.Beta(0)).epsilon(0.015)); - BOOST_REQUIRE_CLOSE(gDist2.Alpha(1), gDist.Alpha(1), 1.5); - BOOST_REQUIRE_CLOSE(gDist2.Beta(1), gDist.Beta(1), 1.5); + REQUIRE(gDist2.Alpha(1) == Approx(gDist.Alpha(1)).epsilon(0.015)); + REQUIRE(gDist2.Beta(1) == Approx(gDist.Beta(1)).epsilon(0.015)); - BOOST_REQUIRE_CLOSE(alphaReal, gDist.Alpha(0), 3.0); - BOOST_REQUIRE_CLOSE(betaReal, gDist.Beta(0), 3.0); + REQUIRE(alphaReal == Approx(gDist.Alpha(0)).epsilon(0.03)); + REQUIRE(betaReal == Approx(gDist.Beta(0)).epsilon(0.03)); - BOOST_REQUIRE_CLOSE(alphaReal, gDist.Alpha(1), 3.0); - BOOST_REQUIRE_CLOSE(betaReal, gDist.Beta(1), 3.0); + REQUIRE(alphaReal == Approx(gDist.Alpha(1)).epsilon(0.03)); + REQUIRE(betaReal == Approx(gDist.Beta(1)).epsilon(0.03)); } /** * This test ensures that the same result is obtained when trained with * probabilities all set to 1 and with no probabilities at all. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainAllProbabilities1Test) +TEST_CASE("GammaDistributionTrainAllProbabilities1Test", "[DistributionTest]") { double alphaReal = 5.4; double betaReal = 6.7; @@ -753,11 +770,11 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainAllProbabilities1Test) arma::vec allProbabilities1(N, arma::fill::ones); gDist2.Train(rdata, allProbabilities1); - BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), gDist.Alpha(0), 1e-5); - BOOST_REQUIRE_CLOSE(gDist2.Beta(0), gDist.Beta(0), 1e-5); + REQUIRE(gDist2.Alpha(0) == Approx(gDist.Alpha(0)).epsilon(1e-7)); + REQUIRE(gDist2.Beta(0) == Approx(gDist.Beta(0)).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(gDist2.Alpha(1), gDist.Alpha(1), 1e-5); - BOOST_REQUIRE_CLOSE(gDist2.Beta(1), gDist.Beta(1), 1e-5); + REQUIRE(gDist2.Alpha(1) == Approx(gDist.Alpha(1)).epsilon(1e-7)); + REQUIRE(gDist2.Beta(1) == Approx(gDist.Beta(1)).epsilon(1e-7)); } /** @@ -767,7 +784,8 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainAllProbabilities1Test) * gamma distribution recovered has the same parameters as the second gamma * distribution with high probabilities. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) +TEST_CASE("GammaDistributionTrainTwoDistProbabilities1Test", + "[DistributionTest]") { double alphaReal = 5.4; double betaReal = 6.7; @@ -807,11 +825,11 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) GammaDistribution gDist; gDist.Train(rdata, probabilities); - BOOST_REQUIRE_CLOSE(alphaReal2, gDist.Alpha(0), 5); - BOOST_REQUIRE_CLOSE(betaReal2, gDist.Beta(0), 5); + REQUIRE(alphaReal2 == Approx(gDist.Alpha(0)).epsilon(0.05)); + REQUIRE(betaReal2 == Approx(gDist.Beta(0)).epsilon(0.05)); - BOOST_REQUIRE_CLOSE(alphaReal2, gDist.Alpha(1), 5); - BOOST_REQUIRE_CLOSE(betaReal2, gDist.Beta(1), 5); + REQUIRE(alphaReal2 == Approx(gDist.Alpha(1)).epsilon(0.05)); + REQUIRE(betaReal2 == Approx(gDist.Beta(1)).epsilon(0.05)); } /** @@ -820,7 +838,7 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) * with different alpha/beta parameters so we make sure we don't have some weird * bug that always converges to the same number. */ -BOOST_AUTO_TEST_CASE(GammaDistributionFittingTest) +TEST_CASE("GammaDistributionFittingTest", "[DistributionTest]") { // Offset from the actual alpha/beta. 10% is quite a relaxed tolerance since // the random points we generate are few (for test speed) and might be fitted @@ -848,8 +866,8 @@ BOOST_AUTO_TEST_CASE(GammaDistributionFittingTest) gDist.Train(rdata); // Estimated parameter must be close to real. - BOOST_REQUIRE_CLOSE(gDist.Alpha(0), alphaReal, errorTolerance); - BOOST_REQUIRE_CLOSE(gDist.Beta(0), betaReal, errorTolerance); + REQUIRE(gDist.Alpha(0) == Approx(alphaReal).epsilon(errorTolerance / 100)); + REQUIRE(gDist.Beta(0) == Approx(betaReal).epsilon(errorTolerance / 100)); /** Iteration 2 (different parameter set) **/ @@ -869,15 +887,15 @@ BOOST_AUTO_TEST_CASE(GammaDistributionFittingTest) gDist2.Train(rdata2); // Estimated parameter must be close to real. - BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), alphaReal2, errorTolerance); - BOOST_REQUIRE_CLOSE(gDist2.Beta(0), betaReal2, errorTolerance); + REQUIRE(gDist2.Alpha(0) == Approx(alphaReal2).epsilon(errorTolerance / 100)); + REQUIRE(gDist2.Beta(0) == Approx(betaReal2).epsilon(errorTolerance / 100)); } /** * Test that Train() and the constructor that takes data give the same resulting * distribution. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainConstructorTest) +TEST_CASE("GammaDistributionTrainConstructorTest", "[DistributionTest]") { const arma::mat data = arma::randu(10, 500); @@ -887,8 +905,8 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainConstructorTest) for (size_t i = 0; i < 10; ++i) { - BOOST_REQUIRE_CLOSE(d1.Alpha(i), d2.Alpha(i), 1e-5); - BOOST_REQUIRE_CLOSE(d1.Beta(i), d2.Beta(i), 1e-5); + REQUIRE(d1.Alpha(i) == Approx(d2.Alpha(i)).epsilon(1e-7)); + REQUIRE(d1.Beta(i) == Approx(d2.Beta(i)).epsilon(1e-7)); } } @@ -896,7 +914,7 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainConstructorTest) * Test that Train() with a dataset and Train() with dataset statistics return * the same results. */ -BOOST_AUTO_TEST_CASE(GammaDistributionTrainStatisticsTest) +TEST_CASE("GammaDistributionTrainStatisticsTest", "[DistributionTest]") { const arma::mat data = arma::randu(1, 500); @@ -910,15 +928,15 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainStatisticsTest) const arma::vec logMeanx = arma::log(meanx); d2.Train(logMeanx, meanLogx, meanx); - BOOST_REQUIRE_CLOSE(d1.Alpha(0), d2.Alpha(0), 1e-5); - BOOST_REQUIRE_CLOSE(d1.Beta(0), d2.Beta(0), 1e-5); + REQUIRE(d1.Alpha(0) == Approx(d2.Alpha(0)).epsilon(1e-7)); + REQUIRE(d1.Beta(0) == Approx(d2.Beta(0)).epsilon(1e-7)); } /** * Tests that Random() generates points that can be reasonably well fit by the * distribution that generated them. */ -BOOST_AUTO_TEST_CASE(GammaDistributionRandomTest) +TEST_CASE("GammaDistributionRandomTest", "[DistributionTest]") { const arma::vec a("2.0 2.5 3.0"), b("0.4 0.6 1.3"); const size_t numPoints = 2000; @@ -934,12 +952,12 @@ BOOST_AUTO_TEST_CASE(GammaDistributionRandomTest) GammaDistribution d2(data); for (size_t i = 0; i < 3; ++i) { - BOOST_REQUIRE_CLOSE(d2.Alpha(i), a(i), 10); // Within 10% - BOOST_REQUIRE_CLOSE(d2.Beta(i), b(i), 10); + REQUIRE(d2.Alpha(i) == Approx(a(i)).epsilon(0.1)); // Within 10% + REQUIRE(d2.Beta(i) == Approx(b(i)).epsilon(0.1)); } } -BOOST_AUTO_TEST_CASE(GammaDistributionProbabilityTest) +TEST_CASE("GammaDistributionProbabilityTest", "[DistributionTest]") { // Train two 1-dimensional distributions. const arma::vec a1("2.0"), b1("0.9"), a2("3.1"), b2("1.4"); @@ -949,16 +967,16 @@ BOOST_AUTO_TEST_CASE(GammaDistributionProbabilityTest) // Evaluated at wolfram|alpha GammaDistribution d1(a1, b1); d1.Probability(x1, prob1); - BOOST_REQUIRE_CLOSE(prob1(0), 0.267575, 1e-3); + REQUIRE(prob1(0) == Approx(0.267575).epsilon(1e-5)); // Evaluated at wolfram|alpha GammaDistribution d2(a2, b2); d2.Probability(x2, prob2); - BOOST_REQUIRE_CLOSE(prob2(0), 0.189043, 1e-3); + REQUIRE(prob2(0) == Approx(0.189043).epsilon(1e-5)); // Check that the overload that returns the probability for 1 dimension // agrees. - BOOST_REQUIRE_CLOSE(prob2(0), d2.Probability(2.94, 0), 1e-5); + REQUIRE(prob2(0) == Approx(d2.Probability(2.94, 0)).epsilon(1e-7)); // Combine into one 2-dimensional distribution. const arma::vec a3("2.0 3.1"), b3("0.9 1.4"); @@ -971,11 +989,11 @@ BOOST_AUTO_TEST_CASE(GammaDistributionProbabilityTest) // 1-dimensional distributions (evaluated at wolfram|alpha). GammaDistribution d3(a3, b3); d3.Probability(x3, prob3); - BOOST_REQUIRE_CLOSE(prob3(0), 0.04408, 1e-2); - BOOST_REQUIRE_CLOSE(prob3(1), 0.026165, 1e-2); + REQUIRE(prob3(0) == Approx(0.04408).epsilon(1e-4)); + REQUIRE(prob3(1) == Approx(0.026165).epsilon(1e-4)); } -BOOST_AUTO_TEST_CASE(GammaDistributionLogProbabilityTest) +TEST_CASE("GammaDistributionLogProbabilityTest", "[DistributionTest]") { // Train two 1-dimensional distributions. const arma::vec a1("2.0"), b1("0.9"), a2("3.1"), b2("1.4"); @@ -985,16 +1003,16 @@ BOOST_AUTO_TEST_CASE(GammaDistributionLogProbabilityTest) // Evaluated at wolfram|alpha GammaDistribution d1(a1, b1); d1.LogProbability(x1, logprob1); - BOOST_REQUIRE_CLOSE(logprob1(0), std::log(0.267575), 1e-3); + REQUIRE(logprob1(0) == Approx(std::log(0.267575)).epsilon(1e-5)); // Evaluated at wolfram|alpha GammaDistribution d2(a2, b2); d2.LogProbability(x2, logprob2); - BOOST_REQUIRE_CLOSE(logprob2(0), std::log(0.189043), 1e-3); + REQUIRE(logprob2(0) == Approx(std::log(0.189043)).epsilon(1e-5)); // Check that the overload that returns the log probability for // 1 dimension agrees. - BOOST_REQUIRE_CLOSE(logprob2(0), d2.LogProbability(2.94, 0), 1e-5); + REQUIRE(logprob2(0) == Approx(d2.LogProbability(2.94, 0)).epsilon(1e-7)); // Combine into one 2-dimensional distribution. const arma::vec a3("2.0 3.1"), b3("0.9 1.4"); @@ -1008,14 +1026,14 @@ BOOST_AUTO_TEST_CASE(GammaDistributionLogProbabilityTest) // 1-dimensional distributions (evaluated at wolfram|alpha). GammaDistribution d3(a3, b3); d3.LogProbability(x3, logprob3); - BOOST_REQUIRE_CLOSE(logprob3(0), std::log(0.04408), 1e-3); - BOOST_REQUIRE_CLOSE(logprob3(1), std::log(0.026165), 1e-3); + REQUIRE(logprob3(0) == Approx(std::log(0.04408)).epsilon(1e-5)); + REQUIRE(logprob3(1) == Approx(std::log(0.026165)).epsilon(1e-5)); } /** * Discrete Distribution serialization test. */ -BOOST_AUTO_TEST_CASE(DiscreteDistributionTest) +TEST_CASE("DiscreteDistributionTest", "[DistributionTest]") { // I assume that I am properly saving vectors, so, this should be // straightforward. @@ -1036,15 +1054,15 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionTest) const double prob = t.Probability(obs); if (prob == 0.0) { - BOOST_REQUIRE_SMALL(xmlT.Probability(obs), 1e-8); - BOOST_REQUIRE_SMALL(textT.Probability(obs), 1e-8); - BOOST_REQUIRE_SMALL(binaryT.Probability(obs), 1e-8); + REQUIRE(xmlT.Probability(obs) == Approx(0.0).margin(1e-8)); + REQUIRE(textT.Probability(obs) == Approx(0.0).margin(1e-8)); + REQUIRE(binaryT.Probability(obs) == Approx(0.0).margin(1e-8)); } else { - BOOST_REQUIRE_CLOSE(prob, xmlT.Probability(obs), 1e-8); - BOOST_REQUIRE_CLOSE(prob, textT.Probability(obs), 1e-8); - BOOST_REQUIRE_CLOSE(prob, binaryT.Probability(obs), 1e-8); + REQUIRE(prob == Approx(xmlT.Probability(obs)).epsilon(1e-10)); + REQUIRE(prob == Approx(textT.Probability(obs)).epsilon(1e-10)); + REQUIRE(prob == Approx(binaryT.Probability(obs)).epsilon(1e-10)); } } } @@ -1052,7 +1070,7 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionTest) /** * Gaussian Distribution serialization test. */ -BOOST_AUTO_TEST_CASE(GaussianDistributionTest) +TEST_CASE("GaussianDistributionTest", "[DistributionTest]") { arma::vec mean(10); mean.randu(); @@ -1066,9 +1084,9 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTest) SerializeObjectAll(g, xmlG, textG, binaryG); - BOOST_REQUIRE_EQUAL(g.Dimensionality(), xmlG.Dimensionality()); - BOOST_REQUIRE_EQUAL(g.Dimensionality(), textG.Dimensionality()); - BOOST_REQUIRE_EQUAL(g.Dimensionality(), binaryG.Dimensionality()); + REQUIRE(g.Dimensionality() == xmlG.Dimensionality()); + REQUIRE(g.Dimensionality() == textG.Dimensionality()); + REQUIRE(g.Dimensionality() == binaryG.Dimensionality()); // First, check the means. CheckMatrices(g.Mean(), xmlG.Mean(), textG.Mean(), binaryG.Mean()); @@ -1088,18 +1106,21 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTest) if (prob == 0.0) { - BOOST_REQUIRE_SMALL(xmlG.Probability(randomObs.unsafe_col(i)), 1e-8); - BOOST_REQUIRE_SMALL(textG.Probability(randomObs.unsafe_col(i)), 1e-8); - BOOST_REQUIRE_SMALL(binaryG.Probability(randomObs.unsafe_col(i)), 1e-8); + REQUIRE(xmlG.Probability(randomObs.unsafe_col(i)) == + Approx(0.0).margin(1e-8)); + REQUIRE(textG.Probability(randomObs.unsafe_col(i)) == + Approx(0.0).margin(1e-8)); + REQUIRE(binaryG.Probability(randomObs.unsafe_col(i)) == + Approx(0.0).margin(1e-8)); } else { - BOOST_REQUIRE_CLOSE(prob, xmlG.Probability(randomObs.unsafe_col(i)), - 1e-8); - BOOST_REQUIRE_CLOSE(prob, textG.Probability(randomObs.unsafe_col(i)), - 1e-8); - BOOST_REQUIRE_CLOSE(prob, binaryG.Probability(randomObs.unsafe_col(i)), - 1e-8); + REQUIRE(prob == + Approx(xmlG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); + REQUIRE(prob == + Approx(textG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); + REQUIRE(prob == + Approx(binaryG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); } } } @@ -1107,7 +1128,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTest) /** * Laplace Distribution serialization test. */ -BOOST_AUTO_TEST_CASE(LaplaceDistributionTest) +TEST_CASE("LaplaceDistributionTest", "[DistributionTest]") { arma::vec mean(20); mean.randu(); @@ -1117,9 +1138,9 @@ BOOST_AUTO_TEST_CASE(LaplaceDistributionTest) SerializeObjectAll(l, xmlL, textL, binaryL); - BOOST_REQUIRE_CLOSE(l.Scale(), xmlL.Scale(), 1e-8); - BOOST_REQUIRE_CLOSE(l.Scale(), textL.Scale(), 1e-8); - BOOST_REQUIRE_CLOSE(l.Scale(), binaryL.Scale(), 1e-8); + REQUIRE(l.Scale() == Approx(xmlL.Scale()).epsilon(1e-10)); + REQUIRE(l.Scale() == Approx(textL.Scale()).epsilon(1e-10)); + REQUIRE(l.Scale() == Approx(binaryL.Scale()).epsilon(1e-10)); CheckMatrices(l.Mean(), xmlL.Mean(), textL.Mean(), binaryL.Mean()); } @@ -1127,15 +1148,15 @@ BOOST_AUTO_TEST_CASE(LaplaceDistributionTest) /** * Laplace Distribution Probability Test. */ -BOOST_AUTO_TEST_CASE(LaplaceDistributionProbabilityTest) +TEST_CASE("LaplaceDistributionProbabilityTest", "[DistributionTest]") { LaplaceDistribution l(arma::vec("0.0"), 1.0); // Simple case. - BOOST_REQUIRE_CLOSE(l.Probability(arma::vec("0.0")), - 0.500000000000000, 1e-5); - BOOST_REQUIRE_CLOSE(l.Probability(arma::vec("1.0")), - 0.183939720585721, 1e-5); + REQUIRE(l.Probability(arma::vec("0.0")) == + Approx(0.500000000000000).epsilon(1e-7)); + REQUIRE(l.Probability(arma::vec("1.0")) == + Approx(0.183939720585721).epsilon(1e-7)); arma::mat points = "0.0 1.0;"; @@ -1143,24 +1164,24 @@ BOOST_AUTO_TEST_CASE(LaplaceDistributionProbabilityTest) l.Probability(points, probabilities); - BOOST_REQUIRE_EQUAL(probabilities.n_elem, 2); + REQUIRE(probabilities.n_elem == 2); - BOOST_REQUIRE_CLOSE(probabilities(0), 0.500000000000000, 1e-5); - BOOST_REQUIRE_CLOSE(probabilities(1), 0.183939720585721, 1e-5); + REQUIRE(probabilities(0) == Approx(0.500000000000000).epsilon(1e-7)); + REQUIRE(probabilities(1) == Approx(0.183939720585721).epsilon(1e-7)); } /** * Laplace Distribution Log Probability Test. */ -BOOST_AUTO_TEST_CASE(LaplaceDistributionLogProbabilityTest) +TEST_CASE("LaplaceDistributionLogProbabilityTest", "[DistributionTest]") { LaplaceDistribution l(arma::vec("0.0"), 1.0); // Simple case. - BOOST_REQUIRE_CLOSE(l.LogProbability(arma::vec("0.0")), - -0.693147180559945, 1e-5); - BOOST_REQUIRE_CLOSE(l.LogProbability(arma::vec("1.0")), - -1.693147180559946, 1e-5); + REQUIRE(l.LogProbability(arma::vec("0.0")) == + Approx(-0.693147180559945).epsilon(1e-7)); + REQUIRE(l.LogProbability(arma::vec("1.0")) == + Approx(-1.693147180559946).epsilon(1e-7)); arma::mat points = "0.0 1.0;"; @@ -1168,18 +1189,19 @@ BOOST_AUTO_TEST_CASE(LaplaceDistributionLogProbabilityTest) l.LogProbability(points, logProbabilities); - BOOST_REQUIRE_EQUAL(logProbabilities.n_elem, 2); + REQUIRE(logProbabilities.n_elem == 2); - BOOST_REQUIRE_CLOSE(logProbabilities(0), -0.693147180559945, - 1e-5); - BOOST_REQUIRE_CLOSE(logProbabilities(1), -1.693147180559946, - 1e-5); + REQUIRE(logProbabilities(0) == + Approx(-0.693147180559945).epsilon(1e-7)); + + REQUIRE(logProbabilities(1) == + Approx(-1.693147180559946).epsilon(1e-7)); } /** * Mahalanobis Distance serialization test. */ -BOOST_AUTO_TEST_CASE(MahalanobisDistanceTest) +TEST_CASE("MahalanobisDistanceTest", "[DistributionTest]") { MahalanobisDistance<> d; d.Covariance().randu(50, 50); @@ -1198,7 +1220,7 @@ BOOST_AUTO_TEST_CASE(MahalanobisDistanceTest) /** * Regression distribution serialization test. */ -BOOST_AUTO_TEST_CASE(RegressionDistributionTest) +TEST_CASE("RegressionDistributionTest", "[DistributionTest]") { // Generate some random data. arma::mat data; @@ -1225,15 +1247,15 @@ BOOST_AUTO_TEST_CASE(RegressionDistributionTest) // Check the regression function. if (rd.Rf().Lambda() == 0.0) { - BOOST_REQUIRE_SMALL(xmlRd.Rf().Lambda(), 1e-8); - BOOST_REQUIRE_SMALL(textRd.Rf().Lambda(), 1e-8); - BOOST_REQUIRE_SMALL(binaryRd.Rf().Lambda(), 1e-8); + REQUIRE(xmlRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); + REQUIRE(textRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); + REQUIRE(binaryRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); } else { - BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), xmlRd.Rf().Lambda(), 1e-8); - BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), textRd.Rf().Lambda(), 1e-8); - BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), binaryRd.Rf().Lambda(), 1e-8); + REQUIRE(rd.Rf().Lambda() == Approx(xmlRd.Rf().Lambda()).epsilon(1e-10)); + REQUIRE(rd.Rf().Lambda() == Approx(textRd.Rf().Lambda()).epsilon(1e-10)); + REQUIRE(rd.Rf().Lambda() == Approx(binaryRd.Rf().Lambda()).epsilon(1e-10)); } CheckMatrices(rd.Rf().Parameters(), @@ -1250,31 +1272,32 @@ BOOST_AUTO_TEST_CASE(RegressionDistributionTest) * Make sure Diagonal Covariance Gaussian distributions are initialized * correctly. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionEmptyConstructor) +TEST_CASE("DiagonalGaussianDistributionEmptyConstructor", "[DistributionTest]") { DiagonalGaussianDistribution d; - BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 0); - BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 0); + REQUIRE(d.Mean().n_elem == 0); + REQUIRE(d.Covariance().n_elem == 0); } /** * Make sure Diagonal Covariance Gaussian distributions are initialized to * the correct dimensionality. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionDimensionalityConstructor) +TEST_CASE("DiagonalGaussianDistributionDimensionalityConstructor", + "[DistributionTest]") { DiagonalGaussianDistribution d(4); - BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 4); - BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 4); + REQUIRE(d.Mean().n_elem == 4); + REQUIRE(d.Covariance().n_elem == 4); } /** * Make sure Diagonal Covariance Gaussian distributions are initialized * correctly when we give a mean and covariance. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionConstructor) +TEST_CASE("DiagonalGaussianDistributionConstructor", "[DistributionTest]") { arma::vec mean = arma::randu(3); arma::vec covariance = arma::randu(3); @@ -1284,8 +1307,8 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionConstructor) // Make sure the mean and covariance is correct. for (size_t i = 0; i < 3; ++i) { - BOOST_REQUIRE_CLOSE(d.Mean()(i), mean(i), 1e-5); - BOOST_REQUIRE_CLOSE(d.Covariance()(i), covariance(i), 1e-5); + REQUIRE(d.Mean()(i) == Approx(mean(i)).epsilon(1e-7)); + REQUIRE(d.Covariance()(i) == Approx(covariance(i)).epsilon(1e-7)); } } @@ -1293,7 +1316,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionConstructor) * Make sure the probability of observations is correct. * The values were calculated using 'dmvnorm' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionProbabilityTest) +TEST_CASE("DiagonalGaussianDistributionProbabilityTest", "[DistributionTest]") { arma::vec mean("2 5 3 4 1"); arma::vec cov("3 1 5 3 2"); @@ -1301,56 +1324,56 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionProbabilityTest) DiagonalGaussianDistribution d(mean, cov); // Observations lists randomly selected. - BOOST_REQUIRE_CLOSE(d.LogProbability("3 5 2 7 8"), -20.861264167855161, - 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("7 8 4 0 5"), -22.277930834521829, - 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("6 8 7 7 5"), -21.111264167855161, - 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("2 9 5 6 3"), -16.911264167855162, - 1e-5); - BOOST_REQUIRE_CLOSE(d.LogProbability("5 8 2 9 7"), -26.111264167855161, - 1e-5); + REQUIRE(d.LogProbability("3 5 2 7 8") == + Approx(-20.861264167855161).epsilon(1e-7)); + REQUIRE(d.LogProbability("7 8 4 0 5") == + Approx(-22.277930834521829).epsilon(1e-7)); + REQUIRE(d.LogProbability("6 8 7 7 5") == + Approx(-21.111264167855161).epsilon(1e-7)); + REQUIRE(d.LogProbability("2 9 5 6 3") == + Approx(-16.9112641678551621).epsilon(1e-7)); + REQUIRE(d.LogProbability("5 8 2 9 7") == + Approx(-26.111264167855161).epsilon(1e-7)); } /** * Test DiagonalGaussianDistribution::Probability() in the univariate case. * The values were calculated using 'dmvnorm' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianUnivariateProbabilityTest) +TEST_CASE("DiagonalGaussianUnivariateProbabilityTest", "[DistributionTest]") { DiagonalGaussianDistribution d(arma::vec("0.0"), arma::vec("1.0")); // Mean: 0.0, Covariance: 1.0 - BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.3989422804014327, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.24197072451914337, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.24197072451914337, 1e-5); + REQUIRE(d.Probability("0.0") == Approx(0.3989422804014327).epsilon(1e-7)); + REQUIRE(d.Probability("1.0") == Approx(0.24197072451914337).epsilon(1e-7)); + REQUIRE(d.Probability("-1.0") == Approx(0.24197072451914337).epsilon(1e-7)); // Mean: 0.0, Covariance: 2.0 d.Covariance("2.0"); - BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.28209479177387814, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.21969564473386122, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.21969564473386122, 1e-5); + REQUIRE(d.Probability("0.0") == Approx(0.28209479177387814).epsilon(1e-7)); + REQUIRE(d.Probability("1.0") == Approx(0.21969564473386122).epsilon(1e-7)); + REQUIRE(d.Probability("-1.0") == Approx(0.21969564473386122).epsilon(1e-7)); // Mean: 1.0, Covariance: 1.0 d.Mean() = "1.0"; d.Covariance("1.0"); - BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.24197072451914337, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.3989422804014327, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.053990966513188056, 1e-5); + REQUIRE(d.Probability("0.0") == Approx(0.24197072451914337).epsilon(1e-7)); + REQUIRE(d.Probability("1.0") == Approx(0.3989422804014327).epsilon(1e-7)); + REQUIRE(d.Probability("-1.0") == Approx(0.053990966513188056).epsilon(1e-7)); // Mean: 1.0, Covariance: 2.0 d.Covariance("2.0"); - BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.21969564473386122, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.28209479177387814, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.10377687435514872, 1e-5); + REQUIRE(d.Probability("0.0") == Approx(0.21969564473386122).epsilon(1e-7)); + REQUIRE(d.Probability("1.0") == Approx(0.28209479177387814).epsilon(1e-7)); + REQUIRE(d.Probability("-1.0") == Approx(0.10377687435514872).epsilon(1e-7)); } /** * Test DiagonalGaussianDistribution::Probability() in the multivariate case. * The values were calculated using 'dmvnorm' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianMultivariateProbabilityTest) +TEST_CASE("DiagonalGaussianMultivariateProbabilityTest", "[DistributionTest]") { arma::vec mean("0 0"); arma::vec cov("2 2"); @@ -1358,27 +1381,28 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianMultivariateProbabilityTest) DiagonalGaussianDistribution d(mean, cov); - BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.079577471545947673, 1e-5); + REQUIRE(d.Probability(obs) == Approx(0.079577471545947673).epsilon(1e-7)); obs = "1 1"; - BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.048266176315026957, 1e-5); + REQUIRE(d.Probability(obs) == Approx(0.048266176315026957).epsilon(1e-7)); d.Mean() = "1 3"; - BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.029274915762159581, 1e-5); - BOOST_REQUIRE_CLOSE(d.Probability(-obs), 0.00053618878559782773, 1e-5); + REQUIRE(d.Probability(obs) == Approx(0.029274915762159581).epsilon(1e-7)); + REQUIRE(d.Probability(-obs) == Approx(0.00053618878559782773).epsilon(1e-7)); // Higher dimensional case. d.Mean() = "1 3 6 2 7"; d.Covariance("3 1 5 3 2"); obs = "2 5 7 3 8"; - BOOST_REQUIRE_CLOSE(d.Probability(obs), 7.2790083003378082e-05, 1e-5); + REQUIRE(d.Probability(obs) == Approx(7.2790083003378082e-05).epsilon(1e-7)); } /** * Test the phi() function, for multiple points in the multivariate Gaussian * case. The values were calculated using 'dmvnorm' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianMultipointMultivariateProbabilityTest) +TEST_CASE("DiagonalGaussianMultipointMultivariateProbabilityTest", + "[DistributionTest]") { arma::vec mean = "2 5 3 7 2"; arma::vec cov("9 2 1 4 8"); @@ -1391,20 +1415,20 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianMultipointMultivariateProbabilityTest) DiagonalGaussianDistribution d(mean, cov); d.LogProbability(points, phis); - BOOST_REQUIRE_EQUAL(phis.n_elem, 6); + REQUIRE(phis.n_elem == 6); - BOOST_REQUIRE_CLOSE(phis(0), -12.453302051926864, 1e-5); - BOOST_REQUIRE_CLOSE(phis(1), -10.147746496371308, 1e-5); - BOOST_REQUIRE_CLOSE(phis(2), -13.210246496371308, 1e-5); - BOOST_REQUIRE_CLOSE(phis(3), -19.724135385260197, 1e-5); - BOOST_REQUIRE_CLOSE(phis(4), -21.585246496371308, 1e-5); - BOOST_REQUIRE_CLOSE(phis(5), -13.647746496371308, 1e-5); + REQUIRE(phis(0) == Approx(-12.453302051926864).epsilon(1e-7)); + REQUIRE(phis(1) == Approx(-10.147746496371308).epsilon(1e-7)); + REQUIRE(phis(2) == Approx(-13.210246496371308).epsilon(1e-7)); + REQUIRE(phis(3) == Approx(-19.724135385260197).epsilon(1e-7)); + REQUIRE(phis(4) == Approx(-21.585246496371308).epsilon(1e-7)); + REQUIRE(phis(5) == Approx(-13.647746496371308).epsilon(1e-7)); } /** * Make sure random observations follow the probability distribution correctly. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionRandomTest) +TEST_CASE("DiagonalGaussianDistributionRandomTest", "[DistributionTest]") { arma::vec mean("2.5 1.25"); arma::vec cov("0.50 0.25"); @@ -1421,17 +1445,17 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionRandomTest) arma::mat obsCov = mlpack::math::ColumnCovariance(obs); // 10% tolerance because this can be noisy. - BOOST_REQUIRE_CLOSE(obsMean(0), mean(0), 10.0); - BOOST_REQUIRE_CLOSE(obsMean(1), mean(1), 10.0); + REQUIRE(obsMean(0) == Approx(mean(0)).epsilon(0.1)); + REQUIRE(obsMean(1) == Approx(mean(1)).epsilon(0.1)); - BOOST_REQUIRE_CLOSE(obsCov(0, 0), cov(0), 10); - BOOST_REQUIRE_CLOSE(obsCov(1, 1), cov(1), 10); + REQUIRE(obsCov(0, 0) == Approx(cov(0)).epsilon(0.1)); + REQUIRE(obsCov(1, 1) == Approx(cov(1)).epsilon(0.1)); } /** * Make sure that we can properly estimate from given observations. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) +TEST_CASE("DiagonalGaussianDistributionTrainTest", "[DistributionTest]") { arma::vec mean("2.5 1.5 8.2 3.1"); arma::vec cov("1.2 3.1 8.3 4.3"); @@ -1454,8 +1478,8 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) // Check that the estimated parameters are right. for (size_t i = 0; i < 4; ++i) { - BOOST_REQUIRE_SMALL(d.Mean()(i) - actualMean(i), 1e-5); - BOOST_REQUIRE_SMALL(d.Covariance()(i) - actualCov(i, i), 1e-5); + REQUIRE(d.Mean()(i) - actualMean(i) == Approx(0.0).margin(1e-5)); + REQUIRE(d.Covariance()(i) - actualCov(i, i) == Approx(0.0).margin(1e-5)); } } @@ -1463,7 +1487,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) * Make sure the unbiased estimator of the weighted sample works correctly. * The values were calculated using 'cov.wt' in R. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianUnbiasedEstimatorTest) +TEST_CASE("DiagonalGaussianUnbiasedEstimatorTest", "[DistributionTest]") { // Generate the observations. arma::mat observations("3 5 2 7;" @@ -1478,15 +1502,15 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianUnbiasedEstimatorTest) // Estimate the parameters. d.Train(observations, probs); - BOOST_REQUIRE_CLOSE(d.Mean()(0), 4.5, 1e-5); - BOOST_REQUIRE_CLOSE(d.Mean()(1), 4.4, 1e-5); - BOOST_REQUIRE_CLOSE(d.Mean()(2), 3.5, 1e-5); - BOOST_REQUIRE_CLOSE(d.Mean()(3), 6.8, 1e-5); + REQUIRE(d.Mean()(0) == Approx(4.5).epsilon(1e-7)); + REQUIRE(d.Mean()(1) == Approx(4.4).epsilon(1e-7)); + REQUIRE(d.Mean()(2) == Approx(3.5).epsilon(1e-7)); + REQUIRE(d.Mean()(3) == Approx(6.8).epsilon(1e-7)); - BOOST_REQUIRE_CLOSE(d.Covariance()(0), 3.78571428571428603, 1e-5); - BOOST_REQUIRE_CLOSE(d.Covariance()(1), 6.34285714285714253, 1e-5); - BOOST_REQUIRE_CLOSE(d.Covariance()(2), 6.64285714285714235, 1e-5); - BOOST_REQUIRE_CLOSE(d.Covariance()(3), 2.22857142857142865, 1e-5); + REQUIRE(d.Covariance()(0) == Approx(3.78571428571428603).epsilon(1e-7)); + REQUIRE(d.Covariance()(1) == Approx(6.34285714285714253).epsilon(1e-7)); + REQUIRE(d.Covariance()(2) == Approx(6.64285714285714235).epsilon(1e-7)); + REQUIRE(d.Covariance()(3) == Approx(2.22857142857142865).epsilon(1e-7)); } /** @@ -1494,7 +1518,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianUnbiasedEstimatorTest) * the weighted mean and covariance reduce to the unweighted sample mean and * covariance. */ -BOOST_AUTO_TEST_CASE(DiagonalGaussianWeightedParametersReductionTest) +TEST_CASE("DiagonalGaussianWeightedParametersReductionTest", "[DistributionTest]") { arma::vec mean("2.5 1.5 8.2 3.1"); arma::vec cov("1.2 3.1 8.3 4.3"); @@ -1516,9 +1540,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianWeightedParametersReductionTest) // Check if these are equal. for (size_t i = 0; i < 4; ++i) { - BOOST_REQUIRE_CLOSE(d1.Mean()(i), d2.Mean()(i), 1e-5); - BOOST_REQUIRE_CLOSE(d1.Covariance()(i), d2.Covariance()(i), 1e-5); + REQUIRE(d1.Mean()(i) == Approx(d2.Mean()(i)).epsilon(1e-7)); + REQUIRE(d1.Covariance()(i) == Approx(d2.Covariance()(i)).epsilon(1e-7)); } } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index ba45afd29d..bcffa4c8a8 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -148,10 +148,10 @@ TEST_CASE("CheckCopyMovingVanillaNetworkTest", "[FeedForwardNetworkTest]") model1->Add >(8, 3); model1->Add >(); - // Check whether copy cpnstructor is working or not. + // Check whether copy constructor is working or not. CheckCopyFunction<>(model, trainData, trainLabels, 1); - // Check whether move cpnstructor is working or not. + // Check whether move constructor is working or not. CheckMoveFunction<>(model1, trainData, trainLabels, 1); } @@ -489,7 +489,7 @@ TEST_CASE("FFNMiscTest", "[FeedForwardNetworkTest]") auto copiedModel(model); copiedModel = model; auto movedModel(std::move(model)); - movedModel = std::move(copiedModel); + auto moveOperator = std::move(copiedModel); } /** @@ -764,7 +764,7 @@ TEST_CASE("RBFNetworkTest", "[FeedForwardNetworkTest]") model.Add >(8, 3); // RBFN neural net with MeanSquaredError. - TestNetwork<>(model, trainData, trainLabels1, testData, testLabels, 10, 0.1); + TestNetwork<>(model, trainData, trainLabels1, testData, testLabels, 10, 0.2); arma::mat dataset; dataset.load("mnist_first250_training_4s_and_9s.arm"); @@ -796,5 +796,5 @@ TEST_CASE("RBFNetworkTest", "[FeedForwardNetworkTest]") model1.Add >(140, 2); // RBFN neural net with MeanSquaredError. - TestNetwork<>(model1, dataset, labels1, dataset, labels, 10, 0.1); + TestNetwork<>(model1, dataset, labels1, dataset, labels, 10, 0.2); } diff --git a/src/mlpack/tests/main_tests/mean_shift_test.cpp b/src/mlpack/tests/main_tests/mean_shift_test.cpp index eea3ceb3c7..5da1c28b95 100644 --- a/src/mlpack/tests/main_tests/mean_shift_test.cpp +++ b/src/mlpack/tests/main_tests/mean_shift_test.cpp @@ -12,15 +12,16 @@ #include #define BINDING_TYPE BINDING_TYPE_TEST -static const std::string testName = "MeanShift"; #include +static const std::string testName = "MeanShift"; + #include #include -#include "test_helper.hpp" -#include -#include "../test_tools.hpp" +#include "test_helper.hpp" +#include "../test_catch_tools.hpp" +#include "../catch.hpp" using namespace mlpack; @@ -48,13 +49,13 @@ static void ResetSettings() IO::RestoreSettings(testName); } -BOOST_FIXTURE_TEST_SUITE(MeanShiftMainTest, MeanShiftTestFixture); - /** * Ensure that the output has 1 extra row for the labels and * check the number of points for output remain the same. */ -BOOST_AUTO_TEST_CASE(MeanShiftOutputDimensionTest) +TEST_CASE_METHOD( + MeanShiftTestFixture, "MeanShiftOutputDimensionTest", + "[MeanShiftMainTest][BindingTests]") { arma::mat x; x.randu(3, 100); // 100 points in 3 dimension @@ -65,16 +66,18 @@ BOOST_AUTO_TEST_CASE(MeanShiftOutputDimensionTest) mlpackMain(); // Now check that the output has 1 extra row for labels. - BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_rows, 3 + 1); + REQUIRE(IO::GetParam("output").n_rows == 3 + 1); // Check number of output points are the same. - BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_cols, 100); + REQUIRE(IO::GetParam("output").n_cols == 100); } /** * Ensure that if we ask for labels_only, output has 1 row and * same number of columns for each point's label. */ -BOOST_AUTO_TEST_CASE(MeanShiftLabelOnlyOutputDimensionTest) +TEST_CASE_METHOD( + MeanShiftTestFixture, "MeanShiftLabelOnlyOutputDimensionTest", + "[MeanShiftMainTest][BindingTests]") { arma::mat x; x.randu(3, 100); // 100 points in 3 dimension @@ -86,9 +89,9 @@ BOOST_AUTO_TEST_CASE(MeanShiftLabelOnlyOutputDimensionTest) mlpackMain(); // Check that there is only 1 row containing all the labels. - BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_rows, 1); + REQUIRE(IO::GetParam("output").n_rows == 1); // Check number of output points are the same. - BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_cols, 100); + REQUIRE(IO::GetParam("output").n_cols == 100); } /** @@ -96,11 +99,13 @@ BOOST_AUTO_TEST_CASE(MeanShiftLabelOnlyOutputDimensionTest) * and check the number of points remain the same if the --in_place * flag is set. */ -BOOST_AUTO_TEST_CASE(MeanShiftInPlaceTest) +TEST_CASE_METHOD( + MeanShiftTestFixture, "MeanShiftInPlaceTest", + "[MeanShiftMainTest][BindingTests]") { arma::mat x; if (!data::Load("iris_test.csv", x)) - BOOST_FAIL("Cannot load test dataset iris_test.csv!"); + FAIL("Cannot load test dataset iris_test.csv!"); // Get initial number of rows and columns in file. int numRows = x.n_rows; @@ -113,20 +118,22 @@ BOOST_AUTO_TEST_CASE(MeanShiftInPlaceTest) mlpackMain(); // Now check that the output has 1 extra row for labels. - BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_rows, numRows + 1); + REQUIRE(IO::GetParam("output").n_rows == numRows + 1); // Check number of output points are the same. - BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_cols, numCols); + REQUIRE(IO::GetParam("output").n_cols == numCols); } /** * Ensure that force_convergence is used by testing that the * force_convergence flag makes a difference in the program. */ -BOOST_AUTO_TEST_CASE(MeanShiftForceConvergenceTest) +TEST_CASE_METHOD( + MeanShiftTestFixture, "MeanShiftForceConvergenceTest", + "[MeanShiftMainTest][BindingTests]") { arma::mat x; if (!data::Load("iris_test.csv", x)) - BOOST_FAIL("Cannot load test dataset iris_test.csv!"); + FAIL("Cannot load test dataset iris_test.csv!"); // Input random data points. SetInputParam("input", x); @@ -150,18 +157,20 @@ BOOST_AUTO_TEST_CASE(MeanShiftForceConvergenceTest) const int numCentroids2 = IO::GetParam("centroid").n_cols; // Resulting number of centroids should be different. - BOOST_REQUIRE_NE(numCentroids1, numCentroids2); + REQUIRE(numCentroids1 != numCentroids2); } /** * Ensure that radius is used by testing that the radius * makes a difference in the program. */ -BOOST_AUTO_TEST_CASE(MeanShiftRadiusTest) +TEST_CASE_METHOD( + MeanShiftTestFixture, "MeanShiftRadiusTest", + "[MeanShiftMainTest][BindingTests]") { arma::mat x; if (!data::Load("iris_test.csv", x)) - BOOST_FAIL("Cannot load test dataset iris_test.csv!"); + FAIL("Cannot load test dataset iris_test.csv!"); // Input random data points. SetInputParam("input", x); @@ -183,18 +192,20 @@ BOOST_AUTO_TEST_CASE(MeanShiftRadiusTest) const int numCentroids2 = IO::GetParam("centroid").n_cols; // Resulting number of centroids should be different. - BOOST_REQUIRE_NE(numCentroids1, numCentroids2); + REQUIRE(numCentroids1 != numCentroids2); } /** * Ensure that max_iterations is used by testing that the * max_iteration makes a difference in the program. */ -BOOST_AUTO_TEST_CASE(MeanShiftMaxIterationsTest) +TEST_CASE_METHOD( + MeanShiftTestFixture, "MeanShiftMaxIterationsTest", + "[MeanShiftMainTest][BindingTests]") { arma::mat x; if (!data::Load("iris_test.csv", x)) - BOOST_FAIL("Cannot load test dataset iris_test.csv!"); + FAIL("Cannot load test dataset iris_test.csv!"); // Input random data points. SetInputParam("input", x); @@ -216,13 +227,15 @@ BOOST_AUTO_TEST_CASE(MeanShiftMaxIterationsTest) const int numCentroids2 = IO::GetParam("centroid").n_cols; // Resulting number of centroids should be different. - BOOST_REQUIRE_NE(numCentroids1, numCentroids2); + REQUIRE(numCentroids1 != numCentroids2); } /** * Ensure that we can't specify an invalid max number of iterations. */ -BOOST_AUTO_TEST_CASE(MeanShiftInvalidMaxIterationsTest) +TEST_CASE_METHOD( + MeanShiftTestFixture, "MeanShiftInvalidMaxIterationsTest", + "[MeanShiftMainTest][BindingTests]") { arma::mat x; x.randu(3, 100); // 100 points in 3 dimension @@ -233,8 +246,6 @@ BOOST_AUTO_TEST_CASE(MeanShiftInvalidMaxIterationsTest) SetInputParam("max_iterations", (int) -1); Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/mean_shift_test.cpp b/src/mlpack/tests/mean_shift_test.cpp index 818602f632..9f6c229639 100644 --- a/src/mlpack/tests/mean_shift_test.cpp +++ b/src/mlpack/tests/mean_shift_test.cpp @@ -12,15 +12,13 @@ #include -#include -#include "test_tools.hpp" +#include "test_catch_tools.hpp" +#include "catch.hpp" using namespace mlpack; using namespace mlpack::meanshift; using namespace mlpack::distribution; -BOOST_AUTO_TEST_SUITE(MeanShiftTest); - // Generate dataset; written transposed because it's easier to read. arma::mat meanShiftData(" 0.0 0.0;" // Class 1. " 0.3 0.4;" @@ -57,7 +55,7 @@ arma::mat meanShiftData(" 0.0 0.0;" // Class 1. /** * 30-point 3-class test case for Mean Shift. */ -BOOST_AUTO_TEST_CASE(MeanShiftSimpleTest) +TEST_CASE("MeanShiftSimpleTest", "[MeanShiftTest]") { MeanShift<> meanShift; @@ -70,29 +68,29 @@ BOOST_AUTO_TEST_CASE(MeanShiftSimpleTest) size_t firstClass = assignments(0); for (size_t i = 1; i < 13; ++i) - BOOST_REQUIRE_EQUAL(assignments(i), firstClass); + REQUIRE(assignments(i) == firstClass); size_t secondClass = assignments(13); // To ensure that class 1 != class 2. - BOOST_REQUIRE_NE(firstClass, secondClass); + REQUIRE(firstClass != secondClass); for (size_t i = 13; i < 20; ++i) - BOOST_REQUIRE_EQUAL(assignments(i), secondClass); + REQUIRE(assignments(i) == secondClass); size_t thirdClass = assignments(20); // To ensure that this is the third class which we haven't seen yet. - BOOST_REQUIRE_NE(firstClass, thirdClass); - BOOST_REQUIRE_NE(secondClass, thirdClass); + REQUIRE(firstClass != thirdClass); + REQUIRE(secondClass != thirdClass); for (size_t i = 20; i < 30; ++i) - BOOST_REQUIRE_EQUAL(assignments(i), thirdClass); + REQUIRE(assignments(i) == thirdClass); } // Generate samples from four Gaussians, and make sure mean shift nearly // recovers those four centers. -BOOST_AUTO_TEST_CASE(GaussianClustering) +TEST_CASE("GaussianClustering", "[MeanShiftTest]") { GaussianDistribution g1("0.0 0.0 0.0", arma::eye(3, 3)); GaussianDistribution g2("5.0 5.0 5.0", 2 * arma::eye(3, 3)); @@ -162,7 +160,5 @@ BOOST_AUTO_TEST_CASE(GaussianClustering) break; } - BOOST_REQUIRE_EQUAL(success, true); + REQUIRE(success == true); } - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/random_forest_test.cpp b/src/mlpack/tests/random_forest_test.cpp index edc6bb2b60..3db62942c3 100644 --- a/src/mlpack/tests/random_forest_test.cpp +++ b/src/mlpack/tests/random_forest_test.cpp @@ -13,8 +13,9 @@ #include #include +#include "serialization_catch.hpp" +#include "test_catch_tools.hpp" #include "catch.hpp" -#include "serialization.hpp" #include "mock_categorical_data.hpp" using namespace mlpack; From 785def258acaa4c79c547cae934a50d31b7b419b Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Tue, 6 Oct 2020 00:44:53 +0530 Subject: [PATCH 06/11] reverted changed test names --- src/mlpack/tests/range_search_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index 41185f7a8a..464f827f64 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -1074,7 +1074,7 @@ TEST_CASE("EmptySearchTest", "[RangeSearchTest]") /** * Make sure things work right after Train() is called. */ -TEST_CASE("RangeTrainTest", "[RangeSearchTest]") +TEST_CASE("TrainTest", "[RangeSearchTest]") { RangeSearch<> empty; From f326b6e86ba1517a4c0237effdd5065a72f03486 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Tue, 6 Oct 2020 01:14:13 +0530 Subject: [PATCH 07/11] tests with same name changed --- src/mlpack/tests/range_search_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index 464f827f64..af01a26ccc 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -1074,7 +1074,7 @@ TEST_CASE("EmptySearchTest", "[RangeSearchTest]") /** * Make sure things work right after Train() is called. */ -TEST_CASE("TrainTest", "[RangeSearchTest]") +TEST_CASE("RangeSearchTrainTest", "[RangeSearchTest]") { RangeSearch<> empty; @@ -1448,7 +1448,7 @@ TEST_CASE("NeighborPtrDeleteTest", "[RangeSearchTest]") /** * Test copy constructor and copy operator. */ -TEST_CASE("CopyConstructorAndOperatorTest", "[RangeSearchTest]") +TEST_CASE("RangeSearchCopyConstructorAndOperatorTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<> rs(std::move(dataset)); @@ -1493,7 +1493,7 @@ TEST_CASE("CopyConstructorAndOperatorTest", "[RangeSearchTest]") /** * Test move constructor. */ -TEST_CASE("MoveConstructorTest", "[RangeSearchTest]") +TEST_CASE("RangeSearchMoveConstructorTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<>* rs = new RangeSearch<>(std::move(dataset)); @@ -1532,7 +1532,7 @@ TEST_CASE("MoveConstructorTest", "[RangeSearchTest]") /** * Test move operator. */ -TEST_CASE("MoveOperatorTest", "[RangeSearchTest]") +TEST_CASE("RangeSearchMoveOperatorTest", "[RangeSearchTest]") { arma::mat dataset = arma::randu(5, 500); RangeSearch<>* rs = new RangeSearch<>(std::move(dataset)); From 0b83c2add01763480ec9fc26bc02a1ccb00f1a98 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Tue, 6 Oct 2020 01:21:24 +0530 Subject: [PATCH 08/11] Revert "updating range_search_test with mlpack/master (#7)" This reverts commit 403b11ebbe8ccbdcc1c651296224bc2341e2b7b4. --- .ci/windows-steps.yaml | 1 - .github/workflows/main.yml | 66 +- HISTORY.md | 2 - src/mlpack/methods/ann/layer/CMakeLists.txt | 2 - src/mlpack/methods/ann/layer/add.hpp | 3 - .../methods/ann/layer/atrous_convolution.hpp | 6 - src/mlpack/methods/ann/layer/layer.hpp | 1 - src/mlpack/methods/ann/layer/linear.hpp | 6 - src/mlpack/methods/ann/layer/softmin.hpp | 97 --- src/mlpack/methods/ann/layer/softmin_impl.hpp | 61 -- src/mlpack/tests/CMakeLists.txt | 8 +- .../tests/activation_functions_test.cpp | 72 -- src/mlpack/tests/ann_layer_test.cpp | 201 +++--- src/mlpack/tests/ann_visitor_test.cpp | 34 - src/mlpack/tests/det_test.cpp | 469 +++++++------ src/mlpack/tests/distribution_test.cpp | 618 +++++++++--------- src/mlpack/tests/feedforward_network_test.cpp | 10 +- .../tests/main_tests/mean_shift_test.cpp | 69 +- src/mlpack/tests/mean_shift_test.cpp | 26 +- src/mlpack/tests/random_forest_test.cpp | 3 +- 20 files changed, 700 insertions(+), 1055 deletions(-) delete mode 100644 src/mlpack/methods/ann/layer/softmin.hpp delete mode 100644 src/mlpack/methods/ann/layer/softmin_impl.hpp diff --git a/.ci/windows-steps.yaml b/.ci/windows-steps.yaml index 69a33520a3..069c6c5b46 100644 --- a/.ci/windows-steps.yaml +++ b/.ci/windows-steps.yaml @@ -78,7 +78,6 @@ steps: msbuildVersion: $(MSBuildVersion) configuration: 'Release' msbuildArchitecture: 'x64' - platform: 'x64' msbuildArguments: /m /p:BuildInParallel=true maximumCpuCount: false clean: false diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8640c26471..8a4790897d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,31 +8,13 @@ on: - master release: types: [published, created, edited] -name: R CMD check mlpack jobs: - cancel: - name: 'Cancel Previous Builds' - if: ${{ github.event_name == 'pull_request' && github.repository == 'mlpack/mlpack' }} - runs-on: ubuntu-latest - timeout-minutes: 3 - steps: - - name: Get all workflow ids and set to env variable - run: echo ::set-env name=WORKFLOW_IDS_TO_CANCEL::$(curl https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows -s | jq -r '.workflows | map(.id|tostring) | join(",")') - - - uses: styfle/cancel-workflow-action@0.5.0 - with: - workflow_id: ${{ env.WORKFLOW_IDS_TO_CANCEL }} - access_token: ${{ secrets.GITHUB_TOKEN }} - jobR: - name: Build mlpack_r_tarball - if: ${{ github.repository == 'mlpack/mlpack' }} + name: mlpack-R runs-on: ubuntu-20.04 - outputs: r_bindings: ${{ steps.mlpack_version.outputs.mlpack_r_package }} - steps: - uses: actions/checkout@v2 @@ -45,35 +27,16 @@ jobs: MLPACK_VERSION_VALUE=${MLPACK_VERSION_MAJOR}.${MLPACK_VERSION_MINOR}.${MLPACK_VERSION_PATCH} echo ::set-output name=mlpack_r_package::$(echo mlpack_"$MLPACK_VERSION_VALUE".tar.gz) - - uses: r-lib/actions/setup-r@master - with: - r-version: release - - - name: Query dependencies - run: | - cp src/mlpack/bindings/R/mlpack/DESCRIPTION.in DESCRIPTION - Rscript -e "install.packages('remotes')" -e "saveRDS(remotes::dev_package_deps(dependencies = TRUE), 'depends.Rds')" - - - name: Cache R packages - if: runner.os != 'Windows' - uses: actions/cache@v1 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-r-release-${{ hashFiles('depends.Rds') }} - restore-keys: ${{ runner.os }}-r-release- - - name: Install Build Dependencies run: | sudo apt-get update sudo apt-get install -y --allow-unauthenticated libopenblas-dev liblapack-dev g++ libboost-all-dev curl https://data.kurg.org/armadillo-8.400.0.tar.xz | tar -xvJ && cd armadillo* cmake . && make && sudo make install && cd .. - - - name: Install R-bindings dependencies - run: | - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("roxygen2") - shell: Rscript {0} + sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran40/' + sudo apt-get -y update + sudo apt-get install -y r-base-core + sudo Rscript -e "install.packages(c('Rcpp', 'RcppArmadillo', 'RcppEnsmallen', 'BH', 'roxygen2', 'testthat'))" - name: CMake run: | @@ -95,7 +58,6 @@ jobs: runs-on: ${{ matrix.config.os }} name: ${{ matrix.config.os }} (${{ matrix.config.r }}) - if: ${{ github.repository == 'mlpack/mlpack' }} strategy: fail-fast: false @@ -112,8 +74,6 @@ jobs: R_CHECK_ARGS: "--no-build-vignettes" _R_CHECK_FORCE_SUGGESTS: 0 R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - RSPM: ${{ matrix.config.rspm }} - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/download-artifact@v2 @@ -126,22 +86,10 @@ jobs: - uses: r-lib/actions/setup-pandoc@master - - name: Query dependencies - run: Rscript -e "install.packages('remotes')" -e "saveRDS(remotes::dev_package_deps('${{ needs.jobR.outputs.r_bindings }}', dependencies = TRUE), 'depends.Rds')" - - - name: Cache R packages - if: runner.os != 'Windows' - uses: actions/cache@v1 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{ hashFiles('depends.Rds') }} - restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}- - - name: Install dependencies run: | - remotes::install_deps('${{ needs.jobR.outputs.r_bindings }}', dependencies = TRUE) - remotes::install_cran("rcmdcheck") - shell: Rscript {0} + Rscript -e "install.packages('remotes')" -e "remotes::install_cran('rcmdcheck')" + Rscript -e "install.packages(c('Rcpp', 'RcppArmadillo', 'RcppEnsmallen', 'BH', 'roxygen2', 'testthat'))" - name: Check run: Rscript -e "rcmdcheck::rcmdcheck('${{ needs.jobR.outputs.r_bindings }}', args = c('--no-manual','--as-cran'), error_on = 'warning', check_dir = 'check')" diff --git a/HISTORY.md b/HISTORY.md index 5acdedcb4f..d7a2437e9e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,8 +2,6 @@ ###### ????-??-?? * Added Mean Absolute Percentage Error. - * Added Softmin activation function as layer in ann/layer. - ### mlpack 3.4.1 ###### 2020-09-07 * Fix incorrect parsing of required matrix/model parameters for command-line diff --git a/src/mlpack/methods/ann/layer/CMakeLists.txt b/src/mlpack/methods/ann/layer/CMakeLists.txt index b4726b0c6f..34ea03c6a7 100644 --- a/src/mlpack/methods/ann/layer/CMakeLists.txt +++ b/src/mlpack/methods/ann/layer/CMakeLists.txt @@ -116,8 +116,6 @@ set(SOURCES celu_impl.hpp softshrink.hpp softshrink_impl.hpp - softmin.hpp - softmin_impl.hpp ) # Add directory name to sources. diff --git a/src/mlpack/methods/ann/layer/add.hpp b/src/mlpack/methods/ann/layer/add.hpp index 42b27809b8..b3f95dbbcc 100644 --- a/src/mlpack/methods/ann/layer/add.hpp +++ b/src/mlpack/methods/ann/layer/add.hpp @@ -100,9 +100,6 @@ class Add //! Get the output size. size_t OutputSize() const { return outSize; } - //! Get the size of weights. - size_t WeightSize() const { return outSize; } - /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/atrous_convolution.hpp b/src/mlpack/methods/ann/layer/atrous_convolution.hpp index b3dfd1ce85..b2a8f497e6 100644 --- a/src/mlpack/methods/ann/layer/atrous_convolution.hpp +++ b/src/mlpack/methods/ann/layer/atrous_convolution.hpp @@ -257,12 +257,6 @@ class AtrousConvolution //! Modify the internal Padding layer. ann::Padding<>& Padding() { return padding; } - //! Get size of the weight matrix. - size_t WeightSize() const - { - return (outSize * inSize * kernelWidth * kernelHeight) + outSize; - } - /** * Serialize the layer. */ diff --git a/src/mlpack/methods/ann/layer/layer.hpp b/src/mlpack/methods/ann/layer/layer.hpp index 947395fd6b..d005d1eb42 100644 --- a/src/mlpack/methods/ann/layer/layer.hpp +++ b/src/mlpack/methods/ann/layer/layer.hpp @@ -66,7 +66,6 @@ #include "sequential.hpp" #include "softshrink.hpp" #include "softmax.hpp" -#include "softmin.hpp" #include "spatial_dropout.hpp" #include "subview.hpp" #include "transposed_convolution.hpp" diff --git a/src/mlpack/methods/ann/layer/linear.hpp b/src/mlpack/methods/ann/layer/linear.hpp index 6dfd719d5f..1930181654 100644 --- a/src/mlpack/methods/ann/layer/linear.hpp +++ b/src/mlpack/methods/ann/layer/linear.hpp @@ -146,12 +146,6 @@ class Linear //! Modify the bias weights of the layer. OutputDataType& Bias() { return bias; } - //! Get the size of the weights. - size_t WeightSize() const - { - return (inSize * outSize) + outSize; - } - /** * Serialize the layer */ diff --git a/src/mlpack/methods/ann/layer/softmin.hpp b/src/mlpack/methods/ann/layer/softmin.hpp deleted file mode 100644 index a7b882c942..0000000000 --- a/src/mlpack/methods/ann/layer/softmin.hpp +++ /dev/null @@ -1,97 +0,0 @@ -/** - * @file methods/ann/layer/softmin.hpp - * @author Aakash Kaushik - * - * Definition of the Softmin class. - * - * mlpack is free software; you may redistribute it and/or modify it under the - * terms of the 3-clause BSD license. You should have received a copy of the - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ - -#ifndef MLPACK_METHODS_ANN_LAYER_SOFTMIN_HPP -#define MLPACK_METHODS_ANN_LAYER_SOFTMIN_HPP - -#include - -namespace mlpack { -namespace ann /** Artificial Neural Network. */ { - -/** - * Implementation of the Softmin layer. The Softmin function takes as a input - * a vector of K real numbers, rescaling them so that the elements of the - * K-dimensional output vector lie in the range [0, 1] and sum to 1. - * - * @tparam InputDataType Type of the input data (arma::colvec, arma::mat, - * arma::sp_mat or arma::cube). - * @tparam OutputDataType Type of the output data (arma::colvec, arma::mat, - * arma::sp_mat or arma::cube). - */ -template < - typename InputDataType = arma::mat, - typename OutputDataType = arma::mat -> -class Softmin -{ - public: - /** - * Create the Softmin object. - */ - Softmin(); - - /** - * Ordinary feed forward pass of a neural network, evaluating the function - * f(x) by propagating the activity forward through f. - * - * @param input Input data used for evaluating the specified function. - * @param output Resulting output activation. - */ - template - void Forward(const InputType& input, OutputType& output); - - /** - * Ordinary feed backward pass of a neural network, calculating the function - * f(x) by propagating x backwards through f. Using the results from the feed - * forward pass. - * - * @param input The propagated input activation. - * @param gy The backpropagated error. - * @param g The calculated gradient. - */ - template - void Backward(const arma::Mat& input, - const arma::Mat& gy, - arma::Mat& g); - - //! Get the output parameter. - OutputDataType& OutputParameter() const { return outputParameter; } - //! Modify the output parameter. - OutputDataType& OutputParameter() { return outputParameter; } - - //! Get the delta. - InputDataType& Delta() const { return delta; } - //! Modify the delta. - InputDataType& Delta() { return delta; } - - /** - * Serialize the layer. - */ - template - void serialize(Archive& /* ar */, const unsigned int /* version */); - - private: - //! Locally-stored delta object. - OutputDataType delta; - - //! Locally stored output parameter object. - OutputDataType outputParameter; -}; // class Softmin - -} // namespace ann -} // namespace mlpack - -// Include implementation. -#include "softmin_impl.hpp" - -#endif diff --git a/src/mlpack/methods/ann/layer/softmin_impl.hpp b/src/mlpack/methods/ann/layer/softmin_impl.hpp deleted file mode 100644 index 7693ca11dd..0000000000 --- a/src/mlpack/methods/ann/layer/softmin_impl.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/** - * @file methods/ann/layer/softmin_impl.hpp - * @author Aakash Kaushik - * - * Implementation of the Softmin class. - * - * mlpack is free software; you may redistribute it and/or modify it under the - * terms of the 3-clause BSD license. You should have received a copy of the - * 3-clause BSD license along with mlpack. If not, see - * http://www.opensource.org/licenses/BSD-3-Clause for more information. - */ -#ifndef MLPACK_METHODS_ANN_LAYER_SOFTMIN_IMPL_HPP -#define MLPACK_METHODS_ANN_LAYER_SOFTMIN_IMPL_HPP - -// In case it hasn't yet been included. -#include "softmin.hpp" - -namespace mlpack { -namespace ann /** Artificial Neural Network. */ { - -template -Softmin::Softmin() -{ - // Nothing to do here. -} - -template -template -void Softmin::Forward( - const InputType& input, - OutputType& output) -{ - InputType inputMin = arma::repmat(arma::min(input,0), input.n_rows, 1); - output = arma::repmat(arma::log(arma::sum( - arma::exp(-(input - inputMin)),0)), input.n_rows, 1); - output = arma::exp(-(input - inputMin) - output); -} - -template -template -void Softmin::Backward( - const arma::Mat& input, - const arma::Mat& gy, - arma::Mat& g) -{ - g = input % (gy - arma::repmat(arma::sum(gy % input), input.n_rows, 1)); -} - -template -template -void Softmin::serialize( - Archive& /* ar */, - const unsigned int /* version */) -{ - // Nothing to do here. -} - -} // namespace ann -} // namespace mlpack - -#endif diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index b273dd3e4e..fae84ae9a8 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -8,6 +8,8 @@ add_executable(mlpack_test io_test.cpp cosine_tree_test.cpp dcgan_test.cpp + det_test.cpp + distribution_test.cpp drusilla_select_test.cpp emst_test.cpp fastmks_test.cpp @@ -34,6 +36,7 @@ add_executable(mlpack_test math_test.cpp matrix_completion_test.cpp maximal_inputs_test.cpp + mean_shift_test.cpp metric_test.cpp mlpack_test.cpp mock_categorical_data.hpp @@ -89,6 +92,7 @@ add_executable(mlpack_test main_tests/local_coordinate_coding_test.cpp main_tests/logistic_regression_test.cpp main_tests/lsh_test.cpp + main_tests/mean_shift_test.cpp main_tests/nbc_test.cpp main_tests/nmf_test.cpp main_tests/perceptron_test.cpp @@ -118,8 +122,6 @@ add_executable(mlpack_catch_test dbscan_test.cpp decision_stump_test.cpp decision_tree_test.cpp - det_test.cpp - distribution_test.cpp feedforward_network_test.cpp image_load_test.cpp imputation_test.cpp @@ -133,7 +135,6 @@ add_executable(mlpack_catch_test load_save_test.cpp loss_functions_test.cpp main.cpp - mean_shift_test.cpp nca_test.cpp one_hot_encoding_test.cpp pca_test.cpp @@ -167,7 +168,6 @@ add_executable(mlpack_catch_test main_tests/kmeans_test.cpp main_tests/knn_test.cpp main_tests/linear_regression_test.cpp - main_tests/mean_shift_test.cpp main_tests/nca_test.cpp main_tests/pca_test.cpp main_tests/preprocess_binarize_test.cpp diff --git a/src/mlpack/tests/activation_functions_test.cpp b/src/mlpack/tests/activation_functions_test.cpp index 9ee1ebcaf9..2c1fe63398 100644 --- a/src/mlpack/tests/activation_functions_test.cpp +++ b/src/mlpack/tests/activation_functions_test.cpp @@ -558,58 +558,6 @@ void CheckCELUDerivativeCorrect(const arma::colvec input, } } -/** - * Implementation of the Softmin activation function test. The function is - * implemented as Softmin layer in the file softmin.hpp. - * - * @param input Input data used for evaluating the Softmin activation function. - * @param target Target data used to evaluate the Softmin activation. - */ -void CheckSoftminActivationCorrect(const arma::colvec input, - const arma::colvec target) -{ - // Initialize Softmin object. - Softmin<> softmin; - - // Test the activation function using the entire vector as input. - arma::colvec activations; - softmin.Forward(input,activations); - for (size_t i = 0; i < activations.n_elem; ++i) - { - REQUIRE(activations.at(i) == Approx(target.at(i)).epsilon(1e-5)); - } -} - -/** - * Implementation of the Softmin activation function derivative test. - * The function is implemented as Softmin layer in the file softmin.hpp. - * - * @param input Input data used for evaluating the Softmin activation function. - * @param target Target data used to evaluate the Softmin activation. - */ -void CheckSoftminDerivativeCorrect(const arma::colvec input, - const arma::colvec target) -{ - // Initialize Softmin object. - Softmin<> softmin; - - // Test the calculation of the derivatives using the entire vector as input. - arma::colvec derivatives, activations; - - // This error vector will be set to [[1.0],[0.0],[1.0],[0.0]] - // to get the derivatives. - arma::colvec error = arma::ones(input.n_elem); - error(1) = 0.0; - error(3) = 0.0; - softmin.Forward(input, activations); - softmin.Backward(activations, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; ++i) - { - REQUIRE(derivatives.at(i) == Approx(target.at(i)).epsilon(1e-5)); - } - -} - /** * Basic test of the tanh function. */ @@ -1115,23 +1063,3 @@ TEST_CASE("GaussianFunctionTest", "[ActivationFunctionsTest]") CheckDerivativeCorrect(desiredActivations, desiredDerivatives); } - -/** - * Basic test of the Softmin function. - */ -TEST_CASE("SoftminFunctionTest", "[ActivationFunctionsTest]") -{ - const arma::colvec activationData("4.2 2.4 7.0 6.4"); - - // Hand-calculated Values. - const arma::colvec desiredActivations("0.1384799751 0.8377550303 \ - 0.008420976 0.0153440186"); - - const arma::colvec desiredDerivatives("0.1181371351 -0.12306701070 \ - 0.0071839266 -0.0022540509"); - - CheckSoftminActivationCorrect(activationData, - desiredActivations); - CheckSoftminDerivativeCorrect(activationData, - desiredDerivatives); -} diff --git a/src/mlpack/tests/ann_layer_test.cpp b/src/mlpack/tests/ann_layer_test.cpp index 37a5a5b192..dfd1ecf091 100644 --- a/src/mlpack/tests/ann_layer_test.cpp +++ b/src/mlpack/tests/ann_layer_test.cpp @@ -87,10 +87,11 @@ TEST_CASE("GradientAddLayerTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -415,10 +416,11 @@ TEST_CASE("GradientLinearLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -506,12 +508,13 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - inSize(4), - outSize(1), - nPoints(2), - batchSize(4) + GradientFunction() { + const size_t inSize = 4; + const size_t outSize = 1; + const size_t nPoints = 2; + const size_t batchSize = 4; + input = arma::randu(inSize * nPoints, batchSize); target = arma::zeros(outSize * nPoints, batchSize); target(0, 0) = 1; @@ -542,10 +545,6 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]") FFN, RandomInitialization>* model; arma::mat input, target; - const size_t inSize; - const size_t outSize; - const size_t nPoints; - const size_t batchSize; } function; REQUIRE(CheckGradient(function) <= 1e-7); @@ -592,10 +591,11 @@ TEST_CASE("GradientNoisyLinearLayerTest", "[ANNLayerTest]") // Noisy linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -695,10 +695,11 @@ TEST_CASE("GradientLinearNoBiasLayerTest", "[ANNLayerTest]") // LinearNoBias function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -796,10 +797,11 @@ TEST_CASE("GradientFlexibleReLULayerTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(2, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(2, 1); + target = arma::mat("1"); + model = new FFN, RandomInitialization>( NegativeLogLikelihood<>(), RandomInitialization(0.1, 0.5)); @@ -1015,10 +1017,10 @@ TEST_CASE("GradientLSTMLayerTest", "[ANNLayerTest]") // LSTM function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(1, 1, 5)), - target(arma::ones(1, 1, 5)) + GradientFunction() { + input = arma::randu(1, 1, 5); + target.ones(1, 1, 5); const size_t rho = 5; model = new RNN >(rho); @@ -1120,10 +1122,10 @@ TEST_CASE("GradientFastLSTMLayerTest", "[ANNLayerTest]") // Fast LSTM function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(1, 1, 5)), - target(arma::ones(1, 1, 5)) + GradientFunction() { + input = arma::randu(1, 1, 5); + target = arma::ones(1, 1, 5); const size_t rho = 5; model = new RNN >(rho); @@ -1389,10 +1391,10 @@ TEST_CASE("GradientGRULayerTest", "[ANNLayerTest]") // GRU function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(1, 1, 5)), - target(arma::ones(1, 1, 5)) + GradientFunction() { + input = arma::randu(1, 1, 5); + target = arma::ones(1, 1, 5); const size_t rho = 5; model = new RNN >(rho); @@ -1629,10 +1631,11 @@ TEST_CASE("GradientConcatLayerTest", "[ANNLayerTest]") // Concat function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -1697,10 +1700,11 @@ TEST_CASE("GradientConcatenateLayerTest", "[ANNLayerTest]") // Concatenate function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -1901,10 +1905,11 @@ TEST_CASE("GradientSoftmaxTest", "[ANNLayerTest]") // Softmax function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1; 0")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1; 0"); + model = new FFN, RandomInitialization>; model->Predictors() = input; model->Responses() = target; @@ -2104,10 +2109,12 @@ TEST_CASE("GradientBatchNormTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randn(32, 2048)), - target(arma::ones(1, 2048)) + GradientFunction() { + input = arma::randn(32, 2048); + arma::mat target; + target.ones(1, 2048); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2177,11 +2184,12 @@ TEST_CASE("GradientVirtualBatchNormTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randn(5, 256)), - target(arma::ones(1, 256)) + GradientFunction() { + input = arma::randn(5, 256); arma::mat referenceBatch = arma::mat(input.memptr(), input.n_rows, 16); + arma::mat target; + target.ones(1, 256); model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; @@ -2239,10 +2247,12 @@ TEST_CASE("MiniBatchDiscriminationTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randn(5, 4)), - target(arma::ones(1, 4)) + GradientFunction() { + input = arma::randn(5, 4); + arma::mat target; + target.ones(1, 4); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2417,10 +2427,11 @@ TEST_CASE("GradientTransposedConvolutionLayerTest", "[ANNLayerTest]") { struct GradientFunction { - GradientFunction() : - input(arma::linspace(0, 35, 36)), - target(arma::mat("1")) + GradientFunction() { + input = arma::linspace(0, 35, 36); + target = arma::mat("1"); + model = new FFN, RandomInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2533,10 +2544,11 @@ TEST_CASE("GradientAtrousConvolutionLayerTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::linspace(0, 35, 36)), - target(arma::mat("1")) + GradientFunction() { + input = arma::linspace(0, 35, 36); + target = arma::mat("1"); + model = new FFN, RandomInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -2563,7 +2575,7 @@ TEST_CASE("GradientAtrousConvolutionLayerTest", "[ANNLayerTest]") arma::mat input, target; } function; - // TODO: this tolerance seems far higher than necessary. The implementation + // TODO: this tolerance seems far higher than necessary. The implementation // should be checked. REQUIRE(CheckGradient(function) <= 0.2); } @@ -2714,10 +2726,12 @@ TEST_CASE("GradientLayerNormTest", "[ANNLayerTest]") // Add function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randn(10, 256)), - target(arma::ones(1, 256)) + GradientFunction() { + input = arma::randn(10, 256); + arma::mat target; + target.ones(1, 256); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3034,10 +3048,11 @@ TEST_CASE("GradientReparametrizationLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3077,10 +3092,11 @@ TEST_CASE("GradientReparametrizationLayerBetaTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 2)), - target(arma::mat("1 1")) + GradientFunction() { + input = arma::randu(10, 2); + target = arma::mat("1 1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3232,10 +3248,11 @@ TEST_CASE("GradientHighwayLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(5, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(5, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3283,10 +3300,11 @@ TEST_CASE("GradientSequentialLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -3333,10 +3351,11 @@ TEST_CASE("GradientWeightNormLayerTest", "[ANNLayerTest]") // Linear function gradient instantiation. struct GradientFunction { - GradientFunction() : - input(arma::randu(10, 1)), - target(arma::mat("1")) + GradientFunction() { + input = arma::randu(10, 1); + target = arma::mat("1"); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -4166,10 +4185,12 @@ TEST_CASE("GradientBatchNormWithMiniBatchesTest", "[ANNLayerTest]") { struct GradientFunction { - GradientFunction() : - input(arma::randn(16, 1024)), - target(arma::ones(1, 1024)) + GradientFunction() { + input = arma::randn(16, 1024); + arma::mat target; + target.ones(1, 1024); + model = new FFN, NguyenWidrowInitialization>(); model->Predictors() = input; model->Responses() = target; @@ -4662,13 +4683,7 @@ TEST_CASE("GradientMultiheadAttentionTest", "[ANNLayerTest]") { struct GradientFunction { - GradientFunction() : - tgtSeqLen(2), - srcSeqLen(2), - embedDim(4), - nHeads(2), - vocabSize(5), - batchSize(2) + GradientFunction() { input = arma::randu(embedDim * (tgtSeqLen + 2 * srcSeqLen), batchSize); target = arma::zeros(vocabSize, batchSize); @@ -4721,13 +4736,13 @@ TEST_CASE("GradientMultiheadAttentionTest", "[ANNLayerTest]") MultiheadAttention<>* attnModule; arma::mat input, target, attnMask, keyPaddingMask; - const size_t tgtSeqLen; - const size_t srcSeqLen; - const size_t embedDim; - const size_t nHeads; - const size_t vocabSize; - const size_t batchSize; + const size_t tgtSeqLen = 2; + const size_t srcSeqLen = 2; + const size_t embedDim = 4; + const size_t nHeads = 2; + const size_t vocabSize = 5; + const size_t batchSize = 2; } function; - REQUIRE(CheckGradient(function) <= 3e-06); + REQUIRE(CheckGradient(function) <= 2e-06); } diff --git a/src/mlpack/tests/ann_visitor_test.cpp b/src/mlpack/tests/ann_visitor_test.cpp index ccf3cca35f..1b01308ff3 100644 --- a/src/mlpack/tests/ann_visitor_test.cpp +++ b/src/mlpack/tests/ann_visitor_test.cpp @@ -52,37 +52,3 @@ TEST_CASE("BiasSetVisitorTest", "[ANNVisitorTest]") boost::apply_visitor(DeleteVisitor(), linear); } - -/** - * Test that WeightSetVisitor works properly. - */ -TEST_CASE("WeightSetVisitorTest", "[ANNVisitorTest]") -{ - size_t randomSize = arma::randi(arma::distr_param(1, 100)); - - LayerTypes<> linear = new Linear<>(randomSize, randomSize); - - arma::mat layerWeights(randomSize * randomSize + randomSize, 1); - layerWeights.zeros(); - - size_t setWeights = boost::apply_visitor(WeightSetVisitor(layerWeights, 0), - linear); - - REQUIRE(setWeights == randomSize * randomSize + randomSize); -} - -/** - * Test that WeightSizeVisitor works properly. - */ -TEST_CASE("WeightSizeVisitorTest", "[ANNVisitorTest]") -{ - size_t randomSize = arma::randi(arma::distr_param(1, 100)); - - LayerTypes<> linear = new Linear<>(randomSize, randomSize); - - size_t weightSize = boost::apply_visitor(WeightSizeVisitor(), - linear); - - REQUIRE(weightSize == randomSize * randomSize + randomSize); -} - diff --git a/src/mlpack/tests/det_test.cpp b/src/mlpack/tests/det_test.cpp index c0989768eb..4a16bbd060 100644 --- a/src/mlpack/tests/det_test.cpp +++ b/src/mlpack/tests/det_test.cpp @@ -11,7 +11,8 @@ * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #include -#include "catch.hpp" +#include +#include "test_tools.hpp" // This trick does not work on Windows. We will have to comment out the tests // that depend on it. @@ -32,11 +33,13 @@ using namespace mlpack; using namespace mlpack::det; using namespace std; +BOOST_AUTO_TEST_SUITE(DETTest); + // Tests for the private functions. We cannot perform these if we are on // Windows because we cannot make private functions accessible using the macro // trick above. #ifndef _WIN32 -TEST_CASE("TestGetMaxMinVals", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestGetMaxMinVals) { arma::mat testData(3, 5); @@ -46,15 +49,15 @@ TEST_CASE("TestGetMaxMinVals", "[DETTest]") DTree tree(testData); - REQUIRE(tree.MaxVals()[0] == 7); - REQUIRE(tree.MinVals()[0] == 3); - REQUIRE(tree.MaxVals()[1] == 7); - REQUIRE(tree.MinVals()[1] == 0); - REQUIRE(tree.MaxVals()[2] == 8); - REQUIRE(tree.MinVals()[2] == 1); + BOOST_REQUIRE_EQUAL(tree.MaxVals()[0], 7); + BOOST_REQUIRE_EQUAL(tree.MinVals()[0], 3); + BOOST_REQUIRE_EQUAL(tree.MaxVals()[1], 7); + BOOST_REQUIRE_EQUAL(tree.MinVals()[1], 0); + BOOST_REQUIRE_EQUAL(tree.MaxVals()[2], 8); + BOOST_REQUIRE_EQUAL(tree.MinVals()[2], 1); } -TEST_CASE("TestComputeNodeError", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestComputeNodeError) { arma::vec maxVals("7 7 8"); arma::vec minVals("3 0 1"); @@ -62,18 +65,17 @@ TEST_CASE("TestComputeNodeError", "[DETTest]") DTree testDTree(maxVals, minVals, 5); double trueNodeError = -log(4.0) - log(7.0) - log(7.0); - REQUIRE((double) testDTree.logNegError == - Approx(trueNodeError).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE((double) testDTree.logNegError, trueNodeError, 1e-10); testDTree.start = 3; testDTree.end = 5; double nodeError = testDTree.LogNegativeError(5); trueNodeError = 2 * log(2.0 / 5.0) - log(4.0) - log(7.0) - log(7.0); - REQUIRE(nodeError == Approx(trueNodeError).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(nodeError, trueNodeError, 1e-10); } -TEST_CASE("TestWithinRange", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestWithinRange) { arma::vec maxVals("7 7 8"); arma::vec minVals("3 0 1"); @@ -83,14 +85,14 @@ TEST_CASE("TestWithinRange", "[DETTest]") arma::vec testQuery(3); testQuery << 4.5 << 2.5 << 2; - REQUIRE(testDTree.WithinRange(testQuery) == true); + BOOST_REQUIRE_EQUAL(testDTree.WithinRange(testQuery), true); testQuery << 8.5 << 2.5 << 2; - REQUIRE(testDTree.WithinRange(testQuery) == false); + BOOST_REQUIRE_EQUAL(testDTree.WithinRange(testQuery), false); } -TEST_CASE("TestFindSplit", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestFindSplit) { arma::mat testData(3, 5); @@ -106,21 +108,20 @@ TEST_CASE("TestFindSplit", "[DETTest]") size_t trueDim = 2; double trueSplit = 5.5; double trueLeftError = 2 * log(2.0 / 5.0) - (log(7.0) + log(4.0) + log(4.5)); - double trueRightError = 2 * log(3.0 / 5.0) - (log(7.0) + log(4.0) + - log(2.5)); + double trueRightError = 2 * log(3.0 / 5.0) - (log(7.0) + log(4.0) + log(2.5)); testDTree.logVolume = log(7.0) + log(4.0) + log(7.0); - REQUIRE(testDTree.FindSplit( + BOOST_REQUIRE(testDTree.FindSplit( testData, obDim, obSplit, obLeftError, obRightError, 1)); - REQUIRE(trueDim == obDim); - REQUIRE(trueSplit == Approx(obSplit).epsilon(1e-12)); + BOOST_REQUIRE(trueDim == obDim); + BOOST_REQUIRE_CLOSE(trueSplit, obSplit, 1e-10); - REQUIRE(trueLeftError == Approx(obLeftError).epsilon(1e-12)); - REQUIRE(trueRightError == Approx(obRightError).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(trueLeftError, obLeftError, 1e-10); + BOOST_REQUIRE_CLOSE(trueRightError, obRightError, 1e-10); } -TEST_CASE("TestSplitData", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestSplitData) { arma::mat testData(3, 5); @@ -139,16 +140,16 @@ TEST_CASE("TestSplitData", "[DETTest]") size_t splitInd = testDTree.SplitData( testData, splitDim, trueSplitVal, oTest); - REQUIRE(splitInd == 2); // 2 points on left side. + BOOST_REQUIRE_EQUAL(splitInd, 2); // 2 points on left side. - REQUIRE(oTest[0] == 1); - REQUIRE(oTest[1] == 4); - REQUIRE(oTest[2] == 3); - REQUIRE(oTest[3] == 2); - REQUIRE(oTest[4] == 5); + BOOST_REQUIRE_EQUAL(oTest[0], 1); + BOOST_REQUIRE_EQUAL(oTest[1], 4); + BOOST_REQUIRE_EQUAL(oTest[2], 3); + BOOST_REQUIRE_EQUAL(oTest[3], 2); + BOOST_REQUIRE_EQUAL(oTest[4], 5); } -TEST_CASE("TestSparseFindSplit", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestSparseFindSplit) { arma::mat realData(4, 7); @@ -172,17 +173,17 @@ TEST_CASE("TestSparseFindSplit", "[DETTest]") (log(7.0) + log(6.5) + log(8.0) + log(6.0)); testDTree.logVolume = log(7.0) + log(7.0) + log(8.0) + log(6.0); - REQUIRE(testDTree.FindSplit( + BOOST_REQUIRE(testDTree.FindSplit( testData, obDim, obSplit, obLeftError, obRightError, 1)); - REQUIRE(trueDim == obDim); - REQUIRE(trueSplit == Approx(obSplit).epsilon(1e-12)); + BOOST_REQUIRE(trueDim == obDim); + BOOST_REQUIRE_CLOSE(trueSplit, obSplit, 1e-10); - REQUIRE(trueLeftError == Approx(obLeftError).epsilon(1e-12)); - REQUIRE(trueRightError == Approx(obRightError).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(trueLeftError, obLeftError, 1e-10); + BOOST_REQUIRE_CLOSE(trueRightError, obRightError, 1e-10); } -TEST_CASE("TestSparseSplitData", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestSparseSplitData) { arma::mat realData(4, 7); @@ -204,22 +205,22 @@ TEST_CASE("TestSparseSplitData", "[DETTest]") size_t splitInd = testDTree.SplitData( testData, splitDim, trueSplitVal, oTest); - REQUIRE(splitInd == 3); // 2 points on left side. + BOOST_REQUIRE_EQUAL(splitInd, 3); // 2 points on left side. - REQUIRE(oTest[0] == 1); - REQUIRE(oTest[1] == 4); - REQUIRE(oTest[2] == 3); - REQUIRE(oTest[3] == 2); - REQUIRE(oTest[4] == 5); - REQUIRE(oTest[5] == 6); - REQUIRE(oTest[6] == 7); + BOOST_REQUIRE_EQUAL(oTest[0], 1); + BOOST_REQUIRE_EQUAL(oTest[1], 4); + BOOST_REQUIRE_EQUAL(oTest[2], 3); + BOOST_REQUIRE_EQUAL(oTest[3], 2); + BOOST_REQUIRE_EQUAL(oTest[4], 5); + BOOST_REQUIRE_EQUAL(oTest[5], 6); + BOOST_REQUIRE_EQUAL(oTest[6], 7); } #endif // Tests for the public functions. -TEST_CASE("TestGrow", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestGrow) { arma::mat testData(3, 5); @@ -243,36 +244,34 @@ TEST_CASE("TestGrow", "[DETTest]") DTree testDTree(testData); double alpha = testDTree.Grow(testData, oTest, false, 2, 1); - REQUIRE(oTest[0] == 0); - REQUIRE(oTest[1] == 3); - REQUIRE(oTest[2] == 1); - REQUIRE(oTest[3] == 2); - REQUIRE(oTest[4] == 4); + BOOST_REQUIRE_EQUAL(oTest[0], 0); + BOOST_REQUIRE_EQUAL(oTest[1], 3); + BOOST_REQUIRE_EQUAL(oTest[2], 1); + BOOST_REQUIRE_EQUAL(oTest[3], 2); + BOOST_REQUIRE_EQUAL(oTest[4], 4); // Test the structure of the tree. - REQUIRE(testDTree.Left()->Left() == NULL); - REQUIRE(testDTree.Left()->Right() == NULL); - REQUIRE(testDTree.Right()->Left()->Left() == NULL); - REQUIRE(testDTree.Right()->Left()->Right() == NULL); - REQUIRE(testDTree.Right()->Right()->Left() == NULL); - REQUIRE(testDTree.Right()->Right()->Right() == NULL); + BOOST_REQUIRE(testDTree.Left()->Left() == NULL); + BOOST_REQUIRE(testDTree.Left()->Right() == NULL); + BOOST_REQUIRE(testDTree.Right()->Left()->Left() == NULL); + BOOST_REQUIRE(testDTree.Right()->Left()->Right() == NULL); + BOOST_REQUIRE(testDTree.Right()->Right()->Left() == NULL); + BOOST_REQUIRE(testDTree.Right()->Right()->Right() == NULL); - REQUIRE(testDTree.SubtreeLeaves() == 3); + BOOST_REQUIRE(testDTree.SubtreeLeaves() == 3); - REQUIRE(testDTree.SplitDim() == 2); - REQUIRE(testDTree.SplitValue() == Approx(5.5).epsilon(1e-7)); - REQUIRE(testDTree.Right()->SplitDim() == 1); - REQUIRE(testDTree.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); + BOOST_REQUIRE(testDTree.SplitDim() == 2); + BOOST_REQUIRE_CLOSE(testDTree.SplitValue(), 5.5, 1e-5); + BOOST_REQUIRE(testDTree.Right()->SplitDim() == 1); + BOOST_REQUIRE_CLOSE(testDTree.Right()->SplitValue(), 0.5, 1e-5); // Test node errors for every node (these are private functions). #ifndef _WIN32 - REQUIRE(testDTree.logNegError == Approx(rootError).epsilon(1e-12)); - REQUIRE(testDTree.Left()->logNegError == Approx(lError).epsilon(1e-12)); - REQUIRE(testDTree.Right()->logNegError == Approx(rError).epsilon(1e-12)); - REQUIRE(testDTree.Right()->Left()->logNegError == - Approx(rlError).epsilon(1e-12)); - REQUIRE(testDTree.Right()->Right()->logNegError == - Approx(rrError).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(testDTree.logNegError, rootError, 1e-10); + BOOST_REQUIRE_CLOSE(testDTree.Left()->logNegError, lError, 1e-10); + BOOST_REQUIRE_CLOSE(testDTree.Right()->logNegError, rError, 1e-10); + BOOST_REQUIRE_CLOSE(testDTree.Right()->Left()->logNegError, rlError, 1e-10); + BOOST_REQUIRE_CLOSE(testDTree.Right()->Right()->logNegError, rrError, 1e-10); #endif // Test alpha. @@ -282,10 +281,10 @@ TEST_CASE("TestGrow", "[DETTest]") rAlpha = std::log(-(std::exp(rError) - (std::exp(rlError) + std::exp(rrError)))); - REQUIRE(alpha == Approx(min(rootAlpha, rAlpha)).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(alpha, min(rootAlpha, rAlpha), 1e-10); } -TEST_CASE("TestPruneAndUpdate", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestPruneAndUpdate) { arma::mat testData(3, 5); @@ -299,19 +298,18 @@ TEST_CASE("TestPruneAndUpdate", "[DETTest]") double alpha = testDTree.Grow(testData, oTest, false, 2, 1); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); - REQUIRE(alpha == Approx(numeric_limits::max()).epsilon(1e-12)); - REQUIRE(testDTree.SubtreeLeaves() == 1); + BOOST_REQUIRE_CLOSE(alpha, numeric_limits::max(), 1e-10); + BOOST_REQUIRE(testDTree.SubtreeLeaves() == 1); double rootError = -log(4.0) - log(7.0) - log(7.0); - REQUIRE(testDTree.LogNegError() == Approx(rootError).epsilon(1e-12)); - REQUIRE(testDTree.SubtreeLeavesLogNegError() == - Approx(rootError).epsilon(1e-12)); - REQUIRE(testDTree.Left() == NULL); - REQUIRE(testDTree.Right() == NULL); + BOOST_REQUIRE_CLOSE(testDTree.LogNegError(), rootError, 1e-10); + BOOST_REQUIRE_CLOSE(testDTree.SubtreeLeavesLogNegError(), rootError, 1e-10); + BOOST_REQUIRE(testDTree.Left() == NULL); + BOOST_REQUIRE(testDTree.Right() == NULL); } -TEST_CASE("TestComputeValue", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestComputeValue) { arma::mat testData(3, 5); @@ -336,22 +334,22 @@ TEST_CASE("TestComputeValue", "[DETTest]") double d2 = (1.0 / 5.0) / exp(log(4.0) + log(0.5) + log(2.5)); double d3 = (2.0 / 5.0) / exp(log(4.0) + log(6.5) + log(2.5)); - REQUIRE(d1 == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); - REQUIRE(d2 == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); - REQUIRE(d3 == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); - REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(d1, testDTree.ComputeValue(q1), 1e-10); + BOOST_REQUIRE_CLOSE(d2, testDTree.ComputeValue(q2), 1e-10); + BOOST_REQUIRE_CLOSE(d3, testDTree.ComputeValue(q3), 1e-10); + BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); double d = 1.0 / exp(log(4.0) + log(7.0) + log(7.0)); - REQUIRE(d == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); - REQUIRE(d == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); - REQUIRE(d == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); - REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q1), 1e-10); + BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q2), 1e-10); + BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q3), 1e-10); + BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); } -TEST_CASE("TestVariableImportance", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestVariableImportance) { arma::mat testData(3, 5); @@ -379,14 +377,12 @@ TEST_CASE("TestVariableImportance", "[DETTest]") testDTree.ComputeVariableImportance(imps); - REQUIRE((double) 0.0 == Approx(imps[0]).epsilon(1e-12)); - REQUIRE((double) (rError - (rlError + rrError)) == - Approx(imps[1]).epsilon(1e-12)); - REQUIRE((double) (rootError - (lError + rError)) == - Approx(imps[2]).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE((double) 0.0, imps[0], 1e-10); + BOOST_REQUIRE_CLOSE((double) (rError - (rlError + rrError)), imps[1], 1e-10); + BOOST_REQUIRE_CLOSE((double) (rootError - (lError + rError)), imps[2], 1e-10); } -TEST_CASE("TestSparsePruneAndUpdate", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestSparsePruneAndUpdate) { arma::mat realData(3, 5); @@ -403,19 +399,18 @@ TEST_CASE("TestSparsePruneAndUpdate", "[DETTest]") double alpha = testDTree.Grow(testData, oTest, false, 2, 1); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); - REQUIRE(alpha == Approx(numeric_limits::max()).epsilon(1e-12)); - REQUIRE(testDTree.SubtreeLeaves() == 1); + BOOST_REQUIRE_CLOSE(alpha, numeric_limits::max(), 1e-10); + BOOST_REQUIRE(testDTree.SubtreeLeaves() == 1); double rootError = -log(4.0) - log(7.0) - log(7.0); - REQUIRE(testDTree.LogNegError() == Approx(rootError).epsilon(1e-12)); - REQUIRE(testDTree.SubtreeLeavesLogNegError() == - Approx(rootError).epsilon(1e-12)); - REQUIRE(testDTree.Left() == NULL); - REQUIRE(testDTree.Right() == NULL); + BOOST_REQUIRE_CLOSE(testDTree.LogNegError(), rootError, 1e-10); + BOOST_REQUIRE_CLOSE(testDTree.SubtreeLeavesLogNegError(), rootError, 1e-10); + BOOST_REQUIRE(testDTree.Left() == NULL); + BOOST_REQUIRE(testDTree.Right() == NULL); } -TEST_CASE("TestSparseComputeValue", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestSparseComputeValue) { arma::mat realData(3, 5); @@ -443,25 +438,25 @@ TEST_CASE("TestSparseComputeValue", "[DETTest]") double d2 = (1.0 / 5.0) / exp(log(4.0) + log(0.5) + log(2.5)); double d3 = (2.0 / 5.0) / exp(log(4.0) + log(6.5) + log(2.5)); - REQUIRE(d1 == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); - REQUIRE(d2 == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); - REQUIRE(d3 == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); - REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(d1, testDTree.ComputeValue(q1), 1e-10); + BOOST_REQUIRE_CLOSE(d2, testDTree.ComputeValue(q2), 1e-10); + BOOST_REQUIRE_CLOSE(d3, testDTree.ComputeValue(q3), 1e-10); + BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); alpha = testDTree.PruneAndUpdate(alpha, testData.n_cols, false); double d = 1.0 / exp(log(4.0) + log(7.0) + log(7.0)); - REQUIRE(d == Approx(testDTree.ComputeValue(q1)).epsilon(1e-12)); - REQUIRE(d == Approx(testDTree.ComputeValue(q2)).epsilon(1e-12)); - REQUIRE(d == Approx(testDTree.ComputeValue(q3)).epsilon(1e-12)); - REQUIRE(0.0 == Approx(testDTree.ComputeValue(q4)).epsilon(1e-12)); + BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q1), 1e-10); + BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q2), 1e-10); + BOOST_REQUIRE_CLOSE(d, testDTree.ComputeValue(q3), 1e-10); + BOOST_REQUIRE_CLOSE(0.0, testDTree.ComputeValue(q4), 1e-10); } /** * These are not yet implemented. * -TEST_CASE("TestTagTree", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestTagTree) { MatType testData(3, 5); @@ -474,7 +469,7 @@ TEST_CASE("TestTagTree", "[DETTest]") delete testDTree; } -TEST_CASE("TestFindBucket", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestFindBucket) { MatType testData(3, 5); @@ -489,24 +484,24 @@ TEST_CASE("TestFindBucket", "[DETTest]") // Test functions in dt_utils.hpp -TEST_CASE("TestTrainer", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestTrainer) { } -TEST_CASE("TestPrintVariableImportance", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestPrintVariableImportance) { } -TEST_CASE("TestPrintLeafMembership", "[DETTest]") +BOOST_AUTO_TEST_CASE(TestPrintLeafMembership) { } */ // Test the copy constructor and the copy operator. -TEST_CASE("CopyConstructorAndOperatorTest", "[DETTest]") +BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest) { arma::mat testData(3, 5); @@ -549,76 +544,76 @@ TEST_CASE("CopyConstructorAndOperatorTest", "[DETTest]") delete testDTree; // Test the data of copied tree (using copy constructor). - REQUIRE(testDTree2.MaxVals()[0] == maxVals0); - REQUIRE(testDTree2.MinVals()[0] == minVals0); - REQUIRE(testDTree2.MaxVals()[1] == maxVals1); - REQUIRE(testDTree2.MinVals()[1] == minVals1); - REQUIRE(testDTree2.MaxVals()[2] == maxVals2); - REQUIRE(testDTree2.MinVals()[2] == minVals2); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); // Test the data of the copied tree (using the copy operator). - REQUIRE(testDTree3.MaxVals()[0] == maxVals0); - REQUIRE(testDTree3.MinVals()[0] == minVals0); - REQUIRE(testDTree3.MaxVals()[1] == maxVals1); - REQUIRE(testDTree3.MinVals()[1] == minVals1); - REQUIRE(testDTree3.MaxVals()[2] == maxVals2); - REQUIRE(testDTree3.MinVals()[2] == minVals2); + BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[0], maxVals0); + BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[0], minVals0); + BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[1], maxVals1); + BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[1], minVals1); + BOOST_REQUIRE_EQUAL(testDTree3.MaxVals()[2], maxVals2); + BOOST_REQUIRE_EQUAL(testDTree3.MinVals()[2], minVals2); // Test the structure of the tree copied using the copy constructor. - REQUIRE(testDTree2.Left()->Left() == NULL); - REQUIRE(testDTree2.Left()->Right() == NULL); - REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the structure of the tree copied using the copy operator. - REQUIRE(testDTree3.Left()->Left() == NULL); - REQUIRE(testDTree3.Left()->Right() == NULL); - REQUIRE(testDTree3.Right()->Left()->Left() == NULL); - REQUIRE(testDTree3.Right()->Left()->Right() == NULL); - REQUIRE(testDTree3.Right()->Right()->Left() == NULL); - REQUIRE(testDTree3.Right()->Right()->Right() == NULL); + BOOST_REQUIRE(testDTree3.Left()->Left() == NULL); + BOOST_REQUIRE(testDTree3.Left()->Right() == NULL); + BOOST_REQUIRE(testDTree3.Right()->Left()->Left() == NULL); + BOOST_REQUIRE(testDTree3.Right()->Left()->Right() == NULL); + BOOST_REQUIRE(testDTree3.Right()->Right()->Left() == NULL); + BOOST_REQUIRE(testDTree3.Right()->Right()->Right() == NULL); // Test the data of the tree copied using the copy constructor. - REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); - REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); - REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); - REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); - REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); - REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); - REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); - REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); - REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); - REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); - REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); - REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); - REQUIRE(testDTree2.SplitDim() == 2); - REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); - REQUIRE(testDTree2.Right()->SplitDim() == 1); - REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); + BOOST_REQUIRE(testDTree2.SplitDim() == 2); + BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); + BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); + BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); // Test the data of the tree copied using the copy operator. - REQUIRE(testDTree3.Left()->MaxVals()[0] == maxValsL0); - REQUIRE(testDTree3.Left()->MaxVals()[1] == maxValsL1); - REQUIRE(testDTree3.Left()->MaxVals()[2] == maxValsL2); - REQUIRE(testDTree3.Left()->MinVals()[0] == minValsL0); - REQUIRE(testDTree3.Left()->MinVals()[1] == minValsL1); - REQUIRE(testDTree3.Left()->MinVals()[2] == minValsL2); - REQUIRE(testDTree3.Right()->MaxVals()[0] == maxValsR0); - REQUIRE(testDTree3.Right()->MaxVals()[1] == maxValsR1); - REQUIRE(testDTree3.Right()->MaxVals()[2] == maxValsR2); - REQUIRE(testDTree3.Right()->MinVals()[0] == minValsR0); - REQUIRE(testDTree3.Right()->MinVals()[1] == minValsR1); - REQUIRE(testDTree3.Right()->MinVals()[2] == minValsR2); - REQUIRE(testDTree3.SplitDim() == 2); - REQUIRE(testDTree3.SplitValue() == Approx(5.5).epsilon(1e-7)); - REQUIRE(testDTree3.Right()->SplitDim() == 1); - REQUIRE(testDTree3.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); + BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[0], maxValsL0); + BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[1], maxValsL1); + BOOST_REQUIRE_EQUAL(testDTree3.Left()->MaxVals()[2], maxValsL2); + BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[0], minValsL0); + BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[1], minValsL1); + BOOST_REQUIRE_EQUAL(testDTree3.Left()->MinVals()[2], minValsL2); + BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[0], maxValsR0); + BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[1], maxValsR1); + BOOST_REQUIRE_EQUAL(testDTree3.Right()->MaxVals()[2], maxValsR2); + BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[0], minValsR0); + BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[1], minValsR1); + BOOST_REQUIRE_EQUAL(testDTree3.Right()->MinVals()[2], minValsR2); + BOOST_REQUIRE(testDTree3.SplitDim() == 2); + BOOST_REQUIRE_CLOSE(testDTree3.SplitValue(), 5.5, 1e-5); + BOOST_REQUIRE(testDTree3.Right()->SplitDim() == 1); + BOOST_REQUIRE_CLOSE(testDTree3.Right()->SplitValue(), 0.5, 1e-5); } // Test the move constructor. -TEST_CASE("MoveConstructorTest", "[DETTest]") +BOOST_AUTO_TEST_CASE(MoveConstructorTest) { arma::mat testData(3, 5); @@ -658,50 +653,50 @@ TEST_CASE("MoveConstructorTest", "[DETTest]") DTree testDTree2(std::move(*testDTree)); // Check default values of the original tree. - REQUIRE(testDTree->LogNegError() == -DBL_MAX); - REQUIRE(testDTree->Left() == (DTree*) NULL); - REQUIRE(testDTree->Right() == (DTree*) NULL); + BOOST_REQUIRE_EQUAL(testDTree->LogNegError(), -DBL_MAX); + BOOST_REQUIRE(testDTree->Left() == (DTree*) NULL); + BOOST_REQUIRE(testDTree->Right() == (DTree*) NULL); // Delete the original tree. delete testDTree; // Test the data of the moved tree. - REQUIRE(testDTree2.MaxVals()[0] == maxVals0); - REQUIRE(testDTree2.MinVals()[0] == minVals0); - REQUIRE(testDTree2.MaxVals()[1] == maxVals1); - REQUIRE(testDTree2.MinVals()[1] == minVals1); - REQUIRE(testDTree2.MaxVals()[2] == maxVals2); - REQUIRE(testDTree2.MinVals()[2] == minVals2); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); // Test the structure of the moved tree. - REQUIRE(testDTree2.Left()->Left() == NULL); - REQUIRE(testDTree2.Left()->Right() == NULL); - REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the data of the moved tree. - REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); - REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); - REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); - REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); - REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); - REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); - REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); - REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); - REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); - REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); - REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); - REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); - REQUIRE(testDTree2.SplitDim() == 2); - REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); - REQUIRE(testDTree2.Right()->SplitDim() == 1); - REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); + BOOST_REQUIRE(testDTree2.SplitDim() == 2); + BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); + BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); + BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); } // Test the move operator. -TEST_CASE("MoveOperatorTest", "[DETTest]") +BOOST_AUTO_TEST_CASE(MoveOperatorTest) { arma::mat testData(3, 5); @@ -741,44 +736,46 @@ TEST_CASE("MoveOperatorTest", "[DETTest]") DTree testDTree2 = std::move(*testDTree); // Check default values of the original tree. - REQUIRE(testDTree->LogNegError() == -DBL_MAX); - REQUIRE(testDTree->Left() == (DTree*) NULL); - REQUIRE(testDTree->Right() == (DTree*) NULL); + BOOST_REQUIRE_EQUAL(testDTree->LogNegError(), -DBL_MAX); + BOOST_REQUIRE(testDTree->Left() == (DTree*) NULL); + BOOST_REQUIRE(testDTree->Right() == (DTree*) NULL); // Delete the original tree. delete testDTree; // Test the data of the moved tree. - REQUIRE(testDTree2.MaxVals()[0] == maxVals0); - REQUIRE(testDTree2.MinVals()[0] == minVals0); - REQUIRE(testDTree2.MaxVals()[1] == maxVals1); - REQUIRE(testDTree2.MinVals()[1] == minVals1); - REQUIRE(testDTree2.MaxVals()[2] == maxVals2); - REQUIRE(testDTree2.MinVals()[2] == minVals2); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[0], maxVals0); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[0], minVals0); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[1], maxVals1); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[1], minVals1); + BOOST_REQUIRE_EQUAL(testDTree2.MaxVals()[2], maxVals2); + BOOST_REQUIRE_EQUAL(testDTree2.MinVals()[2], minVals2); // Test the structure of the moved tree. - REQUIRE(testDTree2.Left()->Left() == NULL); - REQUIRE(testDTree2.Left()->Right() == NULL); - REQUIRE(testDTree2.Right()->Left()->Left() == NULL); - REQUIRE(testDTree2.Right()->Left()->Right() == NULL); - REQUIRE(testDTree2.Right()->Right()->Left() == NULL); - REQUIRE(testDTree2.Right()->Right()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Left()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Left()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Left()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Left()->Right() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Right()->Left() == NULL); + BOOST_REQUIRE(testDTree2.Right()->Right()->Right() == NULL); // Test the data of moved tree. - REQUIRE(testDTree2.Left()->MaxVals()[0] == maxValsL0); - REQUIRE(testDTree2.Left()->MaxVals()[1] == maxValsL1); - REQUIRE(testDTree2.Left()->MaxVals()[2] == maxValsL2); - REQUIRE(testDTree2.Left()->MinVals()[0] == minValsL0); - REQUIRE(testDTree2.Left()->MinVals()[1] == minValsL1); - REQUIRE(testDTree2.Left()->MinVals()[2] == minValsL2); - REQUIRE(testDTree2.Right()->MaxVals()[0] == maxValsR0); - REQUIRE(testDTree2.Right()->MaxVals()[1] == maxValsR1); - REQUIRE(testDTree2.Right()->MaxVals()[2] == maxValsR2); - REQUIRE(testDTree2.Right()->MinVals()[0] == minValsR0); - REQUIRE(testDTree2.Right()->MinVals()[1] == minValsR1); - REQUIRE(testDTree2.Right()->MinVals()[2] == minValsR2); - REQUIRE(testDTree2.SplitDim() == 2); - REQUIRE(testDTree2.SplitValue() == Approx(5.5).epsilon(1e-7)); - REQUIRE(testDTree2.Right()->SplitDim() == 1); - REQUIRE(testDTree2.Right()->SplitValue() == Approx(0.5).epsilon(1e-7)); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[0], maxValsL0); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[1], maxValsL1); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MaxVals()[2], maxValsL2); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[0], minValsL0); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[1], minValsL1); + BOOST_REQUIRE_EQUAL(testDTree2.Left()->MinVals()[2], minValsL2); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[0], maxValsR0); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[1], maxValsR1); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MaxVals()[2], maxValsR2); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[0], minValsR0); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[1], minValsR1); + BOOST_REQUIRE_EQUAL(testDTree2.Right()->MinVals()[2], minValsR2); + BOOST_REQUIRE(testDTree2.SplitDim() == 2); + BOOST_REQUIRE_CLOSE(testDTree2.SplitValue(), 5.5, 1e-5); + BOOST_REQUIRE(testDTree2.Right()->SplitDim() == 1); + BOOST_REQUIRE_CLOSE(testDTree2.Right()->SplitValue(), 0.5, 1e-5); } + +BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/distribution_test.cpp b/src/mlpack/tests/distribution_test.cpp index ab7d606a9f..35103130b9 100644 --- a/src/mlpack/tests/distribution_test.cpp +++ b/src/mlpack/tests/distribution_test.cpp @@ -19,15 +19,17 @@ #include #include -#include "catch.hpp" -#include "serialization_catch.hpp" -#include "test_catch_tools.hpp" +#include +#include "test_tools.hpp" +#include "serialization.hpp" using namespace mlpack; using namespace mlpack::distribution; using namespace mlpack::metric; using namespace mlpack::math; +BOOST_AUTO_TEST_SUITE(DistributionTest); + /*********************************/ /** Discrete Distribution Tests **/ /*********************************/ @@ -35,38 +37,38 @@ using namespace mlpack::math; /** * Make sure we initialize correctly. */ -TEST_CASE("DiscreteDistributionConstructorTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteDistributionConstructorTest) { DiscreteDistribution d(5); - REQUIRE(d.Probabilities().n_elem == 5); - REQUIRE(d.Probability("0") == Approx(0.2).epsilon(1e-7)); - REQUIRE(d.Probability("1") == Approx(0.2).epsilon(1e-7)); - REQUIRE(d.Probability("2") == Approx(0.2).epsilon(1e-7)); - REQUIRE(d.Probability("3") == Approx(0.2).epsilon(1e-7)); - REQUIRE(d.Probability("4") == Approx(0.2).epsilon(1e-7)); + BOOST_REQUIRE_EQUAL(d.Probabilities().n_elem, 5); + BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.2, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.2, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.2, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.2, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("4"), 0.2, 1e-5); } /** * Make sure we get the probabilities of observations right. */ -TEST_CASE("DiscreteDistributionProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteDistributionProbabilityTest) { DiscreteDistribution d(5); d.Probabilities() = "0.2 0.4 0.1 0.1 0.2"; - REQUIRE(d.Probability("0") == Approx(0.2).epsilon(1e-7)); - REQUIRE(d.Probability("1") == Approx(0.4).epsilon(1e-7)); - REQUIRE(d.Probability("2") == Approx(0.1).epsilon(1e-7)); - REQUIRE(d.Probability("3") == Approx(0.1).epsilon(1e-7)); - REQUIRE(d.Probability("4") == Approx(0.2).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.2, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.4, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.1, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.1, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("4"), 0.2, 1e-5); } /** * Make sure we get random observations correct. */ -TEST_CASE("DiscreteDistributionRandomTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteDistributionRandomTest) { DiscreteDistribution d(arma::Col("3")); @@ -83,15 +85,15 @@ TEST_CASE("DiscreteDistributionRandomTest", "[DistributionTest]") actualProb /= accu(actualProb); // 8% tolerance, because this can be a noisy process. - REQUIRE(actualProb(0) == Approx(0.3).epsilon(0.08)); - REQUIRE(actualProb(1) == Approx(0.6).epsilon(0.08)); - REQUIRE(actualProb(2) == Approx(0.1).epsilon(0.08)); + BOOST_REQUIRE_CLOSE(actualProb(0), 0.3, 8.0); + BOOST_REQUIRE_CLOSE(actualProb(1), 0.6, 8.0); + BOOST_REQUIRE_CLOSE(actualProb(2), 0.1, 8.0); } /** * Make sure we can estimate from observations correctly. */ -TEST_CASE("DiscreteDistributionTrainTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainTest) { DiscreteDistribution d(4); @@ -99,16 +101,16 @@ TEST_CASE("DiscreteDistributionTrainTest", "[DistributionTest]") d.Train(obs); - REQUIRE(d.Probability("0") == Approx(0.25).epsilon(1e-7)); - REQUIRE(d.Probability("1") == Approx(0.25).epsilon(1e-7)); - REQUIRE(d.Probability("2") == Approx(0.375).epsilon(1e-7)); - REQUIRE(d.Probability("3") == Approx(0.125).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.25, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.25, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.375, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("3"), 0.125, 1e-5); } /** * Estimate from observations with probabilities. */ -TEST_CASE("DiscreteDistributionTrainProbTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteDistributionTrainProbTest) { DiscreteDistribution d(3); @@ -118,15 +120,15 @@ TEST_CASE("DiscreteDistributionTrainProbTest", "[DistributionTest]") d.Train(obs, prob); - REQUIRE(d.Probability("0") == Approx(0.25).epsilon(1e-7)); - REQUIRE(d.Probability("1") == Approx(0.25).epsilon(1e-7)); - REQUIRE(d.Probability("2") == Approx(0.5).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0"), 0.25, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1"), 0.25, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("2"), 0.5, 1e-5); } /** * Achieve multidimensional probability distribution. */ -TEST_CASE("MultiDiscreteDistributionTrainProbTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProbTest) { DiscreteDistribution d("10 10 10"); @@ -135,29 +137,29 @@ TEST_CASE("MultiDiscreteDistributionTrainProbTest", "[DistributionTest]") "0 0 0 1 1 2 2 2 2 2;"); d.Train(obs); - REQUIRE(d.Probability("0 0 0") == Approx(0.009).epsilon(1e-7)); - REQUIRE(d.Probability("0 1 2") == Approx(0.015).epsilon(1e-7)); - REQUIRE(d.Probability("2 1 0") == Approx(0.054).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.009, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("0 1 2"), 0.015, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.054, 1e-5); } /** * Make sure we initialize multidimensional probability distribution * correctly. */ -TEST_CASE("MultiDiscreteDistributionConstructorTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionConstructorTest) { DiscreteDistribution d("4 4 4 4"); - REQUIRE(d.Probabilities(0).size() == 4); - REQUIRE(d.Dimensionality() == 4); - REQUIRE(d.Probability("0 0 0 0") == Approx(0.00390625).epsilon(1e-7)); - REQUIRE(d.Probability("0 1 2 3") == Approx(0.00390625).epsilon(1e-7)); + BOOST_REQUIRE_EQUAL(d.Probabilities(0).size(), 4); + BOOST_REQUIRE_EQUAL(d.Dimensionality(), 4); + BOOST_REQUIRE_CLOSE(d.Probability("0 0 0 0"), 0.00390625, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("0 1 2 3"), 0.00390625, 1e-5); } /** * Achieve multidimensional probability distribution. */ -TEST_CASE("MultiDiscreteDistributionTrainTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainTest) { std::vector pro; pro.push_back(arma::vec("0.1, 0.3, 0.6")); @@ -166,16 +168,16 @@ TEST_CASE("MultiDiscreteDistributionTrainTest", "[DistributionTest]") DiscreteDistribution d(pro); - REQUIRE(d.Probability("0 0 0") == Approx(0.0083333).epsilon(1e-5)); - REQUIRE(d.Probability("0 1 2") == Approx(0.0166666).epsilon(1e-5)); - REQUIRE(d.Probability("2 1 0") == Approx(0.05).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.0083333, 1e-3); + BOOST_REQUIRE_CLOSE(d.Probability("0 1 2"), 0.0166666, 1e-3); + BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.05, 1e-5); } /** * Estimate multidimensional probability distribution from observations with * probabilities. */ -TEST_CASE("MultiDiscreteDistributionTrainProTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(MultiDiscreteDistributionTrainProTest) { DiscreteDistribution d("5 5 5"); @@ -187,16 +189,16 @@ TEST_CASE("MultiDiscreteDistributionTrainProTest", "[DistributionTest]") d.Train(obs, prob); - REQUIRE(d.Probability("0 0 0") == Approx(0.00390625).epsilon(1e-7)); - REQUIRE(d.Probability("1 0 1") == Approx(0.0078125).epsilon(1e-7)); - REQUIRE(d.Probability("2 1 0") == Approx(0.015625).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0 0 0"), 0.00390625, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1 0 1"), 0.0078125, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("2 1 0"), 0.015625, 1e-5); } /** * Test the LogProbability() function, for multiple points in the multivariate * Discrete case. */ -TEST_CASE("DiscreteLogProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteLogProbabilityTest) { // Same case as before. DiscreteDistribution d("5 5"); @@ -208,17 +210,17 @@ TEST_CASE("DiscreteLogProbabilityTest", "[DistributionTest]") d.LogProbability(obs, logProb); - REQUIRE(logProb.n_elem == 2); + BOOST_REQUIRE_EQUAL(logProb.n_elem, 2); - REQUIRE(logProb(0) == Approx(-3.2188758248682).epsilon(1e-5)); - REQUIRE(logProb(1) == Approx(-3.2188758248682).epsilon(1e-5)); + BOOST_REQUIRE_CLOSE(logProb(0), -3.2188758248682, 1e-3); + BOOST_REQUIRE_CLOSE(logProb(1), -3.2188758248682, 1e-3); } /** * Test the Probability() function, for multiple points in the multivariate * Discrete case. */ -TEST_CASE("DiscreteProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteProbabilityTest) { // Same case as before. DiscreteDistribution d("5 5"); @@ -230,10 +232,10 @@ TEST_CASE("DiscreteProbabilityTest", "[DistributionTest]") d.Probability(obs, prob); - REQUIRE(prob.n_elem == 2); + BOOST_REQUIRE_EQUAL(prob.n_elem, 2); - REQUIRE(prob(0) == Approx(0.0400000000000).epsilon(1e-5)); - REQUIRE(prob(1) == Approx(0.0400000000000).epsilon(1e-5)); + BOOST_REQUIRE_CLOSE(prob(0), 0.0400000000000, 1e-3); + BOOST_REQUIRE_CLOSE(prob(1), 0.0400000000000, 1e-3); } /*********************************/ @@ -243,33 +245,32 @@ TEST_CASE("DiscreteProbabilityTest", "[DistributionTest]") /** * Make sure Gaussian distributions are initialized correctly. */ -TEST_CASE("GaussianDistributionEmptyConstructor", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionEmptyConstructor) { GaussianDistribution d; - REQUIRE(d.Mean().n_elem == 0); - REQUIRE(d.Covariance().n_elem == 0); + BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 0); + BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 0); } /** * Make sure Gaussian distributions are initialized to the correct * dimensionality. */ -TEST_CASE("GaussianDistributionDimensionalityConstructor", - "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionDimensionalityConstructor) { GaussianDistribution d(4); - REQUIRE(d.Mean().n_elem == 4); - REQUIRE(d.Covariance().n_rows == 4); - REQUIRE(d.Covariance().n_cols == 4); + BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 4); + BOOST_REQUIRE_EQUAL(d.Covariance().n_rows, 4); + BOOST_REQUIRE_EQUAL(d.Covariance().n_cols, 4); } /** * Make sure Gaussian distributions are initialized correctly when we give a * mean and covariance. */ -TEST_CASE("GaussianDistributionDistributionConstructor", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionDistributionConstructor) { arma::vec mean(3); arma::mat covariance(3, 3); @@ -282,17 +283,17 @@ TEST_CASE("GaussianDistributionDistributionConstructor", "[DistributionTest]") GaussianDistribution d(mean, covariance); for (size_t i = 0; i < 3; ++i) - REQUIRE(d.Mean()[i] == Approx(mean[i]).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Mean()[i], mean[i], 1e-5); for (size_t i = 0; i < 3; ++i) for (size_t j = 0; j < 3; ++j) - REQUIRE(d.Covariance()(i, j) == Approx(covariance(i, j)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Covariance()(i, j), covariance(i, j), 1e-5); } /** * Make sure the probability of observations is correct. */ -TEST_CASE("GaussianDistributionProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionProbabilityTest) { arma::vec mean("5 6 3 3 2"); arma::mat cov("6 1 1 1 2;" @@ -303,63 +304,52 @@ TEST_CASE("GaussianDistributionProbabilityTest", "[DistributionTest]") GaussianDistribution d(mean, cov); - REQUIRE(d.LogProbability("0 1 2 3 4") == - Approx(-13.432076798791542).epsilon(1e-7)); - REQUIRE(d.LogProbability("3 2 3 7 8") == - Approx(-15.814880322345738).epsilon(1e-7)); - REQUIRE(d.LogProbability("2 2 0 8 1") == - Approx(-13.754462857772776).epsilon(1e-7)); - REQUIRE(d.LogProbability("2 1 5 0 1") == - Approx(-13.283283233107898).epsilon(1e-7)); - REQUIRE(d.LogProbability("3 0 5 1 0") == - Approx(-13.800326511545279).epsilon(1e-7)); - REQUIRE(d.LogProbability("4 0 6 1 0") == - Approx(-14.900192463287908).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.LogProbability("0 1 2 3 4"), -13.432076798791542, 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("3 2 3 7 8"), -15.814880322345738, 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("2 2 0 8 1"), -13.754462857772776, 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("2 1 5 0 1"), -13.283283233107898, 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("3 0 5 1 0"), -13.800326511545279, 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("4 0 6 1 0"), -14.900192463287908, 1e-5); } /** * Test GaussianDistribution::Probability() in the univariate case. */ -TEST_CASE("GaussianUnivariateProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianUnivariateProbabilityTest) { GaussianDistribution g(arma::vec("0.0"), arma::mat("1.0")); // Simple case. - REQUIRE(g.Probability(arma::vec("0.0")) == - Approx(0.398942280401433).epsilon(1e-7)); - REQUIRE(g.Probability(arma::vec("1.0")) == - Approx(0.241970724519143).epsilon(1e-7)); - REQUIRE(g.Probability(arma::vec("-1.0")) == - Approx(0.241970724519143).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("0.0")), 0.398942280401433, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.241970724519143, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.241970724519143, + 1e-5); // A few more cases... arma::mat covariance; covariance = 2.0; g.Covariance(std::move(covariance)); - REQUIRE(g.Probability(arma::vec("0.0")) == - Approx(0.282094791773878).epsilon(1e-7)); - REQUIRE(g.Probability(arma::vec("1.0")) == - Approx(0.219695644733861).epsilon(1e-7)); - REQUIRE(g.Probability(arma::vec("-1.0")) == - Approx(0.219695644733861).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("0.0")), 0.282094791773878, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.219695644733861, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.219695644733861, + 1e-5); g.Mean().fill(1.0); covariance = 1.0; g.Covariance(std::move(covariance)); - REQUIRE(g.Probability(arma::vec("1.0")) == - Approx(0.398942280401433).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("1.0")), 0.398942280401433, 1e-5); covariance = 2.0; g.Covariance(std::move(covariance)); - REQUIRE(g.Probability(arma::vec("-1.0")) == - Approx(0.103776874355149).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(arma::vec("-1.0")), 0.103776874355149, + 1e-5); } /** * Test GaussianDistribution::Probability() in the multivariate case. */ -TEST_CASE("GaussianMultivariateProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianMultivariateProbabilityTest) { // Simple case. arma::vec mean = "0 0"; @@ -368,37 +358,37 @@ TEST_CASE("GaussianMultivariateProbabilityTest", "[DistributionTest]") GaussianDistribution g(mean, cov); - REQUIRE(g.Probability(x) == Approx(0.159154943091895).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(x), 0.159154943091895, 1e-5); arma::mat covariance; covariance = "2 0; 0 2"; g.Covariance(std::move(covariance)); - REQUIRE(g.Probability(x) == Approx(0.0795774715459477).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0795774715459477, 1e-5); x = "1 1"; - REQUIRE(g.Probability(x) == Approx(0.0482661763150270).epsilon(1e-7)); - REQUIRE(g.Probability(-x) == Approx(0.0482661763150270).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0482661763150270, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.0482661763150270, 1e-5); g.Mean() = "1 1"; - REQUIRE(g.Probability(x) == Approx(0.0795774715459477).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(x), 0.0795774715459477, 1e-5); g.Mean() *= -1; - REQUIRE(g.Probability(-x) == Approx(0.0795774715459477).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.0795774715459477, 1e-5); g.Mean() = "1 1"; covariance = "2 1.5; 1.5 4"; g.Covariance(std::move(covariance)); - REQUIRE(g.Probability(x) == Approx(0.066372199406187285).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(x), 0.066372199406187285, 1e-5); g.Mean() *= -1; - REQUIRE(g.Probability(-x) == Approx(0.066372199406187285).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.066372199406187285, 1e-5); g.Mean() = "1 1"; x = "-1 4"; - REQUIRE(g.Probability(x) == Approx(0.00072147262356379415).epsilon(1e-7)); - REQUIRE(g.Probability(-x) == Approx(0.00085851785428674523).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(g.Probability(x), 0.00072147262356379415, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(-x), 0.00085851785428674523, 1e-5); // Higher-dimensional case. x = "0 1 2 3 4"; @@ -411,19 +401,19 @@ TEST_CASE("GaussianMultivariateProbabilityTest", "[DistributionTest]") "2 0 1 0 6"; g.Covariance(std::move(covariance)); - REQUIRE(g.Probability(x) == Approx(1.4673143531128877e-06).epsilon(1e-7)); - REQUIRE(g.Probability(-x) == Approx(7.7404143494891786e-09).epsilon(1e-10)); + BOOST_REQUIRE_CLOSE(g.Probability(x), 1.4673143531128877e-06, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(-x), 7.7404143494891786e-09, 1e-8); g.Mean() *= -1; - REQUIRE(g.Probability(-x) == Approx(1.4673143531128877e-06).epsilon(1e-7)); - REQUIRE(g.Probability(x) == Approx(7.7404143494891786e-09).epsilon(1e-10)); + BOOST_REQUIRE_CLOSE(g.Probability(-x), 1.4673143531128877e-06, 1e-5); + BOOST_REQUIRE_CLOSE(g.Probability(x), 7.7404143494891786e-09, 1e-8); } /** * Test the phi() function, for multiple points in the multivariate Gaussian * case. */ -TEST_CASE("GaussianMultipointMultivariateProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianMultipointMultivariateProbabilityTest) { // Same case as before. arma::vec mean = "5 6 3 3 2"; @@ -443,20 +433,20 @@ TEST_CASE("GaussianMultipointMultivariateProbabilityTest", "[DistributionTest]") GaussianDistribution g(mean, cov); g.LogProbability(points, phis); - REQUIRE(phis.n_elem == 6); + BOOST_REQUIRE_EQUAL(phis.n_elem, 6); - REQUIRE(phis(0) == Approx(-13.432076798791542).epsilon(1e-7)); - REQUIRE(phis(1) == Approx(-15.814880322345738).epsilon(1e-7)); - REQUIRE(phis(2) == Approx(-13.754462857772776).epsilon(1e-7)); - REQUIRE(phis(3) == Approx(-13.283283233107898).epsilon(1e-7)); - REQUIRE(phis(4) == Approx(-13.800326511545279).epsilon(1e-7)); - REQUIRE(phis(5) == Approx(-14.900192463287908).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(phis(0), -13.432076798791542, 1e-5); + BOOST_REQUIRE_CLOSE(phis(1), -15.814880322345738, 1e-5); + BOOST_REQUIRE_CLOSE(phis(2), -13.754462857772776, 1e-5); + BOOST_REQUIRE_CLOSE(phis(3), -13.283283233107898, 1e-5); + BOOST_REQUIRE_CLOSE(phis(4), -13.800326511545279, 1e-5); + BOOST_REQUIRE_CLOSE(phis(5), -14.900192463287908, 1e-5); } /** * Make sure random observations follow the probability distribution correctly. */ -TEST_CASE("GaussianDistributionRandomTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionRandomTest) { arma::vec mean("1.0 2.25"); arma::mat cov("0.85 0.60;" @@ -474,19 +464,19 @@ TEST_CASE("GaussianDistributionRandomTest", "[DistributionTest]") arma::mat obsCov = mlpack::math::ColumnCovariance(obs); // 10% tolerance because this can be noisy. - REQUIRE(obsMean[0] == Approx(mean[0]).epsilon(0.1)); - REQUIRE(obsMean[1] == Approx(mean[1]).epsilon(0.1)); + BOOST_REQUIRE_CLOSE(obsMean[0], mean[0], 10.0); + BOOST_REQUIRE_CLOSE(obsMean[1], mean[1], 10.0); - REQUIRE(obsCov(0, 0) == Approx(cov(0, 0)).epsilon(0.1)); - REQUIRE(obsCov(0, 1) == Approx(cov(0, 1)).epsilon(0.1)); - REQUIRE(obsCov(1, 0) == Approx(cov(1, 0)).epsilon(0.1)); - REQUIRE(obsCov(1, 1) == Approx(cov(1, 1)).epsilon(0.1)); + BOOST_REQUIRE_CLOSE(obsCov(0, 0), cov(0, 0), 10.0); + BOOST_REQUIRE_CLOSE(obsCov(0, 1), cov(0, 1), 10.0); + BOOST_REQUIRE_CLOSE(obsCov(1, 0), cov(1, 0), 10.0); + BOOST_REQUIRE_CLOSE(obsCov(1, 1), cov(1, 1), 10.0); } /** * Make sure that we can properly estimate from given observations. */ -TEST_CASE("GaussianDistributionTrainTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionTrainTest) { arma::vec mean("1.0 3.0 0.0 2.5"); arma::mat cov("3.0 0.0 1.0 4.0;" @@ -512,22 +502,18 @@ TEST_CASE("GaussianDistributionTrainTest", "[DistributionTest]") // Check that everything is estimated right. for (size_t i = 0; i < 4; ++i) - REQUIRE(d.Mean()[i] - actualMean[i] == Approx(0.0).margin(1e-5)); + BOOST_REQUIRE_SMALL(d.Mean()[i] - actualMean[i], 1e-5); for (size_t i = 0; i < 4; ++i) for (size_t j = 0; j < 4; ++j) - { - REQUIRE(d.Covariance()(i, j) - actualCov(i, j) == - Approx(0.0).margin(1e-5)); - } + BOOST_REQUIRE_SMALL(d.Covariance()(i, j) - actualCov(i, j), 1e-5); } /** * This test verifies the fitting of GaussianDistribution works properly when * probabilities for each sample is given. */ -TEST_CASE("GaussianDistributionTrainWithProbabilitiesTest", - "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithProbabilitiesTest) { arma::vec mean = ("5.0"); arma::vec cov = ("2.0"); @@ -552,19 +538,18 @@ TEST_CASE("GaussianDistributionTrainWithProbabilitiesTest", GaussianDistribution guDist2; guDist2.Train(rdata); - REQUIRE(guDist.Mean()[0] == Approx(guDist2.Mean()[0]).epsilon(0.06)); - REQUIRE(guDist.Covariance()[0] == - Approx(guDist2.Covariance()[0]).epsilon(0.06)); + BOOST_REQUIRE_CLOSE(guDist.Mean()[0], guDist2.Mean()[0], 6); + BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], guDist2.Covariance()[0], 6); - REQUIRE(guDist.Mean()[0] == Approx(mean[0]).epsilon(0.06)); - REQUIRE(guDist.Covariance()[0] == Approx(cov[0]).epsilon(0.06)); + BOOST_REQUIRE_CLOSE(guDist.Mean()[0], mean[0], 6); + BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], cov[0], 6); } /** * This test ensures that the same result is obtained when trained with * probabilities all set to 1 and with no probabilities at all. */ -TEST_CASE("GaussianDistributionWithProbabilties1Test", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionWithProbabilties1Test) { arma::vec mean = ("5.0"); arma::vec cov = ("4.0"); @@ -588,9 +573,8 @@ TEST_CASE("GaussianDistributionWithProbabilties1Test", "[DistributionTest]") GaussianDistribution guDist2; guDist2.Train(rdata, probabilities); - REQUIRE(guDist.Mean()[0] == Approx(guDist2.Mean()[0]).epsilon(1e-17)); - REQUIRE(guDist.Covariance()[0] == - Approx(guDist2.Covariance()[0]).epsilon(1e-4)); + BOOST_REQUIRE_CLOSE(guDist.Mean()[0], guDist2.Mean()[0], 1e-15); + BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], guDist2.Covariance()[0], 1e-2); } /** @@ -601,8 +585,7 @@ TEST_CASE("GaussianDistributionWithProbabilties1Test", "[DistributionTest]") * We expect that the distribution we recover after training to be the same as * the second normal distribution (the one with high probabilities). */ -TEST_CASE("GaussianDistributionTrainWithTwoDistProbabilitiesTest", - "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) { arma::vec mean1 = ("5.0"); arma::vec cov1 = ("4.0"); @@ -643,8 +626,8 @@ TEST_CASE("GaussianDistributionTrainWithTwoDistProbabilitiesTest", GaussianDistribution guDist; guDist.Train(rdata, probabilities); - REQUIRE(guDist.Mean()[0] == Approx(mean1[0]).epsilon(0.05)); - REQUIRE(guDist.Covariance()[0] == Approx(cov1[0]).epsilon(0.05)); + BOOST_REQUIRE_CLOSE(guDist.Mean()[0], mean1[0], 5); + BOOST_REQUIRE_CLOSE(guDist.Covariance()[0], cov1[0], 5); } /******************************/ @@ -654,7 +637,7 @@ TEST_CASE("GaussianDistributionTrainWithTwoDistProbabilitiesTest", * Make sure that using an object to fit one reference set and then asking * to fit another works properly. */ -TEST_CASE("GammaDistributionTrainTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionTrainTest) { // Create a gamma distribution random generator. double alphaReal = 5.3; @@ -676,8 +659,8 @@ TEST_CASE("GammaDistributionTrainTest", "[DistributionTest]") gDist.Train(rdata); // Training must estimate d pairs of alpha and beta parameters. - REQUIRE(gDist.Dimensionality() == d); - REQUIRE(gDist.Dimensionality() == d); + BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d); + BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d); // Create a N' x d' gamma distribution, fit results without new object. size_t N2 = 350; @@ -693,15 +676,15 @@ TEST_CASE("GammaDistributionTrainTest", "[DistributionTest]") gDist.Train(rdata2); // Training must estimate d' pairs of alpha and beta parameters. - REQUIRE(gDist.Dimensionality() == d2); - REQUIRE(gDist.Dimensionality() == d2); + BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d2); + BOOST_REQUIRE_EQUAL(gDist.Dimensionality(), d2); } /** * This test verifies that the fitting procedure for GammaDistribution works * properly when probabilities for each sample is given. */ -TEST_CASE("GammaDistributionTrainWithProbabilitiesTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionTrainWithProbabilitiesTest) { double alphaReal = 5.4; double betaReal = 6.7; @@ -728,24 +711,24 @@ TEST_CASE("GammaDistributionTrainWithProbabilitiesTest", "[DistributionTest]") GammaDistribution gDist2; gDist2.Train(rdata); - REQUIRE(gDist2.Alpha(0) == Approx(gDist.Alpha(0)).epsilon(0.015)); - REQUIRE(gDist2.Beta(0) == Approx(gDist.Beta(0)).epsilon(0.015)); + BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), gDist.Alpha(0), 1.5); + BOOST_REQUIRE_CLOSE(gDist2.Beta(0), gDist.Beta(0), 1.5); - REQUIRE(gDist2.Alpha(1) == Approx(gDist.Alpha(1)).epsilon(0.015)); - REQUIRE(gDist2.Beta(1) == Approx(gDist.Beta(1)).epsilon(0.015)); + BOOST_REQUIRE_CLOSE(gDist2.Alpha(1), gDist.Alpha(1), 1.5); + BOOST_REQUIRE_CLOSE(gDist2.Beta(1), gDist.Beta(1), 1.5); - REQUIRE(alphaReal == Approx(gDist.Alpha(0)).epsilon(0.03)); - REQUIRE(betaReal == Approx(gDist.Beta(0)).epsilon(0.03)); + BOOST_REQUIRE_CLOSE(alphaReal, gDist.Alpha(0), 3.0); + BOOST_REQUIRE_CLOSE(betaReal, gDist.Beta(0), 3.0); - REQUIRE(alphaReal == Approx(gDist.Alpha(1)).epsilon(0.03)); - REQUIRE(betaReal == Approx(gDist.Beta(1)).epsilon(0.03)); + BOOST_REQUIRE_CLOSE(alphaReal, gDist.Alpha(1), 3.0); + BOOST_REQUIRE_CLOSE(betaReal, gDist.Beta(1), 3.0); } /** * This test ensures that the same result is obtained when trained with * probabilities all set to 1 and with no probabilities at all. */ -TEST_CASE("GammaDistributionTrainAllProbabilities1Test", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionTrainAllProbabilities1Test) { double alphaReal = 5.4; double betaReal = 6.7; @@ -770,11 +753,11 @@ TEST_CASE("GammaDistributionTrainAllProbabilities1Test", "[DistributionTest]") arma::vec allProbabilities1(N, arma::fill::ones); gDist2.Train(rdata, allProbabilities1); - REQUIRE(gDist2.Alpha(0) == Approx(gDist.Alpha(0)).epsilon(1e-7)); - REQUIRE(gDist2.Beta(0) == Approx(gDist.Beta(0)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), gDist.Alpha(0), 1e-5); + BOOST_REQUIRE_CLOSE(gDist2.Beta(0), gDist.Beta(0), 1e-5); - REQUIRE(gDist2.Alpha(1) == Approx(gDist.Alpha(1)).epsilon(1e-7)); - REQUIRE(gDist2.Beta(1) == Approx(gDist.Beta(1)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(gDist2.Alpha(1), gDist.Alpha(1), 1e-5); + BOOST_REQUIRE_CLOSE(gDist2.Beta(1), gDist.Beta(1), 1e-5); } /** @@ -784,8 +767,7 @@ TEST_CASE("GammaDistributionTrainAllProbabilities1Test", "[DistributionTest]") * gamma distribution recovered has the same parameters as the second gamma * distribution with high probabilities. */ -TEST_CASE("GammaDistributionTrainTwoDistProbabilities1Test", - "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) { double alphaReal = 5.4; double betaReal = 6.7; @@ -825,11 +807,11 @@ TEST_CASE("GammaDistributionTrainTwoDistProbabilities1Test", GammaDistribution gDist; gDist.Train(rdata, probabilities); - REQUIRE(alphaReal2 == Approx(gDist.Alpha(0)).epsilon(0.05)); - REQUIRE(betaReal2 == Approx(gDist.Beta(0)).epsilon(0.05)); + BOOST_REQUIRE_CLOSE(alphaReal2, gDist.Alpha(0), 5); + BOOST_REQUIRE_CLOSE(betaReal2, gDist.Beta(0), 5); - REQUIRE(alphaReal2 == Approx(gDist.Alpha(1)).epsilon(0.05)); - REQUIRE(betaReal2 == Approx(gDist.Beta(1)).epsilon(0.05)); + BOOST_REQUIRE_CLOSE(alphaReal2, gDist.Alpha(1), 5); + BOOST_REQUIRE_CLOSE(betaReal2, gDist.Beta(1), 5); } /** @@ -838,7 +820,7 @@ TEST_CASE("GammaDistributionTrainTwoDistProbabilities1Test", * with different alpha/beta parameters so we make sure we don't have some weird * bug that always converges to the same number. */ -TEST_CASE("GammaDistributionFittingTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionFittingTest) { // Offset from the actual alpha/beta. 10% is quite a relaxed tolerance since // the random points we generate are few (for test speed) and might be fitted @@ -866,8 +848,8 @@ TEST_CASE("GammaDistributionFittingTest", "[DistributionTest]") gDist.Train(rdata); // Estimated parameter must be close to real. - REQUIRE(gDist.Alpha(0) == Approx(alphaReal).epsilon(errorTolerance / 100)); - REQUIRE(gDist.Beta(0) == Approx(betaReal).epsilon(errorTolerance / 100)); + BOOST_REQUIRE_CLOSE(gDist.Alpha(0), alphaReal, errorTolerance); + BOOST_REQUIRE_CLOSE(gDist.Beta(0), betaReal, errorTolerance); /** Iteration 2 (different parameter set) **/ @@ -887,15 +869,15 @@ TEST_CASE("GammaDistributionFittingTest", "[DistributionTest]") gDist2.Train(rdata2); // Estimated parameter must be close to real. - REQUIRE(gDist2.Alpha(0) == Approx(alphaReal2).epsilon(errorTolerance / 100)); - REQUIRE(gDist2.Beta(0) == Approx(betaReal2).epsilon(errorTolerance / 100)); + BOOST_REQUIRE_CLOSE(gDist2.Alpha(0), alphaReal2, errorTolerance); + BOOST_REQUIRE_CLOSE(gDist2.Beta(0), betaReal2, errorTolerance); } /** * Test that Train() and the constructor that takes data give the same resulting * distribution. */ -TEST_CASE("GammaDistributionTrainConstructorTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionTrainConstructorTest) { const arma::mat data = arma::randu(10, 500); @@ -905,8 +887,8 @@ TEST_CASE("GammaDistributionTrainConstructorTest", "[DistributionTest]") for (size_t i = 0; i < 10; ++i) { - REQUIRE(d1.Alpha(i) == Approx(d2.Alpha(i)).epsilon(1e-7)); - REQUIRE(d1.Beta(i) == Approx(d2.Beta(i)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d1.Alpha(i), d2.Alpha(i), 1e-5); + BOOST_REQUIRE_CLOSE(d1.Beta(i), d2.Beta(i), 1e-5); } } @@ -914,7 +896,7 @@ TEST_CASE("GammaDistributionTrainConstructorTest", "[DistributionTest]") * Test that Train() with a dataset and Train() with dataset statistics return * the same results. */ -TEST_CASE("GammaDistributionTrainStatisticsTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionTrainStatisticsTest) { const arma::mat data = arma::randu(1, 500); @@ -928,15 +910,15 @@ TEST_CASE("GammaDistributionTrainStatisticsTest", "[DistributionTest]") const arma::vec logMeanx = arma::log(meanx); d2.Train(logMeanx, meanLogx, meanx); - REQUIRE(d1.Alpha(0) == Approx(d2.Alpha(0)).epsilon(1e-7)); - REQUIRE(d1.Beta(0) == Approx(d2.Beta(0)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d1.Alpha(0), d2.Alpha(0), 1e-5); + BOOST_REQUIRE_CLOSE(d1.Beta(0), d2.Beta(0), 1e-5); } /** * Tests that Random() generates points that can be reasonably well fit by the * distribution that generated them. */ -TEST_CASE("GammaDistributionRandomTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionRandomTest) { const arma::vec a("2.0 2.5 3.0"), b("0.4 0.6 1.3"); const size_t numPoints = 2000; @@ -952,12 +934,12 @@ TEST_CASE("GammaDistributionRandomTest", "[DistributionTest]") GammaDistribution d2(data); for (size_t i = 0; i < 3; ++i) { - REQUIRE(d2.Alpha(i) == Approx(a(i)).epsilon(0.1)); // Within 10% - REQUIRE(d2.Beta(i) == Approx(b(i)).epsilon(0.1)); + BOOST_REQUIRE_CLOSE(d2.Alpha(i), a(i), 10); // Within 10% + BOOST_REQUIRE_CLOSE(d2.Beta(i), b(i), 10); } } -TEST_CASE("GammaDistributionProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionProbabilityTest) { // Train two 1-dimensional distributions. const arma::vec a1("2.0"), b1("0.9"), a2("3.1"), b2("1.4"); @@ -967,16 +949,16 @@ TEST_CASE("GammaDistributionProbabilityTest", "[DistributionTest]") // Evaluated at wolfram|alpha GammaDistribution d1(a1, b1); d1.Probability(x1, prob1); - REQUIRE(prob1(0) == Approx(0.267575).epsilon(1e-5)); + BOOST_REQUIRE_CLOSE(prob1(0), 0.267575, 1e-3); // Evaluated at wolfram|alpha GammaDistribution d2(a2, b2); d2.Probability(x2, prob2); - REQUIRE(prob2(0) == Approx(0.189043).epsilon(1e-5)); + BOOST_REQUIRE_CLOSE(prob2(0), 0.189043, 1e-3); // Check that the overload that returns the probability for 1 dimension // agrees. - REQUIRE(prob2(0) == Approx(d2.Probability(2.94, 0)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(prob2(0), d2.Probability(2.94, 0), 1e-5); // Combine into one 2-dimensional distribution. const arma::vec a3("2.0 3.1"), b3("0.9 1.4"); @@ -989,11 +971,11 @@ TEST_CASE("GammaDistributionProbabilityTest", "[DistributionTest]") // 1-dimensional distributions (evaluated at wolfram|alpha). GammaDistribution d3(a3, b3); d3.Probability(x3, prob3); - REQUIRE(prob3(0) == Approx(0.04408).epsilon(1e-4)); - REQUIRE(prob3(1) == Approx(0.026165).epsilon(1e-4)); + BOOST_REQUIRE_CLOSE(prob3(0), 0.04408, 1e-2); + BOOST_REQUIRE_CLOSE(prob3(1), 0.026165, 1e-2); } -TEST_CASE("GammaDistributionLogProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GammaDistributionLogProbabilityTest) { // Train two 1-dimensional distributions. const arma::vec a1("2.0"), b1("0.9"), a2("3.1"), b2("1.4"); @@ -1003,16 +985,16 @@ TEST_CASE("GammaDistributionLogProbabilityTest", "[DistributionTest]") // Evaluated at wolfram|alpha GammaDistribution d1(a1, b1); d1.LogProbability(x1, logprob1); - REQUIRE(logprob1(0) == Approx(std::log(0.267575)).epsilon(1e-5)); + BOOST_REQUIRE_CLOSE(logprob1(0), std::log(0.267575), 1e-3); // Evaluated at wolfram|alpha GammaDistribution d2(a2, b2); d2.LogProbability(x2, logprob2); - REQUIRE(logprob2(0) == Approx(std::log(0.189043)).epsilon(1e-5)); + BOOST_REQUIRE_CLOSE(logprob2(0), std::log(0.189043), 1e-3); // Check that the overload that returns the log probability for // 1 dimension agrees. - REQUIRE(logprob2(0) == Approx(d2.LogProbability(2.94, 0)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(logprob2(0), d2.LogProbability(2.94, 0), 1e-5); // Combine into one 2-dimensional distribution. const arma::vec a3("2.0 3.1"), b3("0.9 1.4"); @@ -1026,14 +1008,14 @@ TEST_CASE("GammaDistributionLogProbabilityTest", "[DistributionTest]") // 1-dimensional distributions (evaluated at wolfram|alpha). GammaDistribution d3(a3, b3); d3.LogProbability(x3, logprob3); - REQUIRE(logprob3(0) == Approx(std::log(0.04408)).epsilon(1e-5)); - REQUIRE(logprob3(1) == Approx(std::log(0.026165)).epsilon(1e-5)); + BOOST_REQUIRE_CLOSE(logprob3(0), std::log(0.04408), 1e-3); + BOOST_REQUIRE_CLOSE(logprob3(1), std::log(0.026165), 1e-3); } /** * Discrete Distribution serialization test. */ -TEST_CASE("DiscreteDistributionTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiscreteDistributionTest) { // I assume that I am properly saving vectors, so, this should be // straightforward. @@ -1054,15 +1036,15 @@ TEST_CASE("DiscreteDistributionTest", "[DistributionTest]") const double prob = t.Probability(obs); if (prob == 0.0) { - REQUIRE(xmlT.Probability(obs) == Approx(0.0).margin(1e-8)); - REQUIRE(textT.Probability(obs) == Approx(0.0).margin(1e-8)); - REQUIRE(binaryT.Probability(obs) == Approx(0.0).margin(1e-8)); + BOOST_REQUIRE_SMALL(xmlT.Probability(obs), 1e-8); + BOOST_REQUIRE_SMALL(textT.Probability(obs), 1e-8); + BOOST_REQUIRE_SMALL(binaryT.Probability(obs), 1e-8); } else { - REQUIRE(prob == Approx(xmlT.Probability(obs)).epsilon(1e-10)); - REQUIRE(prob == Approx(textT.Probability(obs)).epsilon(1e-10)); - REQUIRE(prob == Approx(binaryT.Probability(obs)).epsilon(1e-10)); + BOOST_REQUIRE_CLOSE(prob, xmlT.Probability(obs), 1e-8); + BOOST_REQUIRE_CLOSE(prob, textT.Probability(obs), 1e-8); + BOOST_REQUIRE_CLOSE(prob, binaryT.Probability(obs), 1e-8); } } } @@ -1070,7 +1052,7 @@ TEST_CASE("DiscreteDistributionTest", "[DistributionTest]") /** * Gaussian Distribution serialization test. */ -TEST_CASE("GaussianDistributionTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(GaussianDistributionTest) { arma::vec mean(10); mean.randu(); @@ -1084,9 +1066,9 @@ TEST_CASE("GaussianDistributionTest", "[DistributionTest]") SerializeObjectAll(g, xmlG, textG, binaryG); - REQUIRE(g.Dimensionality() == xmlG.Dimensionality()); - REQUIRE(g.Dimensionality() == textG.Dimensionality()); - REQUIRE(g.Dimensionality() == binaryG.Dimensionality()); + BOOST_REQUIRE_EQUAL(g.Dimensionality(), xmlG.Dimensionality()); + BOOST_REQUIRE_EQUAL(g.Dimensionality(), textG.Dimensionality()); + BOOST_REQUIRE_EQUAL(g.Dimensionality(), binaryG.Dimensionality()); // First, check the means. CheckMatrices(g.Mean(), xmlG.Mean(), textG.Mean(), binaryG.Mean()); @@ -1106,21 +1088,18 @@ TEST_CASE("GaussianDistributionTest", "[DistributionTest]") if (prob == 0.0) { - REQUIRE(xmlG.Probability(randomObs.unsafe_col(i)) == - Approx(0.0).margin(1e-8)); - REQUIRE(textG.Probability(randomObs.unsafe_col(i)) == - Approx(0.0).margin(1e-8)); - REQUIRE(binaryG.Probability(randomObs.unsafe_col(i)) == - Approx(0.0).margin(1e-8)); + BOOST_REQUIRE_SMALL(xmlG.Probability(randomObs.unsafe_col(i)), 1e-8); + BOOST_REQUIRE_SMALL(textG.Probability(randomObs.unsafe_col(i)), 1e-8); + BOOST_REQUIRE_SMALL(binaryG.Probability(randomObs.unsafe_col(i)), 1e-8); } else { - REQUIRE(prob == - Approx(xmlG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); - REQUIRE(prob == - Approx(textG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); - REQUIRE(prob == - Approx(binaryG.Probability(randomObs.unsafe_col(i))).epsilon(1e-10)); + BOOST_REQUIRE_CLOSE(prob, xmlG.Probability(randomObs.unsafe_col(i)), + 1e-8); + BOOST_REQUIRE_CLOSE(prob, textG.Probability(randomObs.unsafe_col(i)), + 1e-8); + BOOST_REQUIRE_CLOSE(prob, binaryG.Probability(randomObs.unsafe_col(i)), + 1e-8); } } } @@ -1128,7 +1107,7 @@ TEST_CASE("GaussianDistributionTest", "[DistributionTest]") /** * Laplace Distribution serialization test. */ -TEST_CASE("LaplaceDistributionTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(LaplaceDistributionTest) { arma::vec mean(20); mean.randu(); @@ -1138,9 +1117,9 @@ TEST_CASE("LaplaceDistributionTest", "[DistributionTest]") SerializeObjectAll(l, xmlL, textL, binaryL); - REQUIRE(l.Scale() == Approx(xmlL.Scale()).epsilon(1e-10)); - REQUIRE(l.Scale() == Approx(textL.Scale()).epsilon(1e-10)); - REQUIRE(l.Scale() == Approx(binaryL.Scale()).epsilon(1e-10)); + BOOST_REQUIRE_CLOSE(l.Scale(), xmlL.Scale(), 1e-8); + BOOST_REQUIRE_CLOSE(l.Scale(), textL.Scale(), 1e-8); + BOOST_REQUIRE_CLOSE(l.Scale(), binaryL.Scale(), 1e-8); CheckMatrices(l.Mean(), xmlL.Mean(), textL.Mean(), binaryL.Mean()); } @@ -1148,15 +1127,15 @@ TEST_CASE("LaplaceDistributionTest", "[DistributionTest]") /** * Laplace Distribution Probability Test. */ -TEST_CASE("LaplaceDistributionProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(LaplaceDistributionProbabilityTest) { LaplaceDistribution l(arma::vec("0.0"), 1.0); // Simple case. - REQUIRE(l.Probability(arma::vec("0.0")) == - Approx(0.500000000000000).epsilon(1e-7)); - REQUIRE(l.Probability(arma::vec("1.0")) == - Approx(0.183939720585721).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(l.Probability(arma::vec("0.0")), + 0.500000000000000, 1e-5); + BOOST_REQUIRE_CLOSE(l.Probability(arma::vec("1.0")), + 0.183939720585721, 1e-5); arma::mat points = "0.0 1.0;"; @@ -1164,24 +1143,24 @@ TEST_CASE("LaplaceDistributionProbabilityTest", "[DistributionTest]") l.Probability(points, probabilities); - REQUIRE(probabilities.n_elem == 2); + BOOST_REQUIRE_EQUAL(probabilities.n_elem, 2); - REQUIRE(probabilities(0) == Approx(0.500000000000000).epsilon(1e-7)); - REQUIRE(probabilities(1) == Approx(0.183939720585721).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(probabilities(0), 0.500000000000000, 1e-5); + BOOST_REQUIRE_CLOSE(probabilities(1), 0.183939720585721, 1e-5); } /** * Laplace Distribution Log Probability Test. */ -TEST_CASE("LaplaceDistributionLogProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(LaplaceDistributionLogProbabilityTest) { LaplaceDistribution l(arma::vec("0.0"), 1.0); // Simple case. - REQUIRE(l.LogProbability(arma::vec("0.0")) == - Approx(-0.693147180559945).epsilon(1e-7)); - REQUIRE(l.LogProbability(arma::vec("1.0")) == - Approx(-1.693147180559946).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(l.LogProbability(arma::vec("0.0")), + -0.693147180559945, 1e-5); + BOOST_REQUIRE_CLOSE(l.LogProbability(arma::vec("1.0")), + -1.693147180559946, 1e-5); arma::mat points = "0.0 1.0;"; @@ -1189,19 +1168,18 @@ TEST_CASE("LaplaceDistributionLogProbabilityTest", "[DistributionTest]") l.LogProbability(points, logProbabilities); - REQUIRE(logProbabilities.n_elem == 2); + BOOST_REQUIRE_EQUAL(logProbabilities.n_elem, 2); - REQUIRE(logProbabilities(0) == - Approx(-0.693147180559945).epsilon(1e-7)); - - REQUIRE(logProbabilities(1) == - Approx(-1.693147180559946).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(logProbabilities(0), -0.693147180559945, + 1e-5); + BOOST_REQUIRE_CLOSE(logProbabilities(1), -1.693147180559946, + 1e-5); } /** * Mahalanobis Distance serialization test. */ -TEST_CASE("MahalanobisDistanceTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(MahalanobisDistanceTest) { MahalanobisDistance<> d; d.Covariance().randu(50, 50); @@ -1220,7 +1198,7 @@ TEST_CASE("MahalanobisDistanceTest", "[DistributionTest]") /** * Regression distribution serialization test. */ -TEST_CASE("RegressionDistributionTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(RegressionDistributionTest) { // Generate some random data. arma::mat data; @@ -1247,15 +1225,15 @@ TEST_CASE("RegressionDistributionTest", "[DistributionTest]") // Check the regression function. if (rd.Rf().Lambda() == 0.0) { - REQUIRE(xmlRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); - REQUIRE(textRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); - REQUIRE(binaryRd.Rf().Lambda() == Approx(0.0).margin(1e-8)); + BOOST_REQUIRE_SMALL(xmlRd.Rf().Lambda(), 1e-8); + BOOST_REQUIRE_SMALL(textRd.Rf().Lambda(), 1e-8); + BOOST_REQUIRE_SMALL(binaryRd.Rf().Lambda(), 1e-8); } else { - REQUIRE(rd.Rf().Lambda() == Approx(xmlRd.Rf().Lambda()).epsilon(1e-10)); - REQUIRE(rd.Rf().Lambda() == Approx(textRd.Rf().Lambda()).epsilon(1e-10)); - REQUIRE(rd.Rf().Lambda() == Approx(binaryRd.Rf().Lambda()).epsilon(1e-10)); + BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), xmlRd.Rf().Lambda(), 1e-8); + BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), textRd.Rf().Lambda(), 1e-8); + BOOST_REQUIRE_CLOSE(rd.Rf().Lambda(), binaryRd.Rf().Lambda(), 1e-8); } CheckMatrices(rd.Rf().Parameters(), @@ -1272,32 +1250,31 @@ TEST_CASE("RegressionDistributionTest", "[DistributionTest]") * Make sure Diagonal Covariance Gaussian distributions are initialized * correctly. */ -TEST_CASE("DiagonalGaussianDistributionEmptyConstructor", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionEmptyConstructor) { DiagonalGaussianDistribution d; - REQUIRE(d.Mean().n_elem == 0); - REQUIRE(d.Covariance().n_elem == 0); + BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 0); + BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 0); } /** * Make sure Diagonal Covariance Gaussian distributions are initialized to * the correct dimensionality. */ -TEST_CASE("DiagonalGaussianDistributionDimensionalityConstructor", - "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionDimensionalityConstructor) { DiagonalGaussianDistribution d(4); - REQUIRE(d.Mean().n_elem == 4); - REQUIRE(d.Covariance().n_elem == 4); + BOOST_REQUIRE_EQUAL(d.Mean().n_elem, 4); + BOOST_REQUIRE_EQUAL(d.Covariance().n_elem, 4); } /** * Make sure Diagonal Covariance Gaussian distributions are initialized * correctly when we give a mean and covariance. */ -TEST_CASE("DiagonalGaussianDistributionConstructor", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionConstructor) { arma::vec mean = arma::randu(3); arma::vec covariance = arma::randu(3); @@ -1307,8 +1284,8 @@ TEST_CASE("DiagonalGaussianDistributionConstructor", "[DistributionTest]") // Make sure the mean and covariance is correct. for (size_t i = 0; i < 3; ++i) { - REQUIRE(d.Mean()(i) == Approx(mean(i)).epsilon(1e-7)); - REQUIRE(d.Covariance()(i) == Approx(covariance(i)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Mean()(i), mean(i), 1e-5); + BOOST_REQUIRE_CLOSE(d.Covariance()(i), covariance(i), 1e-5); } } @@ -1316,7 +1293,7 @@ TEST_CASE("DiagonalGaussianDistributionConstructor", "[DistributionTest]") * Make sure the probability of observations is correct. * The values were calculated using 'dmvnorm' in R. */ -TEST_CASE("DiagonalGaussianDistributionProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionProbabilityTest) { arma::vec mean("2 5 3 4 1"); arma::vec cov("3 1 5 3 2"); @@ -1324,56 +1301,56 @@ TEST_CASE("DiagonalGaussianDistributionProbabilityTest", "[DistributionTest]") DiagonalGaussianDistribution d(mean, cov); // Observations lists randomly selected. - REQUIRE(d.LogProbability("3 5 2 7 8") == - Approx(-20.861264167855161).epsilon(1e-7)); - REQUIRE(d.LogProbability("7 8 4 0 5") == - Approx(-22.277930834521829).epsilon(1e-7)); - REQUIRE(d.LogProbability("6 8 7 7 5") == - Approx(-21.111264167855161).epsilon(1e-7)); - REQUIRE(d.LogProbability("2 9 5 6 3") == - Approx(-16.9112641678551621).epsilon(1e-7)); - REQUIRE(d.LogProbability("5 8 2 9 7") == - Approx(-26.111264167855161).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.LogProbability("3 5 2 7 8"), -20.861264167855161, + 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("7 8 4 0 5"), -22.277930834521829, + 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("6 8 7 7 5"), -21.111264167855161, + 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("2 9 5 6 3"), -16.911264167855162, + 1e-5); + BOOST_REQUIRE_CLOSE(d.LogProbability("5 8 2 9 7"), -26.111264167855161, + 1e-5); } /** * Test DiagonalGaussianDistribution::Probability() in the univariate case. * The values were calculated using 'dmvnorm' in R. */ -TEST_CASE("DiagonalGaussianUnivariateProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianUnivariateProbabilityTest) { DiagonalGaussianDistribution d(arma::vec("0.0"), arma::vec("1.0")); // Mean: 0.0, Covariance: 1.0 - REQUIRE(d.Probability("0.0") == Approx(0.3989422804014327).epsilon(1e-7)); - REQUIRE(d.Probability("1.0") == Approx(0.24197072451914337).epsilon(1e-7)); - REQUIRE(d.Probability("-1.0") == Approx(0.24197072451914337).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.3989422804014327, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.24197072451914337, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.24197072451914337, 1e-5); // Mean: 0.0, Covariance: 2.0 d.Covariance("2.0"); - REQUIRE(d.Probability("0.0") == Approx(0.28209479177387814).epsilon(1e-7)); - REQUIRE(d.Probability("1.0") == Approx(0.21969564473386122).epsilon(1e-7)); - REQUIRE(d.Probability("-1.0") == Approx(0.21969564473386122).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.28209479177387814, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.21969564473386122, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.21969564473386122, 1e-5); // Mean: 1.0, Covariance: 1.0 d.Mean() = "1.0"; d.Covariance("1.0"); - REQUIRE(d.Probability("0.0") == Approx(0.24197072451914337).epsilon(1e-7)); - REQUIRE(d.Probability("1.0") == Approx(0.3989422804014327).epsilon(1e-7)); - REQUIRE(d.Probability("-1.0") == Approx(0.053990966513188056).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.24197072451914337, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.3989422804014327, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.053990966513188056, 1e-5); // Mean: 1.0, Covariance: 2.0 d.Covariance("2.0"); - REQUIRE(d.Probability("0.0") == Approx(0.21969564473386122).epsilon(1e-7)); - REQUIRE(d.Probability("1.0") == Approx(0.28209479177387814).epsilon(1e-7)); - REQUIRE(d.Probability("-1.0") == Approx(0.10377687435514872).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability("0.0"), 0.21969564473386122, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("1.0"), 0.28209479177387814, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability("-1.0"), 0.10377687435514872, 1e-5); } /** * Test DiagonalGaussianDistribution::Probability() in the multivariate case. * The values were calculated using 'dmvnorm' in R. */ -TEST_CASE("DiagonalGaussianMultivariateProbabilityTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianMultivariateProbabilityTest) { arma::vec mean("0 0"); arma::vec cov("2 2"); @@ -1381,28 +1358,27 @@ TEST_CASE("DiagonalGaussianMultivariateProbabilityTest", "[DistributionTest]") DiagonalGaussianDistribution d(mean, cov); - REQUIRE(d.Probability(obs) == Approx(0.079577471545947673).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.079577471545947673, 1e-5); obs = "1 1"; - REQUIRE(d.Probability(obs) == Approx(0.048266176315026957).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.048266176315026957, 1e-5); d.Mean() = "1 3"; - REQUIRE(d.Probability(obs) == Approx(0.029274915762159581).epsilon(1e-7)); - REQUIRE(d.Probability(-obs) == Approx(0.00053618878559782773).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability(obs), 0.029274915762159581, 1e-5); + BOOST_REQUIRE_CLOSE(d.Probability(-obs), 0.00053618878559782773, 1e-5); // Higher dimensional case. d.Mean() = "1 3 6 2 7"; d.Covariance("3 1 5 3 2"); obs = "2 5 7 3 8"; - REQUIRE(d.Probability(obs) == Approx(7.2790083003378082e-05).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Probability(obs), 7.2790083003378082e-05, 1e-5); } /** * Test the phi() function, for multiple points in the multivariate Gaussian * case. The values were calculated using 'dmvnorm' in R. */ -TEST_CASE("DiagonalGaussianMultipointMultivariateProbabilityTest", - "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianMultipointMultivariateProbabilityTest) { arma::vec mean = "2 5 3 7 2"; arma::vec cov("9 2 1 4 8"); @@ -1415,20 +1391,20 @@ TEST_CASE("DiagonalGaussianMultipointMultivariateProbabilityTest", DiagonalGaussianDistribution d(mean, cov); d.LogProbability(points, phis); - REQUIRE(phis.n_elem == 6); + BOOST_REQUIRE_EQUAL(phis.n_elem, 6); - REQUIRE(phis(0) == Approx(-12.453302051926864).epsilon(1e-7)); - REQUIRE(phis(1) == Approx(-10.147746496371308).epsilon(1e-7)); - REQUIRE(phis(2) == Approx(-13.210246496371308).epsilon(1e-7)); - REQUIRE(phis(3) == Approx(-19.724135385260197).epsilon(1e-7)); - REQUIRE(phis(4) == Approx(-21.585246496371308).epsilon(1e-7)); - REQUIRE(phis(5) == Approx(-13.647746496371308).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(phis(0), -12.453302051926864, 1e-5); + BOOST_REQUIRE_CLOSE(phis(1), -10.147746496371308, 1e-5); + BOOST_REQUIRE_CLOSE(phis(2), -13.210246496371308, 1e-5); + BOOST_REQUIRE_CLOSE(phis(3), -19.724135385260197, 1e-5); + BOOST_REQUIRE_CLOSE(phis(4), -21.585246496371308, 1e-5); + BOOST_REQUIRE_CLOSE(phis(5), -13.647746496371308, 1e-5); } /** * Make sure random observations follow the probability distribution correctly. */ -TEST_CASE("DiagonalGaussianDistributionRandomTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionRandomTest) { arma::vec mean("2.5 1.25"); arma::vec cov("0.50 0.25"); @@ -1445,17 +1421,17 @@ TEST_CASE("DiagonalGaussianDistributionRandomTest", "[DistributionTest]") arma::mat obsCov = mlpack::math::ColumnCovariance(obs); // 10% tolerance because this can be noisy. - REQUIRE(obsMean(0) == Approx(mean(0)).epsilon(0.1)); - REQUIRE(obsMean(1) == Approx(mean(1)).epsilon(0.1)); + BOOST_REQUIRE_CLOSE(obsMean(0), mean(0), 10.0); + BOOST_REQUIRE_CLOSE(obsMean(1), mean(1), 10.0); - REQUIRE(obsCov(0, 0) == Approx(cov(0)).epsilon(0.1)); - REQUIRE(obsCov(1, 1) == Approx(cov(1)).epsilon(0.1)); + BOOST_REQUIRE_CLOSE(obsCov(0, 0), cov(0), 10); + BOOST_REQUIRE_CLOSE(obsCov(1, 1), cov(1), 10); } /** * Make sure that we can properly estimate from given observations. */ -TEST_CASE("DiagonalGaussianDistributionTrainTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) { arma::vec mean("2.5 1.5 8.2 3.1"); arma::vec cov("1.2 3.1 8.3 4.3"); @@ -1478,8 +1454,8 @@ TEST_CASE("DiagonalGaussianDistributionTrainTest", "[DistributionTest]") // Check that the estimated parameters are right. for (size_t i = 0; i < 4; ++i) { - REQUIRE(d.Mean()(i) - actualMean(i) == Approx(0.0).margin(1e-5)); - REQUIRE(d.Covariance()(i) - actualCov(i, i) == Approx(0.0).margin(1e-5)); + BOOST_REQUIRE_SMALL(d.Mean()(i) - actualMean(i), 1e-5); + BOOST_REQUIRE_SMALL(d.Covariance()(i) - actualCov(i, i), 1e-5); } } @@ -1487,7 +1463,7 @@ TEST_CASE("DiagonalGaussianDistributionTrainTest", "[DistributionTest]") * Make sure the unbiased estimator of the weighted sample works correctly. * The values were calculated using 'cov.wt' in R. */ -TEST_CASE("DiagonalGaussianUnbiasedEstimatorTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianUnbiasedEstimatorTest) { // Generate the observations. arma::mat observations("3 5 2 7;" @@ -1502,15 +1478,15 @@ TEST_CASE("DiagonalGaussianUnbiasedEstimatorTest", "[DistributionTest]") // Estimate the parameters. d.Train(observations, probs); - REQUIRE(d.Mean()(0) == Approx(4.5).epsilon(1e-7)); - REQUIRE(d.Mean()(1) == Approx(4.4).epsilon(1e-7)); - REQUIRE(d.Mean()(2) == Approx(3.5).epsilon(1e-7)); - REQUIRE(d.Mean()(3) == Approx(6.8).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Mean()(0), 4.5, 1e-5); + BOOST_REQUIRE_CLOSE(d.Mean()(1), 4.4, 1e-5); + BOOST_REQUIRE_CLOSE(d.Mean()(2), 3.5, 1e-5); + BOOST_REQUIRE_CLOSE(d.Mean()(3), 6.8, 1e-5); - REQUIRE(d.Covariance()(0) == Approx(3.78571428571428603).epsilon(1e-7)); - REQUIRE(d.Covariance()(1) == Approx(6.34285714285714253).epsilon(1e-7)); - REQUIRE(d.Covariance()(2) == Approx(6.64285714285714235).epsilon(1e-7)); - REQUIRE(d.Covariance()(3) == Approx(2.22857142857142865).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d.Covariance()(0), 3.78571428571428603, 1e-5); + BOOST_REQUIRE_CLOSE(d.Covariance()(1), 6.34285714285714253, 1e-5); + BOOST_REQUIRE_CLOSE(d.Covariance()(2), 6.64285714285714235, 1e-5); + BOOST_REQUIRE_CLOSE(d.Covariance()(3), 2.22857142857142865, 1e-5); } /** @@ -1518,7 +1494,7 @@ TEST_CASE("DiagonalGaussianUnbiasedEstimatorTest", "[DistributionTest]") * the weighted mean and covariance reduce to the unweighted sample mean and * covariance. */ -TEST_CASE("DiagonalGaussianWeightedParametersReductionTest", "[DistributionTest]") +BOOST_AUTO_TEST_CASE(DiagonalGaussianWeightedParametersReductionTest) { arma::vec mean("2.5 1.5 8.2 3.1"); arma::vec cov("1.2 3.1 8.3 4.3"); @@ -1540,7 +1516,9 @@ TEST_CASE("DiagonalGaussianWeightedParametersReductionTest", "[DistributionTest] // Check if these are equal. for (size_t i = 0; i < 4; ++i) { - REQUIRE(d1.Mean()(i) == Approx(d2.Mean()(i)).epsilon(1e-7)); - REQUIRE(d1.Covariance()(i) == Approx(d2.Covariance()(i)).epsilon(1e-7)); + BOOST_REQUIRE_CLOSE(d1.Mean()(i), d2.Mean()(i), 1e-5); + BOOST_REQUIRE_CLOSE(d1.Covariance()(i), d2.Covariance()(i), 1e-5); } } + +BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/feedforward_network_test.cpp b/src/mlpack/tests/feedforward_network_test.cpp index bcffa4c8a8..ba45afd29d 100644 --- a/src/mlpack/tests/feedforward_network_test.cpp +++ b/src/mlpack/tests/feedforward_network_test.cpp @@ -148,10 +148,10 @@ TEST_CASE("CheckCopyMovingVanillaNetworkTest", "[FeedForwardNetworkTest]") model1->Add >(8, 3); model1->Add >(); - // Check whether copy constructor is working or not. + // Check whether copy cpnstructor is working or not. CheckCopyFunction<>(model, trainData, trainLabels, 1); - // Check whether move constructor is working or not. + // Check whether move cpnstructor is working or not. CheckMoveFunction<>(model1, trainData, trainLabels, 1); } @@ -489,7 +489,7 @@ TEST_CASE("FFNMiscTest", "[FeedForwardNetworkTest]") auto copiedModel(model); copiedModel = model; auto movedModel(std::move(model)); - auto moveOperator = std::move(copiedModel); + movedModel = std::move(copiedModel); } /** @@ -764,7 +764,7 @@ TEST_CASE("RBFNetworkTest", "[FeedForwardNetworkTest]") model.Add >(8, 3); // RBFN neural net with MeanSquaredError. - TestNetwork<>(model, trainData, trainLabels1, testData, testLabels, 10, 0.2); + TestNetwork<>(model, trainData, trainLabels1, testData, testLabels, 10, 0.1); arma::mat dataset; dataset.load("mnist_first250_training_4s_and_9s.arm"); @@ -796,5 +796,5 @@ TEST_CASE("RBFNetworkTest", "[FeedForwardNetworkTest]") model1.Add >(140, 2); // RBFN neural net with MeanSquaredError. - TestNetwork<>(model1, dataset, labels1, dataset, labels, 10, 0.2); + TestNetwork<>(model1, dataset, labels1, dataset, labels, 10, 0.1); } diff --git a/src/mlpack/tests/main_tests/mean_shift_test.cpp b/src/mlpack/tests/main_tests/mean_shift_test.cpp index 5da1c28b95..eea3ceb3c7 100644 --- a/src/mlpack/tests/main_tests/mean_shift_test.cpp +++ b/src/mlpack/tests/main_tests/mean_shift_test.cpp @@ -12,16 +12,15 @@ #include #define BINDING_TYPE BINDING_TYPE_TEST - -#include static const std::string testName = "MeanShift"; +#include #include #include - #include "test_helper.hpp" -#include "../test_catch_tools.hpp" -#include "../catch.hpp" + +#include +#include "../test_tools.hpp" using namespace mlpack; @@ -49,13 +48,13 @@ static void ResetSettings() IO::RestoreSettings(testName); } +BOOST_FIXTURE_TEST_SUITE(MeanShiftMainTest, MeanShiftTestFixture); + /** * Ensure that the output has 1 extra row for the labels and * check the number of points for output remain the same. */ -TEST_CASE_METHOD( - MeanShiftTestFixture, "MeanShiftOutputDimensionTest", - "[MeanShiftMainTest][BindingTests]") +BOOST_AUTO_TEST_CASE(MeanShiftOutputDimensionTest) { arma::mat x; x.randu(3, 100); // 100 points in 3 dimension @@ -66,18 +65,16 @@ TEST_CASE_METHOD( mlpackMain(); // Now check that the output has 1 extra row for labels. - REQUIRE(IO::GetParam("output").n_rows == 3 + 1); + BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_rows, 3 + 1); // Check number of output points are the same. - REQUIRE(IO::GetParam("output").n_cols == 100); + BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_cols, 100); } /** * Ensure that if we ask for labels_only, output has 1 row and * same number of columns for each point's label. */ -TEST_CASE_METHOD( - MeanShiftTestFixture, "MeanShiftLabelOnlyOutputDimensionTest", - "[MeanShiftMainTest][BindingTests]") +BOOST_AUTO_TEST_CASE(MeanShiftLabelOnlyOutputDimensionTest) { arma::mat x; x.randu(3, 100); // 100 points in 3 dimension @@ -89,9 +86,9 @@ TEST_CASE_METHOD( mlpackMain(); // Check that there is only 1 row containing all the labels. - REQUIRE(IO::GetParam("output").n_rows == 1); + BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_rows, 1); // Check number of output points are the same. - REQUIRE(IO::GetParam("output").n_cols == 100); + BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_cols, 100); } /** @@ -99,13 +96,11 @@ TEST_CASE_METHOD( * and check the number of points remain the same if the --in_place * flag is set. */ -TEST_CASE_METHOD( - MeanShiftTestFixture, "MeanShiftInPlaceTest", - "[MeanShiftMainTest][BindingTests]") +BOOST_AUTO_TEST_CASE(MeanShiftInPlaceTest) { arma::mat x; if (!data::Load("iris_test.csv", x)) - FAIL("Cannot load test dataset iris_test.csv!"); + BOOST_FAIL("Cannot load test dataset iris_test.csv!"); // Get initial number of rows and columns in file. int numRows = x.n_rows; @@ -118,22 +113,20 @@ TEST_CASE_METHOD( mlpackMain(); // Now check that the output has 1 extra row for labels. - REQUIRE(IO::GetParam("output").n_rows == numRows + 1); + BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_rows, numRows + 1); // Check number of output points are the same. - REQUIRE(IO::GetParam("output").n_cols == numCols); + BOOST_REQUIRE_EQUAL(IO::GetParam("output").n_cols, numCols); } /** * Ensure that force_convergence is used by testing that the * force_convergence flag makes a difference in the program. */ -TEST_CASE_METHOD( - MeanShiftTestFixture, "MeanShiftForceConvergenceTest", - "[MeanShiftMainTest][BindingTests]") +BOOST_AUTO_TEST_CASE(MeanShiftForceConvergenceTest) { arma::mat x; if (!data::Load("iris_test.csv", x)) - FAIL("Cannot load test dataset iris_test.csv!"); + BOOST_FAIL("Cannot load test dataset iris_test.csv!"); // Input random data points. SetInputParam("input", x); @@ -157,20 +150,18 @@ TEST_CASE_METHOD( const int numCentroids2 = IO::GetParam("centroid").n_cols; // Resulting number of centroids should be different. - REQUIRE(numCentroids1 != numCentroids2); + BOOST_REQUIRE_NE(numCentroids1, numCentroids2); } /** * Ensure that radius is used by testing that the radius * makes a difference in the program. */ -TEST_CASE_METHOD( - MeanShiftTestFixture, "MeanShiftRadiusTest", - "[MeanShiftMainTest][BindingTests]") +BOOST_AUTO_TEST_CASE(MeanShiftRadiusTest) { arma::mat x; if (!data::Load("iris_test.csv", x)) - FAIL("Cannot load test dataset iris_test.csv!"); + BOOST_FAIL("Cannot load test dataset iris_test.csv!"); // Input random data points. SetInputParam("input", x); @@ -192,20 +183,18 @@ TEST_CASE_METHOD( const int numCentroids2 = IO::GetParam("centroid").n_cols; // Resulting number of centroids should be different. - REQUIRE(numCentroids1 != numCentroids2); + BOOST_REQUIRE_NE(numCentroids1, numCentroids2); } /** * Ensure that max_iterations is used by testing that the * max_iteration makes a difference in the program. */ -TEST_CASE_METHOD( - MeanShiftTestFixture, "MeanShiftMaxIterationsTest", - "[MeanShiftMainTest][BindingTests]") +BOOST_AUTO_TEST_CASE(MeanShiftMaxIterationsTest) { arma::mat x; if (!data::Load("iris_test.csv", x)) - FAIL("Cannot load test dataset iris_test.csv!"); + BOOST_FAIL("Cannot load test dataset iris_test.csv!"); // Input random data points. SetInputParam("input", x); @@ -227,15 +216,13 @@ TEST_CASE_METHOD( const int numCentroids2 = IO::GetParam("centroid").n_cols; // Resulting number of centroids should be different. - REQUIRE(numCentroids1 != numCentroids2); + BOOST_REQUIRE_NE(numCentroids1, numCentroids2); } /** * Ensure that we can't specify an invalid max number of iterations. */ -TEST_CASE_METHOD( - MeanShiftTestFixture, "MeanShiftInvalidMaxIterationsTest", - "[MeanShiftMainTest][BindingTests]") +BOOST_AUTO_TEST_CASE(MeanShiftInvalidMaxIterationsTest) { arma::mat x; x.randu(3, 100); // 100 points in 3 dimension @@ -246,6 +233,8 @@ TEST_CASE_METHOD( SetInputParam("max_iterations", (int) -1); Log::Fatal.ignoreInput = true; - REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error); + BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; } + +BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/mean_shift_test.cpp b/src/mlpack/tests/mean_shift_test.cpp index 9f6c229639..818602f632 100644 --- a/src/mlpack/tests/mean_shift_test.cpp +++ b/src/mlpack/tests/mean_shift_test.cpp @@ -12,13 +12,15 @@ #include -#include "test_catch_tools.hpp" -#include "catch.hpp" +#include +#include "test_tools.hpp" using namespace mlpack; using namespace mlpack::meanshift; using namespace mlpack::distribution; +BOOST_AUTO_TEST_SUITE(MeanShiftTest); + // Generate dataset; written transposed because it's easier to read. arma::mat meanShiftData(" 0.0 0.0;" // Class 1. " 0.3 0.4;" @@ -55,7 +57,7 @@ arma::mat meanShiftData(" 0.0 0.0;" // Class 1. /** * 30-point 3-class test case for Mean Shift. */ -TEST_CASE("MeanShiftSimpleTest", "[MeanShiftTest]") +BOOST_AUTO_TEST_CASE(MeanShiftSimpleTest) { MeanShift<> meanShift; @@ -68,29 +70,29 @@ TEST_CASE("MeanShiftSimpleTest", "[MeanShiftTest]") size_t firstClass = assignments(0); for (size_t i = 1; i < 13; ++i) - REQUIRE(assignments(i) == firstClass); + BOOST_REQUIRE_EQUAL(assignments(i), firstClass); size_t secondClass = assignments(13); // To ensure that class 1 != class 2. - REQUIRE(firstClass != secondClass); + BOOST_REQUIRE_NE(firstClass, secondClass); for (size_t i = 13; i < 20; ++i) - REQUIRE(assignments(i) == secondClass); + BOOST_REQUIRE_EQUAL(assignments(i), secondClass); size_t thirdClass = assignments(20); // To ensure that this is the third class which we haven't seen yet. - REQUIRE(firstClass != thirdClass); - REQUIRE(secondClass != thirdClass); + BOOST_REQUIRE_NE(firstClass, thirdClass); + BOOST_REQUIRE_NE(secondClass, thirdClass); for (size_t i = 20; i < 30; ++i) - REQUIRE(assignments(i) == thirdClass); + BOOST_REQUIRE_EQUAL(assignments(i), thirdClass); } // Generate samples from four Gaussians, and make sure mean shift nearly // recovers those four centers. -TEST_CASE("GaussianClustering", "[MeanShiftTest]") +BOOST_AUTO_TEST_CASE(GaussianClustering) { GaussianDistribution g1("0.0 0.0 0.0", arma::eye(3, 3)); GaussianDistribution g2("5.0 5.0 5.0", 2 * arma::eye(3, 3)); @@ -160,5 +162,7 @@ TEST_CASE("GaussianClustering", "[MeanShiftTest]") break; } - REQUIRE(success == true); + BOOST_REQUIRE_EQUAL(success, true); } + +BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/random_forest_test.cpp b/src/mlpack/tests/random_forest_test.cpp index 3db62942c3..edc6bb2b60 100644 --- a/src/mlpack/tests/random_forest_test.cpp +++ b/src/mlpack/tests/random_forest_test.cpp @@ -13,9 +13,8 @@ #include #include -#include "serialization_catch.hpp" -#include "test_catch_tools.hpp" #include "catch.hpp" +#include "serialization.hpp" #include "mock_categorical_data.hpp" using namespace mlpack; From 6e0484dcace31ce41e60497128a0bf26ad07b0b9 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Tue, 6 Oct 2020 10:49:43 +0530 Subject: [PATCH 09/11] static code fix try --- src/mlpack/tests/range_search_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index af01a26ccc..f8c8d23151 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -1287,7 +1287,7 @@ TEST_CASE("RSModelTest", "[RangeSearchTest]") models[26] = RSModel(RSModel::TreeTypes::OCTREE, true); models[27] = RSModel(RSModel::TreeTypes::OCTREE, false); - for (size_t j = 0; j != 2; ++j) + for (size_t j = 0; j < 3; ++j) { // Get a baseline. RangeSearch<> rs(referenceData); @@ -1373,7 +1373,7 @@ TEST_CASE("RSModelMonochromaticTest", "[RangeSearchTest]") models[26] = RSModel(RSModel::TreeTypes::OCTREE, true); models[27] = RSModel(RSModel::TreeTypes::OCTREE, false); - for (size_t j = 0; j != 2; ++j) + for (size_t j = 0; j < 3; ++j) { // Get a baseline. RangeSearch<> rs(referenceData); From b4c1a40645507b744dd2c584bd0937a88d0bb451 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Tue, 6 Oct 2020 14:35:08 +0530 Subject: [PATCH 10/11] indentation fixed --- .../tests/main_tests/range_search_test.cpp | 12 ++-- src/mlpack/tests/range_search_test.cpp | 60 +++++++++---------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/mlpack/tests/main_tests/range_search_test.cpp b/src/mlpack/tests/main_tests/range_search_test.cpp index b32478da23..3d9fd08bb5 100644 --- a/src/mlpack/tests/main_tests/range_search_test.cpp +++ b/src/mlpack/tests/main_tests/range_search_test.cpp @@ -299,7 +299,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "ModelCheck", CheckMatrices(distances, distancetemp); REQUIRE(ModelToString(outputModel) == - ModelToString(IO::GetParam("output_model"))); + ModelToString(IO::GetParam("output_model"))); remove(neighborsFile.c_str()); remove(distanceFile.c_str()); @@ -357,7 +357,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "LeafValueTesting", CheckMatrices(distances, distancestemp); REQUIRE(ModelToString(outputModel1) != - ModelToString(IO::GetParam("output_model"))); + ModelToString(IO::GetParam("output_model"))); if (i != leafSizes.size() - 1) delete IO::GetParam("output_model"); @@ -431,7 +431,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "TreeTypeTesting", CheckMatrices(neighbors, neighborsTemp); CheckMatrices(distances, distancestemp); REQUIRE(ModelToString(outputModel1) != - ModelToString(IO::GetParam("output_model"))); + ModelToString(IO::GetParam("output_model"))); if (i != trees.size() - 1) delete IO::GetParam("output_model"); @@ -480,7 +480,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "RandomBasisTesting", mlpackMain(); REQUIRE(ModelToString(outputModel) != - ModelToString(IO::GetParam("output_model"))); + ModelToString(IO::GetParam("output_model"))); delete outputModel; @@ -535,7 +535,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "NaiveModeTest", CheckMatrices(distances, distancestemp); REQUIRE(ModelToString(outputModel) != - ModelToString(IO::GetParam("output_model"))); + ModelToString(IO::GetParam("output_model"))); delete outputModel; @@ -589,7 +589,7 @@ TEST_CASE_METHOD(RangeSearchTestFixture, "SingleModeTest", CheckMatrices(neighbors, neighborsTemp); CheckMatrices(distances, distancestemp); REQUIRE(ModelToString(outputModel) != - ModelToString(IO::GetParam("output_model"))); + ModelToString(IO::GetParam("output_model"))); delete outputModel; diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index f8c8d23151..ccf839a018 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -491,8 +491,8 @@ TEST_CASE("DualTreeVsNaive1", "[RangeSearchTest]") for (size_t j = 0; j < sortedTree[i].size(); ++j) { REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); - REQUIRE(sortedTree[i][j].first == Approx(sortedNaive[i][j].first).epsilon - (1e-5)); + REQUIRE(sortedTree[i][j].first == + Approx(sortedNaive[i][j].first).epsilon(1e-7)); } } } @@ -540,8 +540,8 @@ TEST_CASE("DualTreeVsNaive2", "[RangeSearchTest]") for (size_t j = 0; j < sortedTree[i].size(); ++j) { REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); - REQUIRE(sortedTree[i][j].first == Approx(sortedNaive[i][j].first).epsilon - (1e-5)); + REQUIRE(sortedTree[i][j].first == + Approx(sortedNaive[i][j].first).epsilon(1e-7)); } } } @@ -589,8 +589,8 @@ TEST_CASE("SingleTreeVsNaive", "[RangeSearchTest]") for (size_t j = 0; j < sortedTree[i].size(); ++j) { REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); - REQUIRE(sortedTree[i][j].first == Approx(sortedNaive[i][j].first).epsilon - (1e-5)); + REQUIRE(sortedTree[i][j].first == + Approx(sortedNaive[i][j].first).epsilon(1e-7)); } } } @@ -662,8 +662,8 @@ TEST_CASE("CoverTreeTest", "[RangeSearchTest]") for (size_t j = 0; j < kdSorted[i].size(); ++j) { REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); - REQUIRE(kdSorted[i][j].first == Approx(coverSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(kdSorted[i][j].first == + Approx(coverSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } @@ -740,8 +740,8 @@ TEST_CASE("CoverTreeTwoDatasetsTest", "[RangeSearchTest]") for (size_t j = 0; j < kdSorted[i].size(); ++j) { REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); - REQUIRE(kdSorted[i][j].first == Approx(coverSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(kdSorted[i][j].first == + Approx(coverSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } @@ -814,8 +814,8 @@ TEST_CASE("CoverTreeSingleTreeTest", "[RangeSearchTest]") for (size_t j = 0; j < kdSorted[i].size(); ++j) { REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); - REQUIRE(kdSorted[i][j].first == Approx(coverSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(kdSorted[i][j].first == + Approx(coverSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } @@ -888,8 +888,8 @@ TEST_CASE("SingleBallTreeTest", "[RangeSearchTest]") for (size_t j = 0; j < kdSorted[i].size(); ++j) { REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); - REQUIRE(kdSorted[i][j].first == Approx(ballSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(kdSorted[i][j].first == + Approx(ballSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == ballSorted[i].size()); } @@ -962,8 +962,8 @@ TEST_CASE("DualBallTreeTest", "[RangeSearchTest]") for (size_t j = 0; j < kdSorted[i].size(); ++j) { REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); - REQUIRE(kdSorted[i][j].first == Approx(ballSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(kdSorted[i][j].first == + Approx(ballSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == ballSorted[i].size()); } @@ -1041,8 +1041,8 @@ TEST_CASE("DualBallTreeTest2", "[RangeSearchTest]") for (size_t j = 0; j < kdSorted[i].size(); ++j) { REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); - REQUIRE(kdSorted[i][j].first == Approx(ballSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(kdSorted[i][j].first == + Approx(ballSorted[i][j].first).epsilon (1e-7)); } } } @@ -1104,8 +1104,8 @@ TEST_CASE("RangeSearchTrainTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(sorted[i][j].first == + Approx(baselineSorted[i][j].first).epsilon(1e-7)); } } } @@ -1146,8 +1146,8 @@ TEST_CASE("TrainTreeTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(baselineSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(sorted[i][j].first == + Approx(baselineSorted[i][j].first).epsilon(1e-7)); } } } @@ -1201,8 +1201,8 @@ TEST_CASE("MoveConstructorMatrixTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == moveSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(sorted[i][j].first == + Approx(moveSorted[i][j].first).epsilon(1e-7)); } } } @@ -1244,8 +1244,8 @@ TEST_CASE("MoveTrainTest", "[RangeSearchTest]") for (size_t j = 0; j < sorted[i].size(); ++j) { REQUIRE(sorted[i][j].second == moveSorted[i][j].second); - REQUIRE(sorted[i][j].first == Approx(moveSorted[i][j].first).epsilon - (1e-7)); + REQUIRE(sorted[i][j].first == + Approx(moveSorted[i][j].first).epsilon(1e-7)); } } } @@ -1329,8 +1329,8 @@ TEST_CASE("RSModelTest", "[RangeSearchTest]") for (size_t l = 0; l < sorted[k].size(); ++l) { REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); - REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first). - epsilon(1e-7)); + REQUIRE(sorted[k][l].first == + Approx(baselineSorted[k][l].first).epsilon(1e-7)); } } } @@ -1412,8 +1412,8 @@ TEST_CASE("RSModelMonochromaticTest", "[RangeSearchTest]") for (size_t l = 0; l < sorted[k].size(); ++l) { REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); - REQUIRE(sorted[k][l].first == Approx(baselineSorted[k][l].first). - epsilon(1e-7)); + REQUIRE(sorted[k][l].first == + Approx(baselineSorted[k][l].first).epsilon(1e-7)); } } } From 76133b4f3f150f88a1d418f376411d35eba1fcf5 Mon Sep 17 00:00:00 2001 From: Aakash Kaushik Date: Fri, 9 Oct 2020 09:24:24 +0530 Subject: [PATCH 11/11] style guide changes --- src/mlpack/tests/range_search_test.cpp | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index ccf839a018..7bd714beaf 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -492,7 +492,7 @@ TEST_CASE("DualTreeVsNaive1", "[RangeSearchTest]") { REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); REQUIRE(sortedTree[i][j].first == - Approx(sortedNaive[i][j].first).epsilon(1e-7)); + Approx(sortedNaive[i][j].first).epsilon(1e-7)); } } } @@ -541,7 +541,7 @@ TEST_CASE("DualTreeVsNaive2", "[RangeSearchTest]") { REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); REQUIRE(sortedTree[i][j].first == - Approx(sortedNaive[i][j].first).epsilon(1e-7)); + Approx(sortedNaive[i][j].first).epsilon(1e-7)); } } } @@ -590,7 +590,7 @@ TEST_CASE("SingleTreeVsNaive", "[RangeSearchTest]") { REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); REQUIRE(sortedTree[i][j].first == - Approx(sortedNaive[i][j].first).epsilon(1e-7)); + Approx(sortedNaive[i][j].first).epsilon(1e-7)); } } } @@ -663,7 +663,7 @@ TEST_CASE("CoverTreeTest", "[RangeSearchTest]") { REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); REQUIRE(kdSorted[i][j].first == - Approx(coverSorted[i][j].first).epsilon(1e-7)); + Approx(coverSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } @@ -741,7 +741,7 @@ TEST_CASE("CoverTreeTwoDatasetsTest", "[RangeSearchTest]") { REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); REQUIRE(kdSorted[i][j].first == - Approx(coverSorted[i][j].first).epsilon(1e-7)); + Approx(coverSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } @@ -815,7 +815,7 @@ TEST_CASE("CoverTreeSingleTreeTest", "[RangeSearchTest]") { REQUIRE(kdSorted[i][j].second == coverSorted[i][j].second); REQUIRE(kdSorted[i][j].first == - Approx(coverSorted[i][j].first).epsilon(1e-7)); + Approx(coverSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == coverSorted[i].size()); } @@ -889,7 +889,7 @@ TEST_CASE("SingleBallTreeTest", "[RangeSearchTest]") { REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); REQUIRE(kdSorted[i][j].first == - Approx(ballSorted[i][j].first).epsilon(1e-7)); + Approx(ballSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == ballSorted[i].size()); } @@ -963,7 +963,7 @@ TEST_CASE("DualBallTreeTest", "[RangeSearchTest]") { REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); REQUIRE(kdSorted[i][j].first == - Approx(ballSorted[i][j].first).epsilon(1e-7)); + Approx(ballSorted[i][j].first).epsilon(1e-7)); } REQUIRE(kdSorted[i].size() == ballSorted[i].size()); } @@ -1042,7 +1042,7 @@ TEST_CASE("DualBallTreeTest2", "[RangeSearchTest]") { REQUIRE(kdSorted[i][j].second == ballSorted[i][j].second); REQUIRE(kdSorted[i][j].first == - Approx(ballSorted[i][j].first).epsilon (1e-7)); + Approx(ballSorted[i][j].first).epsilon (1e-7)); } } } @@ -1105,7 +1105,7 @@ TEST_CASE("RangeSearchTrainTest", "[RangeSearchTest]") { REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); REQUIRE(sorted[i][j].first == - Approx(baselineSorted[i][j].first).epsilon(1e-7)); + Approx(baselineSorted[i][j].first).epsilon(1e-7)); } } } @@ -1147,7 +1147,7 @@ TEST_CASE("TrainTreeTest", "[RangeSearchTest]") { REQUIRE(sorted[i][j].second == baselineSorted[i][j].second); REQUIRE(sorted[i][j].first == - Approx(baselineSorted[i][j].first).epsilon(1e-7)); + Approx(baselineSorted[i][j].first).epsilon(1e-7)); } } } @@ -1202,7 +1202,7 @@ TEST_CASE("MoveConstructorMatrixTest", "[RangeSearchTest]") { REQUIRE(sorted[i][j].second == moveSorted[i][j].second); REQUIRE(sorted[i][j].first == - Approx(moveSorted[i][j].first).epsilon(1e-7)); + Approx(moveSorted[i][j].first).epsilon(1e-7)); } } } @@ -1245,7 +1245,7 @@ TEST_CASE("MoveTrainTest", "[RangeSearchTest]") { REQUIRE(sorted[i][j].second == moveSorted[i][j].second); REQUIRE(sorted[i][j].first == - Approx(moveSorted[i][j].first).epsilon(1e-7)); + Approx(moveSorted[i][j].first).epsilon(1e-7)); } } } @@ -1330,7 +1330,7 @@ TEST_CASE("RSModelTest", "[RangeSearchTest]") { REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); REQUIRE(sorted[k][l].first == - Approx(baselineSorted[k][l].first).epsilon(1e-7)); + Approx(baselineSorted[k][l].first).epsilon(1e-7)); } } } @@ -1413,7 +1413,7 @@ TEST_CASE("RSModelMonochromaticTest", "[RangeSearchTest]") { REQUIRE(sorted[k][l].second == baselineSorted[k][l].second); REQUIRE(sorted[k][l].first == - Approx(baselineSorted[k][l].first).epsilon(1e-7)); + Approx(baselineSorted[k][l].first).epsilon(1e-7)); } } }