From ea6157820236b2dd5a7a8180657aaa87f5b225eb Mon Sep 17 00:00:00 2001 From: Manish Date: Wed, 2 May 2018 13:46:00 +0530 Subject: [PATCH] Reviewed Changes --- src/mlpack/methods/det/dt_utils.hpp | 6 +-- src/mlpack/tests/main_tests/lsh_test.cpp | 47 ++++++++++++++++---- src/mlpack/tests/main_tests/radical_test.cpp | 8 ++-- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/mlpack/methods/det/dt_utils.hpp b/src/mlpack/methods/det/dt_utils.hpp index 3e2c9ec7d4..4fb602fd4c 100644 --- a/src/mlpack/methods/det/dt_utils.hpp +++ b/src/mlpack/methods/det/dt_utils.hpp @@ -118,12 +118,12 @@ class PathCacher /** * Return the constructed path for a given tag. */ - const std::string& PathFor(int tag) const; + inline const std::string& PathFor(int tag) const; /** * Get the parent tag of a given tag. */ - int ParentOf(int tag) const; + inline int ParentOf(int tag) const; /** * Get the number of nodes in the path cache. @@ -138,7 +138,7 @@ class PathCacher PathFormat format; PathCacheType pathCache; - std::string BuildString(); + inline std::string BuildString(); }; } // namespace det diff --git a/src/mlpack/tests/main_tests/lsh_test.cpp b/src/mlpack/tests/main_tests/lsh_test.cpp index e49002358d..24e0e43c31 100644 --- a/src/mlpack/tests/main_tests/lsh_test.cpp +++ b/src/mlpack/tests/main_tests/lsh_test.cpp @@ -57,7 +57,8 @@ BOOST_AUTO_TEST_CASE(LSHOutputDimensionTest) // Check the neighbors matrix has 6 points for each of the 100 input points. BOOST_REQUIRE_EQUAL(CLI::GetParam>("neighbors").n_rows, 6); - BOOST_REQUIRE_EQUAL(CLI::GetParam>("neighbors").n_cols, 100); + BOOST_REQUIRE_EQUAL(CLI::GetParam>("neighbors").n_cols, + 100); // Check the distances matrix has 6 points for each of the 100 input points. BOOST_REQUIRE_EQUAL(CLI::GetParam("distances").n_rows, 6); @@ -84,7 +85,7 @@ BOOST_AUTO_TEST_CASE(LSHParamValidityTest) bindings::tests::CleanMemory(); - // Test for bucket_size. + // Test for second_hash_size. SetInputParam("reference", reference); SetInputParam("k", (int) 6); @@ -135,6 +136,7 @@ BOOST_AUTO_TEST_CASE(LSHDiffTablesTest) SetInputParam("reference", reference); SetInputParam("k", (int) 6); + mlpack::math::FixedRandomSeed(); mlpackMain(); arma::Mat neighbors = CLI::GetParam>("neighbors"); @@ -148,6 +150,7 @@ BOOST_AUTO_TEST_CASE(LSHDiffTablesTest) SetInputParam("k", (int) 6); SetInputParam("tables", (int) 40); + mlpack::math::FixedRandomSeed(); mlpackMain(); // Check that initial outputs and final outputs using two models are @@ -168,6 +171,7 @@ BOOST_AUTO_TEST_CASE(LSHDiffProjectionsTest) SetInputParam("reference", reference); SetInputParam("k", (int) 6); + mlpack::math::FixedRandomSeed(); mlpackMain(); arma::Mat neighbors = CLI::GetParam>("neighbors"); @@ -181,6 +185,7 @@ BOOST_AUTO_TEST_CASE(LSHDiffProjectionsTest) SetInputParam("k", (int) 6); SetInputParam("projections", (int) 30); + mlpack::math::FixedRandomSeed(); mlpackMain(); // Check that initial outputs and final outputs using two models are @@ -201,6 +206,7 @@ BOOST_AUTO_TEST_CASE(LSHDiffHashWidthTest) SetInputParam("reference", reference); SetInputParam("k", (int) 6); + mlpack::math::FixedRandomSeed(); mlpackMain(); arma::Mat neighbors = CLI::GetParam>("neighbors"); @@ -214,6 +220,7 @@ BOOST_AUTO_TEST_CASE(LSHDiffHashWidthTest) SetInputParam("k", (int) 6); SetInputParam("hash_width", (double) 0.5); + mlpack::math::FixedRandomSeed(); mlpackMain(); // Check that initial outputs and final outputs using two models are @@ -230,8 +237,10 @@ BOOST_AUTO_TEST_CASE(LSHDiffHashWidthTest) BOOST_AUTO_TEST_CASE(LSHDiffNumProbesTest) { arma::mat reference = arma::randu(5, 100); + arma::mat query = arma::randu(5, 40); - SetInputParam("reference", reference); + SetInputParam("reference", std::move(reference)); + SetInputParam("query", query); SetInputParam("k", (int) 6); mlpackMain(); @@ -239,12 +248,12 @@ BOOST_AUTO_TEST_CASE(LSHDiffNumProbesTest) arma::Mat neighbors = CLI::GetParam>("neighbors"); arma::mat distances = CLI::GetParam("distances"); - bindings::tests::CleanMemory(); + CLI::GetSingleton().Parameters()["reference"].wasPassed = false; // Train model using num_probes equals to 5. - SetInputParam("reference", std::move(reference)); - SetInputParam("k", (int) 6); + SetInputParam("input_model", CLI::GetParam*>("output_model")); + SetInputParam("query", std::move(query)); SetInputParam("num_probes", (int) 5); mlpackMain(); @@ -267,6 +276,7 @@ BOOST_AUTO_TEST_CASE(LSHDiffSecondHashSizeTest) SetInputParam("reference", reference); SetInputParam("k", (int) 6); + mlpack::math::FixedRandomSeed(); mlpackMain(); arma::Mat neighbors = CLI::GetParam>("neighbors"); @@ -280,6 +290,7 @@ BOOST_AUTO_TEST_CASE(LSHDiffSecondHashSizeTest) SetInputParam("k", (int) 6); SetInputParam("second_hash_size", (int) 5000); + mlpack::math::FixedRandomSeed(); mlpackMain(); // Check that initial outputs and final outputs using two models are @@ -300,6 +311,7 @@ BOOST_AUTO_TEST_CASE(LSHDiffBucketSizeTest) SetInputParam("reference", reference); SetInputParam("k", (int) 6); + mlpack::math::FixedRandomSeed(); mlpackMain(); arma::Mat neighbors = CLI::GetParam>("neighbors"); @@ -311,8 +323,9 @@ BOOST_AUTO_TEST_CASE(LSHDiffBucketSizeTest) SetInputParam("reference", std::move(reference)); SetInputParam("k", (int) 6); - SetInputParam("bucket_size", (int) 1000); + SetInputParam("bucket_size", (int) 1); + mlpack::math::FixedRandomSeed(); mlpackMain(); // Check that initial outputs and final outputs using the two models are @@ -344,7 +357,6 @@ BOOST_AUTO_TEST_CASE(LSHModelReuseTest) SetInputParam("input_model", CLI::GetParam*>("output_model")); SetInputParam("query", std::move(query)); - SetInputParam("k", (int) 6); mlpackMain(); @@ -354,4 +366,23 @@ BOOST_AUTO_TEST_CASE(LSHModelReuseTest) CheckMatrices(distances, CLI::GetParam("distances")); } +/** + * Make sure true_neighbors have valid dimensions. + */ +BOOST_AUTO_TEST_CASE(LSHModelTrueNighborsDimTest) +{ + arma::mat reference = arma::randu(5, 100); + + // Initalize trueNeighbors with invalid dimensions. + arma::Mat trueNeighbors = arma::randu>(7, 100); + + SetInputParam("reference", std::move(reference)); + SetInputParam("true_neighbors", std::move(trueNeighbors)); + SetInputParam("k", (int) 6); + + Log::Fatal.ignoreInput = true; + BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + Log::Fatal.ignoreInput = false; +} + BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/main_tests/radical_test.cpp b/src/mlpack/tests/main_tests/radical_test.cpp index 6baa2e4967..83f55e02b2 100644 --- a/src/mlpack/tests/main_tests/radical_test.cpp +++ b/src/mlpack/tests/main_tests/radical_test.cpp @@ -55,12 +55,12 @@ BOOST_AUTO_TEST_CASE(RadicalOutputDimensionTest) mlpackMain(); // Check dimension of Y matrix. - BOOST_REQUIRE_EQUAL(CLI::GetParam("output_ic").n_rows,5); - BOOST_REQUIRE_EQUAL(CLI::GetParam("output_ic").n_cols,3); + BOOST_REQUIRE_EQUAL(CLI::GetParam("output_ic").n_rows, 5); + BOOST_REQUIRE_EQUAL(CLI::GetParam("output_ic").n_cols, 3); // Check dimension of W matrix. - BOOST_REQUIRE_EQUAL(CLI::GetParam("output_unmixing").n_rows,5); - BOOST_REQUIRE_EQUAL(CLI::GetParam("output_unmixing").n_cols,5); + BOOST_REQUIRE_EQUAL(CLI::GetParam("output_unmixing").n_rows, 5); + BOOST_REQUIRE_EQUAL(CLI::GetParam("output_unmixing").n_cols, 5); } /**