From cee2441d6e9d147dfcd7b8ab005d9cf65b916403 Mon Sep 17 00:00:00 2001 From: Omar Shrit Date: Sat, 3 Oct 2020 17:48:14 +0200 Subject: [PATCH] Copy required function in the second file Signed-off-by: Omar Shrit --- .../tests/feedforward_network_2_test.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/mlpack/tests/feedforward_network_2_test.cpp b/src/mlpack/tests/feedforward_network_2_test.cpp index f447f487fb..9400aad8cd 100644 --- a/src/mlpack/tests/feedforward_network_2_test.cpp +++ b/src/mlpack/tests/feedforward_network_2_test.cpp @@ -28,6 +28,36 @@ using namespace mlpack; using namespace mlpack::ann; using namespace mlpack::kmeans; +/** + * Train and evaluate a model with the specified structure. + */ +template +void TestNetwork(ModelType& model, + MatType& trainData, + MatType& trainLabels, + MatType& testData, + MatType& testLabels, + const size_t maxEpochs, + const double classificationErrorThreshold) +{ + ens::RMSProp opt(0.01, 32, 0.88, 1e-8, maxEpochs * trainData.n_cols, -1); + model.Train(trainData, trainLabels, opt); + + MatType predictionTemp; + model.Predict(testData, predictionTemp); + MatType prediction = arma::zeros(1, predictionTemp.n_cols); + + for (size_t i = 0; i < predictionTemp.n_cols; ++i) + { + prediction(i) = arma::as_scalar(arma::find( + arma::max(predictionTemp.col(i)) == predictionTemp.col(i), 1)) + 1; + } + + size_t correct = arma::accu(prediction == testLabels); + double classificationError = 1 - double(correct) / testData.n_cols; + REQUIRE(classificationError <= classificationErrorThreshold); +} + /** * Train the highway network on a larger dataset.