Merge pull request #2009 from rcurtin/dt-main-test-fixes

Fix occasional `DecisionTreeMainTest` bugs
This commit is contained in:
Ryan Curtin
2019-09-10 17:26:58 -04:00
committed by GitHub
3 changed files with 21 additions and 11 deletions
-1
View File
@@ -33,7 +33,6 @@
@attribute 'Active' {0,1,2,3,4,5,6}
@attribute 'Passive' {0,1,2,3,4}
@attribute 'Logged_income' REAL
@attribute 'Trips' {0,1,2,3,4,5}
@data
41,0,2187.5,186.9,0,0,3,7.690514618
@@ -33,7 +33,6 @@
@attribute 'Active' {0,1,2,3,4,5,6}
@attribute 'Passive' {0,1,2,3,4}
@attribute 'Logged_income' REAL
@attribute 'Trips' {0,1,2,3,4,5,7}
@data
19,1,2351.485149,170.4,0,0,0,7.762802386
@@ -261,6 +261,8 @@ BOOST_AUTO_TEST_CASE(DecisionRegularisationTest)
mlpackMain();
pred = std::move(CLI::GetParam<arma::Row<size_t>>("predictions"));
bindings::tests::CleanMemory();
// Input training data.
SetInputParam("training", std::make_tuple(info, inputData));
SetInputParam("labels", std::move(labels));
@@ -275,8 +277,8 @@ BOOST_AUTO_TEST_CASE(DecisionRegularisationTest)
predRegularised = std::move(CLI::GetParam<arma::Row<size_t>>("predictions"));
size_t count = 0;
// This part of code is dupliacte with no weighted one.
for (size_t i = 0; i < 1000; ++i)
BOOST_REQUIRE_EQUAL(pred.n_elem, predRegularised.n_elem);
for (size_t i = 0; i < pred.n_elem; ++i)
{
if (pred[i] != predRegularised[i])
count++;
@@ -377,9 +379,13 @@ BOOST_AUTO_TEST_CASE(DecisionTreeTrainingVerTest)
mlpackMain();
DecisionTreeModel* model = CLI::GetParam<DecisionTreeModel*>("output_model");
CLI::GetParam<DecisionTreeModel*>("output_model") = NULL;
bindings::tests::CleanMemory();
// Input pre-trained model.
SetInputParam("input_model",
std::move(CLI::GetParam<DecisionTreeModel*>("output_model")));
SetInputParam("input_model", model);
Log::Fatal.ignoreInput = true;
BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error);
@@ -424,6 +430,11 @@ BOOST_AUTO_TEST_CASE(DecisionModelCategoricalReuseTest)
predictions = std::move(CLI::GetParam<arma::Row<size_t>>("predictions"));
probabilities = std::move(CLI::GetParam<arma::mat>("probabilities"));
DecisionTreeModel* model = CLI::GetParam<DecisionTreeModel*>("output_model");
CLI::GetParam<DecisionTreeModel*>("output_model") = NULL;
bindings::tests::CleanMemory();
// Reset passed parameters.
CLI::GetSingleton().Parameters()["training"].wasPassed = false;
CLI::GetSingleton().Parameters()["labels"].wasPassed = false;
@@ -432,8 +443,7 @@ BOOST_AUTO_TEST_CASE(DecisionModelCategoricalReuseTest)
// Input trained model.
SetInputParam("test", std::make_tuple(info, testData));
SetInputParam("input_model",
std::move(CLI::GetParam<DecisionTreeModel*>("output_model")));
SetInputParam("input_model", model);
mlpackMain();
@@ -488,19 +498,21 @@ BOOST_AUTO_TEST_CASE(DecisionTreeMaximumDepthTest)
// Check that number of output points are equal to number of input points.
arma::Row<size_t> predictions;
predictions = CLI::GetParam<arma::Row<size_t>>("predictions");
predictions = std::move(CLI::GetParam<arma::Row<size_t>>("predictions"));
ResetDTSettings();
bindings::tests::CleanMemory();
// Input training data.
SetInputParam("training", std::make_tuple(info, inputData));
SetInputParam("labels", std::move(labels));
SetInputParam("weights", std::move(weights));
SetInputParam("maximum_depth", (int) 4);
SetInputParam("maximum_depth", (int) 2);
// Input test data.
SetInputParam("test", std::make_tuple(info, testData));
mlpackMain();
CheckMatricesNotEqual(predictions,
CLI::GetParam<arma::Row<size_t>>("predictions"));
}