Add serialization test.
This commit is contained in:
@@ -130,9 +130,9 @@ BOOST_AUTO_TEST_CASE(PredictiveUncertainties)
|
||||
|
||||
for (size_t i = 0; i < matX.n_cols; i++)
|
||||
BOOST_REQUIRE_GT(std[i], estStd);
|
||||
|
||||
|
||||
// Check that the estimated variance is close to 1.
|
||||
BOOST_REQUIRE_CLOSE(estStd, 1, 10);
|
||||
BOOST_REQUIRE_CLOSE(estStd, 1, 20);
|
||||
}
|
||||
|
||||
// Check the solution is equal to the classical ridge.
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <mlpack/methods/lsh/lsh_search.hpp>
|
||||
#include <mlpack/methods/decision_stump/decision_stump.hpp>
|
||||
#include <mlpack/methods/lars/lars.hpp>
|
||||
#include <mlpack/methods/bayesian_linear_regression/bayesian_linear_regression.hpp>
|
||||
#include <mlpack/methods/ann/rbm/rbm.hpp>
|
||||
#include <mlpack/methods/ann/init_rules/gaussian_init.hpp>
|
||||
|
||||
@@ -1604,4 +1605,34 @@ BOOST_AUTO_TEST_CASE(ssRBMTest)
|
||||
CheckMatrices(Rbm.Weight(), RbmBinary.Weight());
|
||||
}
|
||||
|
||||
// Make sure serialization works for BayesianLinearRegression.
|
||||
BOOST_AUTO_TEST_CASE(BayesianLinearRegressionTest)
|
||||
{
|
||||
using namespace mlpack::regression;
|
||||
|
||||
// Create a dataset.
|
||||
arma::mat X = arma::randn(75, 250);
|
||||
arma::vec omega = arma::randn(75, 1);
|
||||
arma::rowvec y = omega.t() * X;
|
||||
|
||||
BayesianLinearRegression blr(false, false);
|
||||
blr.Train(X, y);
|
||||
arma::vec omegaOpt = blr.Omega();
|
||||
|
||||
// Now, serialize.
|
||||
BayesianLinearRegression xmlBlr(false, false), binaryBlr(false, false),
|
||||
textBlr(false, false);
|
||||
|
||||
SerializeObjectAll(blr, xmlBlr, binaryBlr, textBlr);
|
||||
|
||||
// Now, check that predictions are the same.
|
||||
arma::rowvec pred, xmlPred, textPred, binaryPred;
|
||||
blr.Predict(X, pred);
|
||||
xmlBlr.Predict(X, xmlPred);
|
||||
textBlr.Predict(X, textPred);
|
||||
binaryBlr.Predict(X, binaryPred);
|
||||
|
||||
CheckMatrices(pred, xmlPred, textPred, binaryPred);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END();
|
||||
|
||||
Reference in New Issue
Block a user