Adding test for callback

This commit is contained in:
Vikas Shetty
2019-10-20 17:28:47 +05:30
parent ebe104bf29
commit adb3040bf1
+24
View File
@@ -5,11 +5,13 @@
#include <mlpack/methods/ann/ffn.hpp>
#include <mlpack/methods/ann/rnn.hpp>
#include <mlpack/methods/ann/loss_functions/mean_squared_error.hpp>
#include <mlpack/methods/logistic_regression/logistic_regression.hpp>
#include <boost/test/unit_test.hpp>
using namespace mlpack;
using namespace mlpack::ann;
using namespace mlpack::regression;
BOOST_AUTO_TEST_SUITE(CallbackTest);
@@ -115,4 +117,26 @@ BOOST_AUTO_TEST_CASE(RNNWithOptimizerCallbackTest)
BOOST_REQUIRE_GT(stream.str().length(), 0);
}
/**
* Test Logistic regression implementation with Printloss callback.
*/
BOOST_AUTO_TEST_CASE(LRWithOptimizerCallback)
{
arma::mat data("1 2 3;"
"1 2 3");
arma::Row<size_t> responses("1 1 0");
ens::StandardSGD sgd(0.005, 32, 500000, 1e-4);
LogisticRegression<> logisticRegression(data, responses, sgd, 0.001);
std::stringstream stream;
logisticRegression.Train<ens::L_BFGS>(
data,
responses,
sgd,
ens::PrintLoss(stream)
);
BOOST_REQUIRE_GT(stream.str().length(), 0);
}
BOOST_AUTO_TEST_SUITE_END();