From 87cb72eee08ca12f0add933befd556bc00e21c3d Mon Sep 17 00:00:00 2001 From: Yashwant Date: Sun, 19 May 2019 22:57:38 +0530 Subject: [PATCH 01/18] Add Gmm CLI test --- src/mlpack/methods/gmm/gmm_train_main.cpp | 6 ++++++ src/mlpack/tests/CMakeLists.txt | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/mlpack/methods/gmm/gmm_train_main.cpp b/src/mlpack/methods/gmm/gmm_train_main.cpp index a01adfcb0e..35c6eb8b8f 100644 --- a/src/mlpack/methods/gmm/gmm_train_main.cpp +++ b/src/mlpack/methods/gmm/gmm_train_main.cpp @@ -144,12 +144,18 @@ static void mlpackMain() "number of Gaussians must be positive"); const int gaussians = CLI::GetParam("gaussians"); + RequireParamValue("trials", [](int x) { return x > 0; }, true, + "trials must be greater than 0"); + ReportIgnoredParam({{ "diagonal_covariance", true }}, "no_force_positive"); RequireAtLeastOnePassed({ "output_model" }, false, "no model will be saved"); RequireParamValue("noise", [](double x) { return x >= 0.0; }, true, "variance of noise must be greater than or equal to 0"); + RequireParamValue("max_iterations", [](int x) { return x >= 0; }, true, + "max_iterations must be greater than or equal to 0"); + arma::mat dataPoints = std::move(CLI::GetParam("input")); // Do we need to add noise to the dataset? diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index 8354d3423c..d125c31121 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -120,6 +120,9 @@ add_executable(mlpack_test main_tests/det_test.cpp main_tests/decision_tree_test.cpp main_tests/decision_stump_test.cpp + main_tests/gmm_generate_test.cpp + main_tests/gmm_probability_test.cpp + main_tests/gmm_train_test.cpp main_tests/kde_test.cpp main_tests/linear_regression_test.cpp main_tests/logistic_regression_test.cpp From 8cb1e8940fc7b16057413f8fe653c4a40ad3ec1c Mon Sep 17 00:00:00 2001 From: Yashwant Date: Sun, 19 May 2019 23:01:21 +0530 Subject: [PATCH 02/18] Add GMM CLI test --- .../tests/main_tests/gmm_generate_test.cpp | 98 +++++ .../tests/main_tests/gmm_probability_test.cpp | 73 ++++ .../tests/main_tests/gmm_train_test.cpp | 370 ++++++++++++++++++ 3 files changed, 541 insertions(+) create mode 100644 src/mlpack/tests/main_tests/gmm_generate_test.cpp create mode 100644 src/mlpack/tests/main_tests/gmm_probability_test.cpp create mode 100644 src/mlpack/tests/main_tests/gmm_train_test.cpp diff --git a/src/mlpack/tests/main_tests/gmm_generate_test.cpp b/src/mlpack/tests/main_tests/gmm_generate_test.cpp new file mode 100644 index 0000000000..d49538b497 --- /dev/null +++ b/src/mlpack/tests/main_tests/gmm_generate_test.cpp @@ -0,0 +1,98 @@ +/** + * @file gmm_generate_test.cpp + * @author Yashwant Singh + * + * Test mlpackMain() of gmm_generate_main.cpp. + * + * 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. + */ +#define BINDING_TYPE BINDING_TYPE_TEST +static const std::string testName = "GmmGenerate"; + +#include +#include +#include + +#include "test_helper.hpp" +#include +#include "../test_tools.hpp" + +using namespace mlpack; + +struct GmmGenerateTestFixture +{ + public: + GmmGenerateTestFixture() + { + // Cache in the options for this program. + CLI::RestoreSettings(testName); + } + + ~GmmGenerateTestFixture() + { + // Clear the settings. + CLI::ClearSettings(); + } +}; + +BOOST_FIXTURE_TEST_SUITE(GmmGenerateMainTest, GmmGenerateTestFixture); + +// Checking that Samples must greater than 0. +BOOST_AUTO_TEST_CASE(GmmGenerateSamplesTest) +{ + arma::mat inputData; + if (!data::Load("vc2.csv", inputData)) + BOOST_FAIL("Unable to load train dataset vc2.csv!"); + + GMM gmm(1, 2); + gmm.Train(inputData, 2); + + SetInputParam("input_model", &gmm); + + Log::Fatal.ignoreInput = true; + SetInputParam("samples", 0);// Invalid + BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + Log::Fatal.ignoreInput = false; +} + +// Making sure samples are provided. +BOOST_AUTO_TEST_CASE(GmmGenerateSamples) +{ + arma::mat inputData; + if (!data::Load("vc2.csv", inputData)) + BOOST_FAIL("Unable to load train dataset vc2.csv!"); + + GMM gmm(1, 2); + gmm.Train(inputData, 2); + + SetInputParam("input_model", &gmm); + + Log::Fatal.ignoreInput = true; + BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + Log::Fatal.ignoreInput = false; +} + +// Checking dimensionality of output. +BOOST_AUTO_TEST_CASE(GmmGenerateDimensionality) +{ + arma::mat inputData; + if (!data::Load("vc2.csv", inputData)) + BOOST_FAIL("Unable to load train dataset vc2.csv!"); + + GMM gmm(1, 2); + gmm.Train(inputData,2); + SetInputParam("input_model", &gmm); + SetInputParam("samples", (int) 10); + + mlpackMain(); + + arma::mat output = std::move(CLI::GetParam("output")); + + BOOST_REQUIRE_EQUAL(output.n_rows, gmm.Dimensionality()); + BOOST_REQUIRE_EQUAL(output.n_cols, (int) 10); + } + +BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/main_tests/gmm_probability_test.cpp b/src/mlpack/tests/main_tests/gmm_probability_test.cpp new file mode 100644 index 0000000000..0fb50b1e3d --- /dev/null +++ b/src/mlpack/tests/main_tests/gmm_probability_test.cpp @@ -0,0 +1,73 @@ +/** + * @file gmm_probability_test.cpp + * @author Yashwant Singh + * + * Test mlpackMain() of gmm_probability_main.cpp. + * + * 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. + */ + +#define BINDING_TYPE BINDING_TYPE_TEST + +static const std::string testName = "GmmProbability"; + +#include +#include +#include + +#include "test_helper.hpp" + +#include + + +using namespace mlpack; + +struct GmmProbabilityTestFixture +{ + public: + GmmProbabilityTestFixture() + { + // Cache in the options for this program. + CLI::RestoreSettings(testName); + } + + ~GmmProbabilityTestFixture() + { + // Clear the settings. + CLI::ClearSettings(); + } +}; + +void ResetGmmProbabilitySetting() +{ + CLI::ClearSettings(); + CLI::RestoreSettings(testName); +} + +BOOST_FIXTURE_TEST_SUITE(GmmProbabilityMainTest, GmmProbabilityTestFixture); + +// Checking the input and output dimensionality. +BOOST_AUTO_TEST_CASE(GmmProbabilityDimensionality) +{ + arma::mat inputData; + if (!data::Load("vc2.csv", inputData)) + BOOST_FAIL("Unable to load train dataset vc2.csv!"); + + GMM gmm(1, 2); + gmm.Train(std::move(inputData), 2); + + arma::mat inputPoints(1, 8, arma::fill::randu); + + SetInputParam("input", std::move(inputPoints)); + SetInputParam("input_model", &gmm); + + mlpackMain(); + + BOOST_REQUIRE_EQUAL(CLI::GetParam("output").n_cols,8); + BOOST_REQUIRE_EQUAL(CLI::GetParam("output").n_rows,1); +} + +BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp new file mode 100644 index 0000000000..6b4a455269 --- /dev/null +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -0,0 +1,370 @@ +/** + * @file gmm_train_test.cpp + * @author Yashwant Singh + * + * Test mlpackMain() of gmm_train_main.cpp. + * + * 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. + */ +#include + +#define BINDING_TYPE BINDING_TYPE_TEST +static const std::string testName = "GmmTrain"; + +#include +#include +#include "test_helper.hpp" +#include + +#include +#include "../test_tools.hpp" + +using namespace mlpack; + +struct GmmTrainTestFixture +{ +public: + GmmTrainTestFixture() + { + // Cache in the options for this program. + CLI::RestoreSettings(testName); + } + + ~GmmTrainTestFixture() + { + // Clear the settings. + bindings::tests::CleanMemory(); + CLI::ClearSettings(); + } +}; + +void ResetGmmTrainSetting() +{ + CLI::ClearSettings(); + CLI::RestoreSettings(testName); +} + +BOOST_FIXTURE_TEST_SUITE(GmmTrainMainTest, GmmTrainTestFixture); + +// To check if the gaussian is positive or not. +BOOST_AUTO_TEST_CASE(GmmTrainValidGaussianTest) +{ + arma::mat inputData(5, 10, arma::fill::randu); + + SetInputParam("input", std::move(inputData)); + SetInputParam("gaussians", 0);// Invalid + + Log::Fatal.ignoreInput = true; + BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + Log::Fatal.ignoreInput = false; +} + +/** + * To check if the number of gaussians in the output model is same as + * that of input gaussian parameter or not. + **/ +BOOST_AUTO_TEST_CASE(GmmTrainOutputModelGaussianTest) +{ + arma::mat inputData(5, 10, arma::fill::randu); + + SetInputParam("input", std::move(inputData)); + SetInputParam("gaussians", (int) 2); + SetInputParam("trials", (int) 2); + + mlpackMain(); + + GMM* gmm = CLI::GetParam("output_model"); + BOOST_REQUIRE_EQUAL(gmm->Gaussians(), (int) 2); +} + +// Max iterations must be positive. +BOOST_AUTO_TEST_CASE(GmmTrainMaxIterationsTest) +{ + arma::mat inputData(5, 10, arma::fill::randu); + + SetInputParam("input", std::move(inputData)); + SetInputParam("gaussians", (int) 2); + SetInputParam("trials", (int) 1); + SetInputParam("max_iterations", (int)-1);// Invalid. + + Log::Fatal.ignoreInput = true; + BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + Log::Fatal.ignoreInput = false; +} + +// Ensure that Trials must be greater than 0. +BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) +{ + arma::mat inputData(5, 10, arma::fill::randu); + + SetInputParam("input", std::move(inputData)); + SetInputParam("gaussians", (int) 2); + SetInputParam("trials", (int) 0);// Invalid. + + Log::Fatal.ignoreInput = true; + BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + Log::Fatal.ignoreInput = false; +} + +// Checking that percentage is between 0 and 1. +BOOST_AUTO_TEST_CASE(RefinedStartPercentageTest) +{ + arma::mat inputData(5, 10, arma::fill::randu); + + SetInputParam("input", std::move(inputData)); + SetInputParam("refined_start", true); + + Log::Fatal.ignoreInput = true; + SetInputParam("percentage", (double) 2.0);// Invalid + BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + + SetInputParam("percentage", (double) -1.0);// Invalid + BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + + Log::Fatal.ignoreInput = false; +} + +// Samplings must be positive. +BOOST_AUTO_TEST_CASE(GmmTrainSamplings) +{ + arma::mat inputData(5, 10, arma::fill::randu); + + SetInputParam("input", std::move(inputData)); + SetInputParam("refined_start", true); + SetInputParam("samplings", (int) 0);// Invalid + + Log::Fatal.ignoreInput = true; + BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + Log::Fatal.ignoreInput = false; +} + +// Number of gaussians in the model trained from input model. +BOOST_AUTO_TEST_CASE(GmmTrainNumberOfGaussian) +{ + arma::mat inputData(5, 10, arma::fill::randu); + + SetInputParam("input", inputData); + SetInputParam("gaussians", (int) 2); + + mlpackMain(); + + GMM* gmm = CLI::GetParam("output_model"); + + SetInputParam("input_model", gmm); + + CLI::GetSingleton().Parameters()["input"].wasPassed = false; + + SetInputParam("input", std::move(inputData)); + + mlpackMain(); + + GMM* gmm1 = CLI::GetParam("output_model"); + + BOOST_REQUIRE_EQUAL(gmm1->Gaussians(), (int) 2); +} + +// Ensure that Noise affects the final result. +BOOST_AUTO_TEST_CASE(GmmTrainNoisetest) +{ + arma::mat inputData(5, 10, arma::fill::randu); + + SetInputParam("input", inputData); + SetInputParam("gaussians", (int) 2); + SetInputParam("noise", (double) 0.0); + + mlpackMain(); + + GMM* gmm = CLI::GetParam("output_model"); + + CLI::GetSingleton().Parameters()["input"].wasPassed = false; + CLI::GetSingleton().Parameters()["gaussians"].wasPassed = false; + CLI::GetSingleton().Parameters()["noise"].wasPassed = false; + + SetInputParam("input", std::move(inputData)); + SetInputParam("gaussians", (int) 2); + SetInputParam("noise", (double) 1.5); + mlpackMain(); + + GMM* gmm1 = CLI::GetParam("output_model"); + + arma::uvec sortedIndices = sort_index(gmm->Weights()); + + for(size_t k = 0; k < sortedIndices.n_elem; k++) + CheckMatricesNotEqual(gmm->Component(sortedIndices[k]).Covariance(), + gmm1->Component(sortedIndices[k]).Covariance()); + +} + +// Ensure that Percentage affects the final result when refined_start is true. +BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) +{ + arma::mat inputData(5, 10, arma::fill::randu); + + SetInputParam("input", inputData); + SetInputParam("gaussians", (int) 2); + SetInputParam("refined_start", true); + SetInputParam("percentage", (double) 0.02); + + mlpackMain(); + + GMM* gmm = CLI::GetParam("output_model"); + + CLI::GetSingleton().Parameters()["input"].wasPassed = false; + CLI::GetSingleton().Parameters()["gaussians"].wasPassed = false; + CLI::GetSingleton().Parameters()["refined_start"].wasPassed = false; + CLI::GetSingleton().Parameters()["percentage"].wasPassed = false; + + SetInputParam("input", std::move(inputData)); + SetInputParam("gaussians", (int) 2); + SetInputParam("refined_start", true); + SetInputParam("percentage", (double) 0.52); + + mlpackMain(); + + GMM* gmm1 = CLI::GetParam("output_model"); + + arma::uvec sortedIndices = sort_index(gmm->Weights()); + + for(size_t k = 0; k < sortedIndices.n_elem; k++) + CheckMatricesNotEqual(gmm->Component(sortedIndices[k]).Covariance(), + gmm1->Component(sortedIndices[k]).Covariance()); +} + +// Ensure that Sampling affects the final result when refined_start is true. +BOOST_AUTO_TEST_CASE(GmmTrainSamplingsTest) +{ + arma::mat inputData(5, 10, arma::fill::randu); + + SetInputParam("input", inputData); + SetInputParam("gaussians", (int) 2); + SetInputParam("refined_start", true); + SetInputParam("percentage", (double) 0.5); + SetInputParam("samplings", (int) 100); + + mlpackMain(); + + GMM* gmm = CLI::GetParam("output_model"); + + CLI::GetSingleton().Parameters()["input"].wasPassed = false; + CLI::GetSingleton().Parameters()["gaussians"].wasPassed = false; + CLI::GetSingleton().Parameters()["refined_start"].wasPassed = false; + CLI::GetSingleton().Parameters()["percentage"].wasPassed = false; + CLI::GetSingleton().Parameters()["samplings"].wasPassed = false; + + SetInputParam("input", std::move(inputData)); + SetInputParam("gaussians", (int) 2); + SetInputParam("refined_start", true); + SetInputParam("percentage", (double) 0.5); + SetInputParam("samplings", (int) 500); + + mlpackMain(); + + GMM* gmm1 = CLI::GetParam("output_model"); + + arma::uvec sortedIndices = sort_index(gmm->Weights()); + + for(size_t k = 0; k < sortedIndices.n_elem; k++) + CheckMatricesNotEqual(gmm->Component(sortedIndices[k]).Covariance(), + gmm1->Component(sortedIndices[k]).Covariance()); + +} + +// Ensure that tolerance affects the final result. +BOOST_AUTO_TEST_CASE(GmmTrainToleranceTest) +{ + arma::mat inputData; + if (!data::Load("vc2.csv", inputData)) + BOOST_FAIL("Unable to load train dataset vc2.csv!"); + + SetInputParam("input", inputData); + SetInputParam("gaussians", (int) 2); + SetInputParam("tolerance", (double) 1e-10); + + mlpackMain(); + + GMM* gmm = CLI::GetParam("output_model"); + + CLI::GetSingleton().Parameters()["input"].wasPassed = false; + CLI::GetSingleton().Parameters()["gaussians"].wasPassed = false; + CLI::GetSingleton().Parameters()["tolerance"].wasPassed = false; + + SetInputParam("input", std::move(inputData)); + SetInputParam("gaussians", (int) 2); + SetInputParam("tolerance", (double) 1e-30); + + mlpackMain(); + + GMM* gmm1 = CLI::GetParam("output_model"); + + arma::uvec sortedIndices = sort_index(gmm->Weights()); + + for(size_t k = 0; k < sortedIndices.n_elem; k++) + CheckMatricesNotEqual(gmm->Component(sortedIndices[k]).Covariance(), + gmm1->Component(sortedIndices[k]).Covariance()); +} + +// Ensure that saved model can be used again. +BOOST_AUTO_TEST_CASE(GmmTrainModelReuseTest) +{ + arma::mat inputData(5, 10, arma::fill::randu); + + SetInputParam("input", inputData); + SetInputParam("gaussians", (int) 2); + + mlpackMain(); + + GMM* gmm = CLI::GetParam("output_model"); + + SetInputParam("input_model", gmm); + + CLI::GetSingleton().Parameters()["input"].wasPassed = false; + + SetInputParam("input", inputData); + + mlpackMain(); + + GMM* gmm1 = CLI::GetParam("output_model"); + + SetInputParam("input_model", gmm1); + + CLI::GetSingleton().Parameters()["input"].wasPassed = false; + + SetInputParam("input", std::move(inputData)); + + mlpackMain(); + + GMM* gmm2 = CLI::GetParam("output_model"); + + BOOST_REQUIRE_EQUAL(gmm1, gmm2); +} + +// Ensure that Gmm's covariances are diagonal when diagonal_covariance is true. +BOOST_AUTO_TEST_CASE(GmmTrainDiagCovariance) +{ + arma::mat inputData(5, 10, arma::fill::randu); + + SetInputParam("input", std::move(inputData)); + SetInputParam("gaussians", (int) 2); + SetInputParam("diagonal_covariance", true); + + mlpackMain(); + + GMM* gmm = CLI::GetParam("output_model"); + + arma::uvec sortedIndices = sort_index(gmm->Weights()); + + for(size_t k = 0; k < sortedIndices.n_elem; k++) + { + arma::mat diagCov(gmm->Component(sortedIndices[k]).Covariance()); + for(size_t i = 0; i < diagCov.n_rows; i++) + for(size_t j = 0; j < diagCov.n_cols; j++) + if (i != j && diagCov(i, j) != (double) 0) + BOOST_FAIL("Covariance Are Not Diagonal"); + } +} + +BOOST_AUTO_TEST_SUITE_END(); + From 45ee51470895d48806929d9a96ce7085426d8f46 Mon Sep 17 00:00:00 2001 From: Yashwant Date: Sun, 19 May 2019 23:27:45 +0530 Subject: [PATCH 03/18] Fix Style Checks --- .../tests/main_tests/gmm_generate_test.cpp | 34 ++++---- .../tests/main_tests/gmm_probability_test.cpp | 28 +++---- .../tests/main_tests/gmm_train_test.cpp | 81 +++++++++---------- 3 files changed, 71 insertions(+), 72 deletions(-) diff --git a/src/mlpack/tests/main_tests/gmm_generate_test.cpp b/src/mlpack/tests/main_tests/gmm_generate_test.cpp index d49538b497..9139549857 100644 --- a/src/mlpack/tests/main_tests/gmm_generate_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_generate_test.cpp @@ -25,17 +25,17 @@ using namespace mlpack; struct GmmGenerateTestFixture { public: - GmmGenerateTestFixture() - { - // Cache in the options for this program. - CLI::RestoreSettings(testName); - } + GmmGenerateTestFixture() + { + // Cache in the options for this program. + CLI::RestoreSettings(testName); + } - ~GmmGenerateTestFixture() - { - // Clear the settings. - CLI::ClearSettings(); - } + ~GmmGenerateTestFixture() + { + // Clear the settings. + CLI::ClearSettings(); + } }; BOOST_FIXTURE_TEST_SUITE(GmmGenerateMainTest, GmmGenerateTestFixture); @@ -46,14 +46,14 @@ BOOST_AUTO_TEST_CASE(GmmGenerateSamplesTest) arma::mat inputData; if (!data::Load("vc2.csv", inputData)) BOOST_FAIL("Unable to load train dataset vc2.csv!"); - + GMM gmm(1, 2); gmm.Train(inputData, 2); SetInputParam("input_model", &gmm); Log::Fatal.ignoreInput = true; - SetInputParam("samples", 0);// Invalid + SetInputParam("samples", 0); // Invalid BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; } @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(GmmGenerateSamples) arma::mat inputData; if (!data::Load("vc2.csv", inputData)) BOOST_FAIL("Unable to load train dataset vc2.csv!"); - + GMM gmm(1, 2); gmm.Train(inputData, 2); @@ -77,13 +77,13 @@ BOOST_AUTO_TEST_CASE(GmmGenerateSamples) // Checking dimensionality of output. BOOST_AUTO_TEST_CASE(GmmGenerateDimensionality) -{ +{ arma::mat inputData; if (!data::Load("vc2.csv", inputData)) BOOST_FAIL("Unable to load train dataset vc2.csv!"); - + GMM gmm(1, 2); - gmm.Train(inputData,2); + gmm.Train(inputData, 2); SetInputParam("input_model", &gmm); SetInputParam("samples", (int) 10); @@ -93,6 +93,6 @@ BOOST_AUTO_TEST_CASE(GmmGenerateDimensionality) BOOST_REQUIRE_EQUAL(output.n_rows, gmm.Dimensionality()); BOOST_REQUIRE_EQUAL(output.n_cols, (int) 10); - } +} BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/main_tests/gmm_probability_test.cpp b/src/mlpack/tests/main_tests/gmm_probability_test.cpp index 0fb50b1e3d..4219a372cf 100644 --- a/src/mlpack/tests/main_tests/gmm_probability_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_probability_test.cpp @@ -9,7 +9,7 @@ * 3-clause BSD license along with mlpack. If not, see * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ - + #define BINDING_TYPE BINDING_TYPE_TEST static const std::string testName = "GmmProbability"; @@ -28,17 +28,17 @@ using namespace mlpack; struct GmmProbabilityTestFixture { public: - GmmProbabilityTestFixture() - { - // Cache in the options for this program. - CLI::RestoreSettings(testName); - } + GmmProbabilityTestFixture() + { + // Cache in the options for this program. + CLI::RestoreSettings(testName); + } - ~GmmProbabilityTestFixture() - { - // Clear the settings. - CLI::ClearSettings(); - } + ~GmmProbabilityTestFixture() + { + // Clear the settings. + CLI::ClearSettings(); + } }; void ResetGmmProbabilitySetting() @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(GmmProbabilityDimensionality) arma::mat inputData; if (!data::Load("vc2.csv", inputData)) BOOST_FAIL("Unable to load train dataset vc2.csv!"); - + GMM gmm(1, 2); gmm.Train(std::move(inputData), 2); @@ -66,8 +66,8 @@ BOOST_AUTO_TEST_CASE(GmmProbabilityDimensionality) mlpackMain(); - BOOST_REQUIRE_EQUAL(CLI::GetParam("output").n_cols,8); - BOOST_REQUIRE_EQUAL(CLI::GetParam("output").n_rows,1); + BOOST_REQUIRE_EQUAL(CLI::GetParam("output").n_cols, 8); + BOOST_REQUIRE_EQUAL(CLI::GetParam("output").n_rows, 1); } BOOST_AUTO_TEST_SUITE_END(); diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index 6b4a455269..93049763ba 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -26,19 +26,19 @@ using namespace mlpack; struct GmmTrainTestFixture { -public: - GmmTrainTestFixture() - { - // Cache in the options for this program. - CLI::RestoreSettings(testName); - } + public: + GmmTrainTestFixture() + { + // Cache in the options for this program. + CLI::RestoreSettings(testName); + } - ~GmmTrainTestFixture() - { - // Clear the settings. - bindings::tests::CleanMemory(); - CLI::ClearSettings(); - } + ~GmmTrainTestFixture() + { + // Clear the settings. + bindings::tests::CleanMemory(); + CLI::ClearSettings(); + } }; void ResetGmmTrainSetting() @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainValidGaussianTest) arma::mat inputData(5, 10, arma::fill::randu); SetInputParam("input", std::move(inputData)); - SetInputParam("gaussians", 0);// Invalid + SetInputParam("gaussians", 0); // Invalid Log::Fatal.ignoreInput = true; BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); @@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainOutputModelGaussianTest) SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); SetInputParam("trials", (int) 2); - + mlpackMain(); GMM* gmm = CLI::GetParam("output_model"); @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainMaxIterationsTest) SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); SetInputParam("trials", (int) 1); - SetInputParam("max_iterations", (int)-1);// Invalid. + SetInputParam("max_iterations", (int)-1); // Invalid. Log::Fatal.ignoreInput = true; BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); @@ -102,8 +102,8 @@ BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); - SetInputParam("trials", (int) 0);// Invalid. - + SetInputParam("trials", (int) 0); // Invalid. + Log::Fatal.ignoreInput = true; BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; @@ -118,10 +118,10 @@ BOOST_AUTO_TEST_CASE(RefinedStartPercentageTest) SetInputParam("refined_start", true); Log::Fatal.ignoreInput = true; - SetInputParam("percentage", (double) 2.0);// Invalid + SetInputParam("percentage", (double) 2.0); // Invalid BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); - SetInputParam("percentage", (double) -1.0);// Invalid + SetInputParam("percentage", (double) -1.0); // Invalid BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); Log::Fatal.ignoreInput = false; @@ -134,7 +134,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainSamplings) SetInputParam("input", std::move(inputData)); SetInputParam("refined_start", true); - SetInputParam("samplings", (int) 0);// Invalid + SetInputParam("samplings", (int) 0); // Invalid Log::Fatal.ignoreInput = true; BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); @@ -150,7 +150,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainNumberOfGaussian) SetInputParam("gaussians", (int) 2); mlpackMain(); - + GMM* gmm = CLI::GetParam("output_model"); SetInputParam("input_model", gmm); @@ -176,13 +176,13 @@ BOOST_AUTO_TEST_CASE(GmmTrainNoisetest) SetInputParam("noise", (double) 0.0); mlpackMain(); - + GMM* gmm = CLI::GetParam("output_model"); CLI::GetSingleton().Parameters()["input"].wasPassed = false; CLI::GetSingleton().Parameters()["gaussians"].wasPassed = false; CLI::GetSingleton().Parameters()["noise"].wasPassed = false; - + SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); SetInputParam("noise", (double) 1.5); @@ -191,11 +191,10 @@ BOOST_AUTO_TEST_CASE(GmmTrainNoisetest) GMM* gmm1 = CLI::GetParam("output_model"); arma::uvec sortedIndices = sort_index(gmm->Weights()); - - for(size_t k = 0; k < sortedIndices.n_elem; k++) + + for (size_t k = 0; k < sortedIndices.n_elem; k++) CheckMatricesNotEqual(gmm->Component(sortedIndices[k]).Covariance(), gmm1->Component(sortedIndices[k]).Covariance()); - } // Ensure that Percentage affects the final result when refined_start is true. @@ -209,7 +208,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) SetInputParam("percentage", (double) 0.02); mlpackMain(); - + GMM* gmm = CLI::GetParam("output_model"); CLI::GetSingleton().Parameters()["input"].wasPassed = false; @@ -227,8 +226,8 @@ BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) GMM* gmm1 = CLI::GetParam("output_model"); arma::uvec sortedIndices = sort_index(gmm->Weights()); - - for(size_t k = 0; k < sortedIndices.n_elem; k++) + + for (size_t k = 0; k < sortedIndices.n_elem; k++) CheckMatricesNotEqual(gmm->Component(sortedIndices[k]).Covariance(), gmm1->Component(sortedIndices[k]).Covariance()); } @@ -245,7 +244,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainSamplingsTest) SetInputParam("samplings", (int) 100); mlpackMain(); - + GMM* gmm = CLI::GetParam("output_model"); CLI::GetSingleton().Parameters()["input"].wasPassed = false; @@ -265,8 +264,8 @@ BOOST_AUTO_TEST_CASE(GmmTrainSamplingsTest) GMM* gmm1 = CLI::GetParam("output_model"); arma::uvec sortedIndices = sort_index(gmm->Weights()); - - for(size_t k = 0; k < sortedIndices.n_elem; k++) + + for (size_t k = 0; k < sortedIndices.n_elem; k++) CheckMatricesNotEqual(gmm->Component(sortedIndices[k]).Covariance(), gmm1->Component(sortedIndices[k]).Covariance()); @@ -284,7 +283,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainToleranceTest) SetInputParam("tolerance", (double) 1e-10); mlpackMain(); - + GMM* gmm = CLI::GetParam("output_model"); CLI::GetSingleton().Parameters()["input"].wasPassed = false; @@ -300,8 +299,8 @@ BOOST_AUTO_TEST_CASE(GmmTrainToleranceTest) GMM* gmm1 = CLI::GetParam("output_model"); arma::uvec sortedIndices = sort_index(gmm->Weights()); - - for(size_t k = 0; k < sortedIndices.n_elem; k++) + + for (size_t k = 0; k < sortedIndices.n_elem; k++) CheckMatricesNotEqual(gmm->Component(sortedIndices[k]).Covariance(), gmm1->Component(sortedIndices[k]).Covariance()); } @@ -315,7 +314,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainModelReuseTest) SetInputParam("gaussians", (int) 2); mlpackMain(); - + GMM* gmm = CLI::GetParam("output_model"); SetInputParam("input_model", gmm); @@ -327,7 +326,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainModelReuseTest) mlpackMain(); GMM* gmm1 = CLI::GetParam("output_model"); - + SetInputParam("input_model", gmm1); CLI::GetSingleton().Parameters()["input"].wasPassed = false; @@ -351,16 +350,16 @@ BOOST_AUTO_TEST_CASE(GmmTrainDiagCovariance) SetInputParam("diagonal_covariance", true); mlpackMain(); - + GMM* gmm = CLI::GetParam("output_model"); arma::uvec sortedIndices = sort_index(gmm->Weights()); - for(size_t k = 0; k < sortedIndices.n_elem; k++) + for (size_t k = 0; k < sortedIndices.n_elem; k++) { arma::mat diagCov(gmm->Component(sortedIndices[k]).Covariance()); - for(size_t i = 0; i < diagCov.n_rows; i++) - for(size_t j = 0; j < diagCov.n_cols; j++) + for (size_t i = 0; i < diagCov.n_rows; i++) + for (size_t j = 0; j < diagCov.n_cols; j++) if (i != j && diagCov(i, j) != (double) 0) BOOST_FAIL("Covariance Are Not Diagonal"); } From 25c531577795507034cc334e4d1ebfa81922e62b Mon Sep 17 00:00:00 2001 From: Yashwant Date: Mon, 27 May 2019 08:06:55 +0530 Subject: [PATCH 04/18] Fix Style Checksx --- src/mlpack/tests/main_tests/gmm_generate_test.cpp | 15 +++++---------- .../tests/main_tests/gmm_probability_test.cpp | 7 +++---- src/mlpack/tests/main_tests/gmm_train_test.cpp | 6 +++--- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/mlpack/tests/main_tests/gmm_generate_test.cpp b/src/mlpack/tests/main_tests/gmm_generate_test.cpp index 9139549857..1d725a28e6 100644 --- a/src/mlpack/tests/main_tests/gmm_generate_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_generate_test.cpp @@ -24,7 +24,7 @@ using namespace mlpack; struct GmmGenerateTestFixture { - public: + public: GmmGenerateTestFixture() { // Cache in the options for this program. @@ -43,9 +43,7 @@ BOOST_FIXTURE_TEST_SUITE(GmmGenerateMainTest, GmmGenerateTestFixture); // Checking that Samples must greater than 0. BOOST_AUTO_TEST_CASE(GmmGenerateSamplesTest) { - arma::mat inputData; - if (!data::Load("vc2.csv", inputData)) - BOOST_FAIL("Unable to load train dataset vc2.csv!"); + arma::mat inputData(5, 10, arma::fill::randu); GMM gmm(1, 2); gmm.Train(inputData, 2); @@ -61,9 +59,7 @@ BOOST_AUTO_TEST_CASE(GmmGenerateSamplesTest) // Making sure samples are provided. BOOST_AUTO_TEST_CASE(GmmGenerateSamples) { - arma::mat inputData; - if (!data::Load("vc2.csv", inputData)) - BOOST_FAIL("Unable to load train dataset vc2.csv!"); + arma::mat inputData(5, 10, arma::fill::randu); GMM gmm(1, 2); gmm.Train(inputData, 2); @@ -78,9 +74,7 @@ BOOST_AUTO_TEST_CASE(GmmGenerateSamples) // Checking dimensionality of output. BOOST_AUTO_TEST_CASE(GmmGenerateDimensionality) { - arma::mat inputData; - if (!data::Load("vc2.csv", inputData)) - BOOST_FAIL("Unable to load train dataset vc2.csv!"); + arma::mat inputData(5, 10, arma::fill::randu); GMM gmm(1, 2); gmm.Train(inputData, 2); @@ -96,3 +90,4 @@ BOOST_AUTO_TEST_CASE(GmmGenerateDimensionality) } BOOST_AUTO_TEST_SUITE_END(); + diff --git a/src/mlpack/tests/main_tests/gmm_probability_test.cpp b/src/mlpack/tests/main_tests/gmm_probability_test.cpp index 4219a372cf..f945ea134b 100644 --- a/src/mlpack/tests/main_tests/gmm_probability_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_probability_test.cpp @@ -27,7 +27,7 @@ using namespace mlpack; struct GmmProbabilityTestFixture { - public: + public: GmmProbabilityTestFixture() { // Cache in the options for this program. @@ -52,9 +52,7 @@ BOOST_FIXTURE_TEST_SUITE(GmmProbabilityMainTest, GmmProbabilityTestFixture); // Checking the input and output dimensionality. BOOST_AUTO_TEST_CASE(GmmProbabilityDimensionality) { - arma::mat inputData; - if (!data::Load("vc2.csv", inputData)) - BOOST_FAIL("Unable to load train dataset vc2.csv!"); + arma::mat inputData(5, 10, arma::fill::randu); GMM gmm(1, 2); gmm.Train(std::move(inputData), 2); @@ -71,3 +69,4 @@ BOOST_AUTO_TEST_CASE(GmmProbabilityDimensionality) } BOOST_AUTO_TEST_SUITE_END(); + diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index 93049763ba..85074fdc62 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -26,7 +26,7 @@ using namespace mlpack; struct GmmTrainTestFixture { - public: + public: GmmTrainTestFixture() { // Cache in the options for this program. @@ -205,7 +205,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) SetInputParam("input", inputData); SetInputParam("gaussians", (int) 2); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.02); + SetInputParam("percentage", (double) 0.22); mlpackMain(); @@ -219,7 +219,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.52); + SetInputParam("percentage", (double) 0.82); mlpackMain(); From 4b0a41fa64848144c66e8a55f3bc1f565727dbf6 Mon Sep 17 00:00:00 2001 From: Yashwant Date: Fri, 31 May 2019 16:05:57 +0530 Subject: [PATCH 05/18] Resolve Tests --- .../tests/main_tests/gmm_generate_test.cpp | 12 +-- .../tests/main_tests/gmm_probability_test.cpp | 4 +- .../tests/main_tests/gmm_train_test.cpp | 74 ++++++++++--------- 3 files changed, 49 insertions(+), 41 deletions(-) diff --git a/src/mlpack/tests/main_tests/gmm_generate_test.cpp b/src/mlpack/tests/main_tests/gmm_generate_test.cpp index 1d725a28e6..494b99097d 100644 --- a/src/mlpack/tests/main_tests/gmm_generate_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_generate_test.cpp @@ -45,8 +45,8 @@ BOOST_AUTO_TEST_CASE(GmmGenerateSamplesTest) { arma::mat inputData(5, 10, arma::fill::randu); - GMM gmm(1, 2); - gmm.Train(inputData, 2); + GMM gmm(1, 5); + gmm.Train(inputData, 5); SetInputParam("input_model", &gmm); @@ -61,8 +61,8 @@ BOOST_AUTO_TEST_CASE(GmmGenerateSamples) { arma::mat inputData(5, 10, arma::fill::randu); - GMM gmm(1, 2); - gmm.Train(inputData, 2); + GMM gmm(1, 5); + gmm.Train(inputData, 5); SetInputParam("input_model", &gmm); @@ -76,8 +76,8 @@ BOOST_AUTO_TEST_CASE(GmmGenerateDimensionality) { arma::mat inputData(5, 10, arma::fill::randu); - GMM gmm(1, 2); - gmm.Train(inputData, 2); + GMM gmm(1, 5); + gmm.Train(inputData, 5); SetInputParam("input_model", &gmm); SetInputParam("samples", (int) 10); diff --git a/src/mlpack/tests/main_tests/gmm_probability_test.cpp b/src/mlpack/tests/main_tests/gmm_probability_test.cpp index f945ea134b..17d5a8f983 100644 --- a/src/mlpack/tests/main_tests/gmm_probability_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_probability_test.cpp @@ -54,8 +54,8 @@ BOOST_AUTO_TEST_CASE(GmmProbabilityDimensionality) { arma::mat inputData(5, 10, arma::fill::randu); - GMM gmm(1, 2); - gmm.Train(std::move(inputData), 2); + GMM gmm(1, 5); + gmm.Train(std::move(inputData), 5); arma::mat inputPoints(1, 8, arma::fill::randu); diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index 85074fdc62..2a9d1672a4 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -47,6 +47,7 @@ void ResetGmmTrainSetting() CLI::RestoreSettings(testName); } + BOOST_FIXTURE_TEST_SUITE(GmmTrainMainTest, GmmTrainTestFixture); // To check if the gaussian is positive or not. @@ -175,17 +176,18 @@ BOOST_AUTO_TEST_CASE(GmmTrainNoisetest) SetInputParam("gaussians", (int) 2); SetInputParam("noise", (double) 0.0); + mlpack::math::FixedRandomSeed(); mlpackMain(); GMM* gmm = CLI::GetParam("output_model"); - CLI::GetSingleton().Parameters()["input"].wasPassed = false; - CLI::GetSingleton().Parameters()["gaussians"].wasPassed = false; - CLI::GetSingleton().Parameters()["noise"].wasPassed = false; + ResetGmmTrainSetting(); SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); - SetInputParam("noise", (double) 1.5); + SetInputParam("noise", (double) 100.0); + + mlpack::math::FixedRandomSeed(); mlpackMain(); GMM* gmm1 = CLI::GetParam("output_model"); @@ -193,8 +195,10 @@ BOOST_AUTO_TEST_CASE(GmmTrainNoisetest) arma::uvec sortedIndices = sort_index(gmm->Weights()); for (size_t k = 0; k < sortedIndices.n_elem; k++) - CheckMatricesNotEqual(gmm->Component(sortedIndices[k]).Covariance(), - gmm1->Component(sortedIndices[k]).Covariance()); + BOOST_REQUIRE(arma::norm(gmm->Component(sortedIndices[k]).Mean() - + gmm1->Component(sortedIndices[k]).Mean()) > 1e-50 || + arma::norm(gmm->Component(sortedIndices[k]).Covariance() - + gmm1->Component(sortedIndices[k]).Covariance()) > 1e-50); } // Ensure that Percentage affects the final result when refined_start is true. @@ -205,22 +209,23 @@ BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) SetInputParam("input", inputData); SetInputParam("gaussians", (int) 2); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.22); + SetInputParam("percentage", (double) 0.01); + SetInputParam("samplings", (int) 200); + mlpack::math::FixedRandomSeed(); mlpackMain(); GMM* gmm = CLI::GetParam("output_model"); - CLI::GetSingleton().Parameters()["input"].wasPassed = false; - CLI::GetSingleton().Parameters()["gaussians"].wasPassed = false; - CLI::GetSingleton().Parameters()["refined_start"].wasPassed = false; - CLI::GetSingleton().Parameters()["percentage"].wasPassed = false; + ResetGmmTrainSetting(); SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.82); + SetInputParam("percentage", (double) 0.99); + SetInputParam("samplings", (int) 200); + mlpack::math::FixedRandomSeed(); mlpackMain(); GMM* gmm1 = CLI::GetParam("output_model"); @@ -228,8 +233,10 @@ BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) arma::uvec sortedIndices = sort_index(gmm->Weights()); for (size_t k = 0; k < sortedIndices.n_elem; k++) - CheckMatricesNotEqual(gmm->Component(sortedIndices[k]).Covariance(), - gmm1->Component(sortedIndices[k]).Covariance()); + BOOST_REQUIRE(arma::norm(gmm->Component(sortedIndices[k]).Mean() - + gmm1->Component(sortedIndices[k]).Mean()) > 1e-50 || + arma::norm(gmm->Component(sortedIndices[k]).Covariance() - + gmm1->Component(sortedIndices[k]).Covariance()) > 1e-50); } // Ensure that Sampling affects the final result when refined_start is true. @@ -240,25 +247,23 @@ BOOST_AUTO_TEST_CASE(GmmTrainSamplingsTest) SetInputParam("input", inputData); SetInputParam("gaussians", (int) 2); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.5); - SetInputParam("samplings", (int) 100); + SetInputParam("percentage", (double) 0.950); + SetInputParam("samplings", (int) 10); + mlpack::math::FixedRandomSeed(); mlpackMain(); GMM* gmm = CLI::GetParam("output_model"); - CLI::GetSingleton().Parameters()["input"].wasPassed = false; - CLI::GetSingleton().Parameters()["gaussians"].wasPassed = false; - CLI::GetSingleton().Parameters()["refined_start"].wasPassed = false; - CLI::GetSingleton().Parameters()["percentage"].wasPassed = false; - CLI::GetSingleton().Parameters()["samplings"].wasPassed = false; + ResetGmmTrainSetting(); SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.5); - SetInputParam("samplings", (int) 500); + SetInputParam("percentage", (double) 0.950); + SetInputParam("samplings", (int) 1000); + mlpack::math::FixedRandomSeed(); mlpackMain(); GMM* gmm1 = CLI::GetParam("output_model"); @@ -266,9 +271,10 @@ BOOST_AUTO_TEST_CASE(GmmTrainSamplingsTest) arma::uvec sortedIndices = sort_index(gmm->Weights()); for (size_t k = 0; k < sortedIndices.n_elem; k++) - CheckMatricesNotEqual(gmm->Component(sortedIndices[k]).Covariance(), - gmm1->Component(sortedIndices[k]).Covariance()); - + BOOST_REQUIRE(arma::norm(gmm->Component(sortedIndices[k]).Mean() - + gmm1->Component(sortedIndices[k]).Mean()) > 1e-50 || + arma::norm(gmm->Component(sortedIndices[k]).Covariance() - + gmm1->Component(sortedIndices[k]).Covariance()) > 1e-50); } // Ensure that tolerance affects the final result. @@ -280,20 +286,20 @@ BOOST_AUTO_TEST_CASE(GmmTrainToleranceTest) SetInputParam("input", inputData); SetInputParam("gaussians", (int) 2); - SetInputParam("tolerance", (double) 1e-10); + SetInputParam("tolerance", (double) 1e-8); + mlpack::math::FixedRandomSeed(); mlpackMain(); GMM* gmm = CLI::GetParam("output_model"); - CLI::GetSingleton().Parameters()["input"].wasPassed = false; - CLI::GetSingleton().Parameters()["gaussians"].wasPassed = false; - CLI::GetSingleton().Parameters()["tolerance"].wasPassed = false; + ResetGmmTrainSetting(); SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); - SetInputParam("tolerance", (double) 1e-30); + SetInputParam("tolerance", (double) 10); + mlpack::math::FixedRandomSeed(); mlpackMain(); GMM* gmm1 = CLI::GetParam("output_model"); @@ -301,8 +307,10 @@ BOOST_AUTO_TEST_CASE(GmmTrainToleranceTest) arma::uvec sortedIndices = sort_index(gmm->Weights()); for (size_t k = 0; k < sortedIndices.n_elem; k++) - CheckMatricesNotEqual(gmm->Component(sortedIndices[k]).Covariance(), - gmm1->Component(sortedIndices[k]).Covariance()); + BOOST_REQUIRE(arma::norm(gmm->Component(sortedIndices[k]).Mean() - + gmm1->Component(sortedIndices[k]).Mean()) > 1e-50 || + arma::norm(gmm->Component(sortedIndices[k]).Covariance() - + gmm1->Component(sortedIndices[k]).Covariance()) > 1e-50); } // Ensure that saved model can be used again. From 5084c903bee04b60515754c4cdaae3685d9d91ab Mon Sep 17 00:00:00 2001 From: Yashwant Date: Thu, 6 Jun 2019 20:08:18 +0530 Subject: [PATCH 06/18] Add more Test --- .../tests/main_tests/gmm_generate_test.cpp | 15 -- .../tests/main_tests/gmm_probability_test.cpp | 19 ++- .../tests/main_tests/gmm_train_test.cpp | 153 +++++++++++++++--- 3 files changed, 149 insertions(+), 38 deletions(-) diff --git a/src/mlpack/tests/main_tests/gmm_generate_test.cpp b/src/mlpack/tests/main_tests/gmm_generate_test.cpp index 494b99097d..0063c17aeb 100644 --- a/src/mlpack/tests/main_tests/gmm_generate_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_generate_test.cpp @@ -56,21 +56,6 @@ BOOST_AUTO_TEST_CASE(GmmGenerateSamplesTest) Log::Fatal.ignoreInput = false; } -// Making sure samples are provided. -BOOST_AUTO_TEST_CASE(GmmGenerateSamples) -{ - arma::mat inputData(5, 10, arma::fill::randu); - - GMM gmm(1, 5); - gmm.Train(inputData, 5); - - SetInputParam("input_model", &gmm); - - Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); - Log::Fatal.ignoreInput = false; -} - // Checking dimensionality of output. BOOST_AUTO_TEST_CASE(GmmGenerateDimensionality) { diff --git a/src/mlpack/tests/main_tests/gmm_probability_test.cpp b/src/mlpack/tests/main_tests/gmm_probability_test.cpp index 17d5a8f983..7e5853ab7f 100644 --- a/src/mlpack/tests/main_tests/gmm_probability_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_probability_test.cpp @@ -49,6 +49,21 @@ void ResetGmmProbabilitySetting() BOOST_FIXTURE_TEST_SUITE(GmmProbabilityMainTest, GmmProbabilityTestFixture); +// Making sure input_file are provided. +BOOST_AUTO_TEST_CASE(GmmProbabilityInputTest) +{ + arma::mat inputData(5, 10, arma::fill::randu); + + GMM gmm(1, 5); + gmm.Train(inputData, 5); + + SetInputParam("input_model", &gmm); + + Log::Fatal.ignoreInput = true; + BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + Log::Fatal.ignoreInput = false; +} + // Checking the input and output dimensionality. BOOST_AUTO_TEST_CASE(GmmProbabilityDimensionality) { @@ -57,14 +72,14 @@ BOOST_AUTO_TEST_CASE(GmmProbabilityDimensionality) GMM gmm(1, 5); gmm.Train(std::move(inputData), 5); - arma::mat inputPoints(1, 8, arma::fill::randu); + arma::mat inputPoints(1, 5, arma::fill::randu); SetInputParam("input", std::move(inputPoints)); SetInputParam("input_model", &gmm); mlpackMain(); - BOOST_REQUIRE_EQUAL(CLI::GetParam("output").n_cols, 8); + BOOST_REQUIRE_EQUAL(CLI::GetParam("output").n_cols, 5); BOOST_REQUIRE_EQUAL(CLI::GetParam("output").n_rows, 1); } diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index 2a9d1672a4..197c7fc1a6 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainMaxIterationsTest) } // Ensure that Trials must be greater than 0. -BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) +BOOST_AUTO_TEST_CASE(GmmTrainPositiveTrialsTest) { arma::mat inputData(5, 10, arma::fill::randu); @@ -167,16 +167,48 @@ BOOST_AUTO_TEST_CASE(GmmTrainNumberOfGaussian) BOOST_REQUIRE_EQUAL(gmm1->Gaussians(), (int) 2); } -// Ensure that Noise affects the final result. -BOOST_AUTO_TEST_CASE(GmmTrainNoisetest) +// Making sure that enabling no_force_positive doesn't crash. +BOOST_AUTO_TEST_CASE(GmmTrainNoForcePositiveTest) { arma::mat inputData(5, 10, arma::fill::randu); + SetInputParam("input", inputData); + SetInputParam("gaussians", (int) 1); + SetInputParam("no_force_positive", true); + + mlpackMain(); + + GMM* gmm = CLI::GetParam("output_model"); + + SetInputParam("input_model", gmm); + + CLI::GetSingleton().Parameters()["input"].wasPassed = false; + + SetInputParam("input", std::move(inputData)); + + mlpackMain(); + + GMM* gmm1 = CLI::GetParam("output_model"); + + BOOST_REQUIRE_EQUAL(gmm1->Gaussians(), (int) 1); +} + +// Ensure that Noise affects the final result. +BOOST_AUTO_TEST_CASE(GmmTrainNoiseTest) +{ + arma::mat inputData; + if (!data::Load("data_3d_mixed.txt", inputData)) + BOOST_FAIL("Unable to load train dataset data_3d_mixed.txt!"); + SetInputParam("input", inputData); SetInputParam("gaussians", (int) 2); SetInputParam("noise", (double) 0.0); - mlpack::math::FixedRandomSeed(); + size_t seed = std::time(NULL); + mlpack::math::randGen.seed((uint32_t) seed); + srand((unsigned int) seed); + arma::arma_rng::set_seed(seed); + mlpackMain(); GMM* gmm = CLI::GetParam("output_model"); @@ -187,7 +219,10 @@ BOOST_AUTO_TEST_CASE(GmmTrainNoisetest) SetInputParam("gaussians", (int) 2); SetInputParam("noise", (double) 100.0); - mlpack::math::FixedRandomSeed(); + mlpack::math::randGen.seed((uint32_t) seed); + srand((unsigned int) seed); + arma::arma_rng::set_seed(seed); + mlpackMain(); GMM* gmm1 = CLI::GetParam("output_model"); @@ -195,24 +230,75 @@ BOOST_AUTO_TEST_CASE(GmmTrainNoisetest) arma::uvec sortedIndices = sort_index(gmm->Weights()); for (size_t k = 0; k < sortedIndices.n_elem; k++) + { BOOST_REQUIRE(arma::norm(gmm->Component(sortedIndices[k]).Mean() - gmm1->Component(sortedIndices[k]).Mean()) > 1e-50 || arma::norm(gmm->Component(sortedIndices[k]).Covariance() - gmm1->Component(sortedIndices[k]).Covariance()) > 1e-50); + } +} + +// Ensure that Trials affects the final result. +BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) +{ + arma::mat inputData(5, 100, arma::fill::randu); + + SetInputParam("input", inputData); + SetInputParam("gaussians", (int) 2); + SetInputParam("trials", (int) 1); + + size_t seed = std::time(NULL); + mlpack::math::randGen.seed((uint32_t) seed); + srand((unsigned int) seed); + arma::arma_rng::set_seed(seed); + + mlpackMain(); + + GMM* gmm = CLI::GetParam("output_model"); + + ResetGmmTrainSetting(); + + SetInputParam("input", std::move(inputData)); + SetInputParam("gaussians", (int) 2); + SetInputParam("trials", (int) 500); + + mlpack::math::randGen.seed((uint32_t) seed); + srand((unsigned int) seed); + arma::arma_rng::set_seed(seed); + + mlpackMain(); + + GMM* gmm1 = CLI::GetParam("output_model"); + + arma::uvec sortedIndices = sort_index(gmm->Weights()); + + for (size_t k = 0; k < sortedIndices.n_elem; k++) + { + BOOST_REQUIRE(arma::norm(gmm->Component(sortedIndices[k]).Mean() - + gmm1->Component(sortedIndices[k]).Mean()) > 1e-50 || + arma::norm(gmm->Component(sortedIndices[k]).Covariance() - + gmm1->Component(sortedIndices[k]).Covariance()) > 1e-50); + } } // Ensure that Percentage affects the final result when refined_start is true. BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) { - arma::mat inputData(5, 10, arma::fill::randu); + arma::mat inputData; + if (!data::Load("data_3d_mixed.txt", inputData)) + BOOST_FAIL("Unable to load train dataset data_3d_mixed.txt!"); SetInputParam("input", inputData); SetInputParam("gaussians", (int) 2); SetInputParam("refined_start", true); SetInputParam("percentage", (double) 0.01); - SetInputParam("samplings", (int) 200); + SetInputParam("samplings", (int) 1000); + + size_t seed = std::time(NULL); + mlpack::math::randGen.seed((uint32_t) seed); + srand((unsigned int) seed); + arma::arma_rng::set_seed(seed); - mlpack::math::FixedRandomSeed(); mlpackMain(); GMM* gmm = CLI::GetParam("output_model"); @@ -222,10 +308,13 @@ BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.99); - SetInputParam("samplings", (int) 200); + SetInputParam("percentage", (double) 0.20); + SetInputParam("samplings", (int) 1000); + + mlpack::math::randGen.seed((uint32_t) seed); + srand((unsigned int) seed); + arma::arma_rng::set_seed(seed); - mlpack::math::FixedRandomSeed(); mlpackMain(); GMM* gmm1 = CLI::GetParam("output_model"); @@ -233,24 +322,32 @@ BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) arma::uvec sortedIndices = sort_index(gmm->Weights()); for (size_t k = 0; k < sortedIndices.n_elem; k++) + { BOOST_REQUIRE(arma::norm(gmm->Component(sortedIndices[k]).Mean() - gmm1->Component(sortedIndices[k]).Mean()) > 1e-50 || arma::norm(gmm->Component(sortedIndices[k]).Covariance() - gmm1->Component(sortedIndices[k]).Covariance()) > 1e-50); + } } // Ensure that Sampling affects the final result when refined_start is true. BOOST_AUTO_TEST_CASE(GmmTrainSamplingsTest) { - arma::mat inputData(5, 10, arma::fill::randu); + arma::mat inputData; + if (!data::Load("data_3d_mixed.txt", inputData)) + BOOST_FAIL("Unable to load train dataset data_3d_mixed.txt!"); SetInputParam("input", inputData); SetInputParam("gaussians", (int) 2); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.950); + SetInputParam("percentage", (double) 0.2); SetInputParam("samplings", (int) 10); - mlpack::math::FixedRandomSeed(); + size_t seed = std::time(NULL); + mlpack::math::randGen.seed((uint32_t) seed); + srand((unsigned int) seed); + arma::arma_rng::set_seed(seed); + mlpackMain(); GMM* gmm = CLI::GetParam("output_model"); @@ -260,10 +357,13 @@ BOOST_AUTO_TEST_CASE(GmmTrainSamplingsTest) SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.950); - SetInputParam("samplings", (int) 1000); + SetInputParam("percentage", (double) 0.2); + SetInputParam("samplings", (int) 10000); + + mlpack::math::randGen.seed((uint32_t) seed); + srand((unsigned int) seed); + arma::arma_rng::set_seed(seed); - mlpack::math::FixedRandomSeed(); mlpackMain(); GMM* gmm1 = CLI::GetParam("output_model"); @@ -271,24 +371,30 @@ BOOST_AUTO_TEST_CASE(GmmTrainSamplingsTest) arma::uvec sortedIndices = sort_index(gmm->Weights()); for (size_t k = 0; k < sortedIndices.n_elem; k++) + { BOOST_REQUIRE(arma::norm(gmm->Component(sortedIndices[k]).Mean() - gmm1->Component(sortedIndices[k]).Mean()) > 1e-50 || arma::norm(gmm->Component(sortedIndices[k]).Covariance() - gmm1->Component(sortedIndices[k]).Covariance()) > 1e-50); + } } // Ensure that tolerance affects the final result. BOOST_AUTO_TEST_CASE(GmmTrainToleranceTest) { arma::mat inputData; - if (!data::Load("vc2.csv", inputData)) - BOOST_FAIL("Unable to load train dataset vc2.csv!"); + if (!data::Load("data_3d_mixed.txt", inputData)) + BOOST_FAIL("Unable to load train dataset data_3d_mixed.txt!"); SetInputParam("input", inputData); SetInputParam("gaussians", (int) 2); SetInputParam("tolerance", (double) 1e-8); - mlpack::math::FixedRandomSeed(); + size_t seed = std::time(NULL); + mlpack::math::randGen.seed((uint32_t) seed); + srand((unsigned int) seed); + arma::arma_rng::set_seed(seed); + mlpackMain(); GMM* gmm = CLI::GetParam("output_model"); @@ -299,7 +405,10 @@ BOOST_AUTO_TEST_CASE(GmmTrainToleranceTest) SetInputParam("gaussians", (int) 2); SetInputParam("tolerance", (double) 10); - mlpack::math::FixedRandomSeed(); + mlpack::math::randGen.seed((uint32_t) seed); + srand((unsigned int) seed); + arma::arma_rng::set_seed(seed); + mlpackMain(); GMM* gmm1 = CLI::GetParam("output_model"); @@ -307,10 +416,12 @@ BOOST_AUTO_TEST_CASE(GmmTrainToleranceTest) arma::uvec sortedIndices = sort_index(gmm->Weights()); for (size_t k = 0; k < sortedIndices.n_elem; k++) + { BOOST_REQUIRE(arma::norm(gmm->Component(sortedIndices[k]).Mean() - gmm1->Component(sortedIndices[k]).Mean()) > 1e-50 || arma::norm(gmm->Component(sortedIndices[k]).Covariance() - gmm1->Component(sortedIndices[k]).Covariance()) > 1e-50); + } } // Ensure that saved model can be used again. From 9a3e3e77006e8339529db535488e0d70e09f654e Mon Sep 17 00:00:00 2001 From: Yashwant Date: Mon, 17 Jun 2019 09:10:35 +0530 Subject: [PATCH 07/18] Remove and upadte Tests as suggested --- .../tests/main_tests/gmm_probability_test.cpp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/mlpack/tests/main_tests/gmm_probability_test.cpp b/src/mlpack/tests/main_tests/gmm_probability_test.cpp index 7e5853ab7f..0282763aa4 100644 --- a/src/mlpack/tests/main_tests/gmm_probability_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_probability_test.cpp @@ -49,21 +49,6 @@ void ResetGmmProbabilitySetting() BOOST_FIXTURE_TEST_SUITE(GmmProbabilityMainTest, GmmProbabilityTestFixture); -// Making sure input_file are provided. -BOOST_AUTO_TEST_CASE(GmmProbabilityInputTest) -{ - arma::mat inputData(5, 10, arma::fill::randu); - - GMM gmm(1, 5); - gmm.Train(inputData, 5); - - SetInputParam("input_model", &gmm); - - Log::Fatal.ignoreInput = true; - BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); - Log::Fatal.ignoreInput = false; -} - // Checking the input and output dimensionality. BOOST_AUTO_TEST_CASE(GmmProbabilityDimensionality) { @@ -72,7 +57,7 @@ BOOST_AUTO_TEST_CASE(GmmProbabilityDimensionality) GMM gmm(1, 5); gmm.Train(std::move(inputData), 5); - arma::mat inputPoints(1, 5, arma::fill::randu); + arma::mat inputPoints(5, 5, arma::fill::randu); SetInputParam("input", std::move(inputPoints)); SetInputParam("input_model", &gmm); From 5ad9bc10c3fed7c006d1be59a1c3421dbf25fa91 Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Mon, 17 Jun 2019 11:56:22 +0530 Subject: [PATCH 08/18] Fix GMMTrainTest --- src/mlpack/tests/main_tests/gmm_train_test.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index 197c7fc1a6..7dc6c1e131 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -284,9 +284,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) // Ensure that Percentage affects the final result when refined_start is true. BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) { - arma::mat inputData; - if (!data::Load("data_3d_mixed.txt", inputData)) - BOOST_FAIL("Unable to load train dataset data_3d_mixed.txt!"); + arma::mat inputData(50, 100, arma::fill::randu); SetInputParam("input", inputData); SetInputParam("gaussians", (int) 2); @@ -308,7 +306,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.20); + SetInputParam("percentage", (double) 0.35); SetInputParam("samplings", (int) 1000); mlpack::math::randGen.seed((uint32_t) seed); From ed89731921d6c62e027c776761c3aa3ad7ab0c6c Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Mon, 17 Jun 2019 13:07:38 +0530 Subject: [PATCH 09/18] Update gmm_train_test.cpp --- src/mlpack/tests/main_tests/gmm_train_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index 7dc6c1e131..ab71a7c78b 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -306,7 +306,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.35); + SetInputParam("percentage", (double) 0.20); SetInputParam("samplings", (int) 1000); mlpack::math::randGen.seed((uint32_t) seed); From 645cf1b325b32fec6083922055b697d0356b3401 Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Mon, 17 Jun 2019 13:52:38 +0530 Subject: [PATCH 10/18] Fix --- src/mlpack/tests/main_tests/gmm_train_test.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index ab71a7c78b..ffa3ebf544 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -284,7 +284,9 @@ BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) // Ensure that Percentage affects the final result when refined_start is true. BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) { - arma::mat inputData(50, 100, arma::fill::randu); + arma::mat inputData; + if (!data::Load("data_3d_mixed.txt", inputData)) + BOOST_FAIL("Unable to load train dataset data_3d_mixed.txt!"); SetInputParam("input", inputData); SetInputParam("gaussians", (int) 2); @@ -306,7 +308,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.20); + SetInputParam("percentage", (double) 0.35); SetInputParam("samplings", (int) 1000); mlpack::math::randGen.seed((uint32_t) seed); From 2fd5a7fd6812098e5104d478cd81b0cfdabcbd09 Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Tue, 18 Jun 2019 16:30:05 +0530 Subject: [PATCH 11/18] Fix Some Tests --- src/mlpack/tests/main_tests/gmm_train_test.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index ffa3ebf544..a8a02b32b9 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -244,8 +244,9 @@ BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) arma::mat inputData(5, 100, arma::fill::randu); SetInputParam("input", inputData); - SetInputParam("gaussians", (int) 2); + SetInputParam("gaussians", (int) 3); SetInputParam("trials", (int) 1); + SetInputParam("max_iterations", (int) 500); size_t seed = std::time(NULL); mlpack::math::randGen.seed((uint32_t) seed); @@ -259,7 +260,8 @@ BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) ResetGmmTrainSetting(); SetInputParam("input", std::move(inputData)); - SetInputParam("gaussians", (int) 2); + SetInputParam("gaussians", (int) 3); + SetInputParam("max_iterations", (int) 500); SetInputParam("trials", (int) 500); mlpack::math::randGen.seed((uint32_t) seed); @@ -308,7 +310,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainPercentageTest) SetInputParam("input", std::move(inputData)); SetInputParam("gaussians", (int) 2); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.35); + SetInputParam("percentage", (double) 0.45); SetInputParam("samplings", (int) 1000); mlpack::math::randGen.seed((uint32_t) seed); @@ -338,9 +340,8 @@ BOOST_AUTO_TEST_CASE(GmmTrainSamplingsTest) BOOST_FAIL("Unable to load train dataset data_3d_mixed.txt!"); SetInputParam("input", inputData); - SetInputParam("gaussians", (int) 2); + SetInputParam("gaussians", (int) 3); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.2); SetInputParam("samplings", (int) 10); size_t seed = std::time(NULL); @@ -355,10 +356,9 @@ BOOST_AUTO_TEST_CASE(GmmTrainSamplingsTest) ResetGmmTrainSetting(); SetInputParam("input", std::move(inputData)); - SetInputParam("gaussians", (int) 2); + SetInputParam("gaussians", (int) 3); SetInputParam("refined_start", true); - SetInputParam("percentage", (double) 0.2); - SetInputParam("samplings", (int) 10000); + SetInputParam("samplings", (int) 25000); mlpack::math::randGen.seed((uint32_t) seed); srand((unsigned int) seed); @@ -485,4 +485,3 @@ BOOST_AUTO_TEST_CASE(GmmTrainDiagCovariance) } BOOST_AUTO_TEST_SUITE_END(); - From 7ed45b7909da8edac05fe649ee8488cbaf268aa8 Mon Sep 17 00:00:00 2001 From: Yashwant Date: Thu, 20 Jun 2019 17:35:58 +0530 Subject: [PATCH 12/18] Fix SamplingsTest --- src/mlpack/tests/main_tests/gmm_train_test.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index a8a02b32b9..00f2160da1 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -244,8 +244,9 @@ BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) arma::mat inputData(5, 100, arma::fill::randu); SetInputParam("input", inputData); - SetInputParam("gaussians", (int) 3); + SetInputParam("gaussians", (int) 8); SetInputParam("trials", (int) 1); + SetInputParam("samplings", (int) 50); SetInputParam("max_iterations", (int) 500); size_t seed = std::time(NULL); @@ -260,8 +261,9 @@ BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) ResetGmmTrainSetting(); SetInputParam("input", std::move(inputData)); - SetInputParam("gaussians", (int) 3); + SetInputParam("gaussians", (int) 8); SetInputParam("max_iterations", (int) 500); + SetInputParam("samplings", (int) 50); SetInputParam("trials", (int) 500); mlpack::math::randGen.seed((uint32_t) seed); @@ -340,8 +342,9 @@ BOOST_AUTO_TEST_CASE(GmmTrainSamplingsTest) BOOST_FAIL("Unable to load train dataset data_3d_mixed.txt!"); SetInputParam("input", inputData); - SetInputParam("gaussians", (int) 3); + SetInputParam("gaussians", (int) 8); SetInputParam("refined_start", true); + SetInputParam("trials", (int) 2); SetInputParam("samplings", (int) 10); size_t seed = std::time(NULL); @@ -356,9 +359,10 @@ BOOST_AUTO_TEST_CASE(GmmTrainSamplingsTest) ResetGmmTrainSetting(); SetInputParam("input", std::move(inputData)); - SetInputParam("gaussians", (int) 3); + SetInputParam("gaussians", (int) 8); SetInputParam("refined_start", true); - SetInputParam("samplings", (int) 25000); + SetInputParam("trials", (int) 2); + SetInputParam("samplings", (int) 5000); mlpack::math::randGen.seed((uint32_t) seed); srand((unsigned int) seed); @@ -485,3 +489,4 @@ BOOST_AUTO_TEST_CASE(GmmTrainDiagCovariance) } BOOST_AUTO_TEST_SUITE_END(); + From 4a791b7b87910cfd594c23f1a5488aeeae517b35 Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Thu, 20 Jun 2019 18:34:28 +0530 Subject: [PATCH 13/18] Fix TrailsTest --- src/mlpack/tests/main_tests/gmm_train_test.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index 00f2160da1..e9315fc21f 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -244,9 +244,8 @@ BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) arma::mat inputData(5, 100, arma::fill::randu); SetInputParam("input", inputData); - SetInputParam("gaussians", (int) 8); + SetInputParam("gaussians", (int) 4); SetInputParam("trials", (int) 1); - SetInputParam("samplings", (int) 50); SetInputParam("max_iterations", (int) 500); size_t seed = std::time(NULL); @@ -261,9 +260,8 @@ BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) ResetGmmTrainSetting(); SetInputParam("input", std::move(inputData)); - SetInputParam("gaussians", (int) 8); + SetInputParam("gaussians", (int) 4); SetInputParam("max_iterations", (int) 500); - SetInputParam("samplings", (int) 50); SetInputParam("trials", (int) 500); mlpack::math::randGen.seed((uint32_t) seed); From 29fbf8600daba32a923e030a8d6edba3e33a3019 Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Thu, 20 Jun 2019 19:27:26 +0530 Subject: [PATCH 14/18] Still Failing TrialsTest --- src/mlpack/tests/main_tests/gmm_train_test.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index e9315fc21f..050b756fca 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -244,7 +244,9 @@ BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) arma::mat inputData(5, 100, arma::fill::randu); SetInputParam("input", inputData); - SetInputParam("gaussians", (int) 4); + SetInputParam("gaussians", (int) 3); + SetInputParam("refined_start", true); + SetInputParam("samplings", (int) 1000); SetInputParam("trials", (int) 1); SetInputParam("max_iterations", (int) 500); @@ -260,7 +262,9 @@ BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) ResetGmmTrainSetting(); SetInputParam("input", std::move(inputData)); - SetInputParam("gaussians", (int) 4); + SetInputParam("gaussians", (int) 3); + SetInputParam("refined_start", true); + SetInputParam("samplings", (int) 1000); SetInputParam("max_iterations", (int) 500); SetInputParam("trials", (int) 500); From 2f5dc0d8d08838eaeac44d03e385d4a8768eb50b Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Sat, 22 Jun 2019 17:45:10 +0530 Subject: [PATCH 15/18] Fix Trials test --- src/mlpack/tests/main_tests/gmm_train_test.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index 050b756fca..2c38247c30 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -9,6 +9,7 @@ * 3-clause BSD license along with mlpack. If not, see * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ + #include #define BINDING_TYPE BINDING_TYPE_TEST @@ -241,14 +242,12 @@ BOOST_AUTO_TEST_CASE(GmmTrainNoiseTest) // Ensure that Trials affects the final result. BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) { - arma::mat inputData(5, 100, arma::fill::randu); + arma::mat inputData(10000, 50, arma::fill::randu); SetInputParam("input", inputData); - SetInputParam("gaussians", (int) 3); - SetInputParam("refined_start", true); - SetInputParam("samplings", (int) 1000); - SetInputParam("trials", (int) 1); + SetInputParam("gaussians", (int) 5); SetInputParam("max_iterations", (int) 500); + SetInputParam("trials", (int) 1); size_t seed = std::time(NULL); mlpack::math::randGen.seed((uint32_t) seed); @@ -262,9 +261,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) ResetGmmTrainSetting(); SetInputParam("input", std::move(inputData)); - SetInputParam("gaussians", (int) 3); - SetInputParam("refined_start", true); - SetInputParam("samplings", (int) 1000); + SetInputParam("gaussians", (int) 5); SetInputParam("max_iterations", (int) 500); SetInputParam("trials", (int) 500); @@ -491,4 +488,3 @@ BOOST_AUTO_TEST_CASE(GmmTrainDiagCovariance) } BOOST_AUTO_TEST_SUITE_END(); - From c53f8481436f443b06f2ffb7e22a72f2844754cf Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Sat, 22 Jun 2019 18:13:45 +0530 Subject: [PATCH 16/18] Fix :( --- src/mlpack/tests/main_tests/gmm_train_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index 2c38247c30..4e7380ef1a 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -242,12 +242,12 @@ BOOST_AUTO_TEST_CASE(GmmTrainNoiseTest) // Ensure that Trials affects the final result. BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) { - arma::mat inputData(10000, 50, arma::fill::randu); + arma::mat inputData(5, 1000, arma::fill::randu); SetInputParam("input", inputData); - SetInputParam("gaussians", (int) 5); - SetInputParam("max_iterations", (int) 500); + SetInputParam("gaussians", (int) 3); SetInputParam("trials", (int) 1); + SetInputParam("max_iterations", (int) 500); size_t seed = std::time(NULL); mlpack::math::randGen.seed((uint32_t) seed); @@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) ResetGmmTrainSetting(); SetInputParam("input", std::move(inputData)); - SetInputParam("gaussians", (int) 5); + SetInputParam("gaussians", (int) 3); SetInputParam("max_iterations", (int) 500); SetInputParam("trials", (int) 500); From ecb6daf640888ff6efaf3dec65d06ab5ea7e5f5f Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Sat, 22 Jun 2019 23:21:41 +0530 Subject: [PATCH 17/18] Add gmmtrainmaintest To parallel test --- src/mlpack/tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index 8084e29d5b..af1a86c17e 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -188,7 +188,7 @@ set(parallel_tests "SVDIncrementalTest;SVDBatchTest;" "LocalCoordinateCodingTest;FeedForwardNetworkTest;SparseAutoencoderTest;" "GMMTest;CFTest;ConvolutionalNetworkTest;HMMTest;LARSTest;" - "LogisticRegressionTest;" + "LogisticRegressionTest;GmmTrainMainTest;" "LinearSVMTest") # Add tests to the testing framework From ff3d0d8f73ae184ea748b3d89e2acf34dc27ea8d Mon Sep 17 00:00:00 2001 From: Yashwant Singh Parihar Date: Sun, 23 Jun 2019 07:24:47 +0530 Subject: [PATCH 18/18] Update gmm_train_test.cpp --- src/mlpack/tests/main_tests/gmm_train_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index 4e7380ef1a..e049e8538e 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(GmmTrainNoiseTest) // Ensure that Trials affects the final result. BOOST_AUTO_TEST_CASE(GmmTrainTrialsTest) { - arma::mat inputData(5, 1000, arma::fill::randu); + arma::mat inputData(5, 250, arma::fill::randu); SetInputParam("input", inputData); SetInputParam("gaussians", (int) 3);