Merge remote-tracking branch 'origin/master' into azure-msi
This commit is contained in:
@@ -27,10 +27,6 @@ jobs:
|
||||
# binding: 'go'
|
||||
# go.version: '1.11.0'
|
||||
# CMakeArgs: '-DDEBUG=OFF -DPROFILE=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=ON -DBUILD_R_BINDINGS=OFF'
|
||||
# R:
|
||||
# binding: 'R'
|
||||
# R.version: '4.0.0'
|
||||
# CMakeArgs: '-DDEBUG=OFF -DPROFILE=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_R_BINDINGS=ON'
|
||||
# Markdown:
|
||||
# CMakeArgs: '-DDEBUG=OFF -DPROFILE=OFF -DBUILD_MARKDOWN_BINDINGS=ON -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_R_BINDINGS=OFF'
|
||||
#
|
||||
@@ -59,11 +55,6 @@ jobs:
|
||||
# python.version: '2.7'
|
||||
# go.version: '1.11.0'
|
||||
# CMakeArgs: '-DDEBUG=OFF -DPROFILE=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=ON -DBUILD_R_BINDINGS=OFF'
|
||||
# R:
|
||||
# binding: 'R'
|
||||
# python.version: '2.7'
|
||||
# R.version: '4.0.0'
|
||||
# CMakeArgs: '-DDEBUG=OFF -DPROFILE=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_R_BINDINGS=ON'
|
||||
#
|
||||
# steps:
|
||||
# - template: macos-steps.yaml
|
||||
|
||||
@@ -34,15 +34,6 @@ steps:
|
||||
sudo tar -C /opt/ -xvpf julia-1.3.0-linux-x86_64.tar.gz
|
||||
fi
|
||||
|
||||
if [ "$(binding)" == "R" ]; then
|
||||
if [ "a$(R.version)" != "a" ]; then
|
||||
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran40/'
|
||||
sudo apt-get -y update
|
||||
sudo apt-get install -y r-base-core
|
||||
fi
|
||||
sudo Rscript -e "install.packages(c('Rcpp', 'RcppArmadillo', 'RcppEnsmallen', 'BH', 'roxygen2', 'testthat'))"
|
||||
fi
|
||||
|
||||
# Install armadillo.
|
||||
curl https://data.kurg.org/armadillo-8.400.0.tar.xz | tar -xvJ && cd armadillo*
|
||||
cmake . && make && sudo make install && cd ..
|
||||
|
||||
@@ -25,14 +25,6 @@ steps:
|
||||
brew cask install julia
|
||||
fi
|
||||
|
||||
if [ "$(binding)" == "R" ]; then
|
||||
if [ "a$(R.version)" != "a" ]; then
|
||||
brew cask install r
|
||||
fi
|
||||
brew cask install gfortran
|
||||
Rscript -e "install.packages(c('Rcpp', 'RcppArmadillo', 'RcppEnsmallen', 'BH', 'roxygen2', 'testthat'), repos = 'http://cran.us.r-project.org')"
|
||||
fi
|
||||
|
||||
git clone --depth 1 https://github.com/mlpack/jenkins-conf.git conf
|
||||
displayName: 'Install Build Dependencies'
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ on:
|
||||
- master
|
||||
release:
|
||||
types: [published, created, edited]
|
||||
name: R CMD check mlpack
|
||||
name: mlpack.mlpack
|
||||
|
||||
jobs:
|
||||
cancel:
|
||||
@@ -26,7 +26,7 @@ jobs:
|
||||
access_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
jobR:
|
||||
name: Build mlpack_r_tarball
|
||||
name: mlpack R tarball
|
||||
if: ${{ github.repository == 'mlpack/mlpack' }}
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
@@ -78,11 +78,15 @@ jobs:
|
||||
- name: CMake
|
||||
run: |
|
||||
mkdir build
|
||||
cd build && cmake -DDEBUG=OFF -DPROFILE=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_R_BINDINGS=ON ..
|
||||
cd build && cmake -DDEBUG=OFF -DPROFILE=OFF -DBUILD_CLI_EXECUTABLES=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_JULIA_BINDINGS=OFF -DBUILD_GO_BINDINGS=OFF -DBUILD_R_BINDINGS=ON ..
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
cd build && make R -j2
|
||||
cd build && make -j2
|
||||
|
||||
- name: Run tests via ctest
|
||||
run: |
|
||||
cd build && CTEST_OUTPUT_ON_FAILURE=1 ctest -T Test .
|
||||
|
||||
- name: Upload R packages
|
||||
uses: actions/upload-artifact@v2
|
||||
@@ -94,16 +98,16 @@ jobs:
|
||||
needs: jobR
|
||||
runs-on: ${{ matrix.config.os }}
|
||||
|
||||
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
|
||||
name: ${{ matrix.config.name }}
|
||||
if: ${{ github.repository == 'mlpack/mlpack' }}
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- {os: windows-latest, r: '4.0'}
|
||||
- {os: macOS-latest, r: 'release'}
|
||||
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
|
||||
- {os: windows-latest, r: '4.0', name: 'Windows R'}
|
||||
- {os: macOS-latest, r: 'release', name: 'macOS R'}
|
||||
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest", name: 'Linux R'}
|
||||
|
||||
|
||||
env:
|
||||
@@ -151,4 +155,6 @@ jobs:
|
||||
uses: actions/upload-artifact@master
|
||||
with:
|
||||
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
|
||||
path: check
|
||||
path: |
|
||||
check/mlpack.Rcheck/00check.log
|
||||
check/mlpack.Rcheck/00install.out
|
||||
|
||||
@@ -568,6 +568,7 @@ add_custom_target(mlpack_arma_config ALL
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-D ARMADILLO_INCLUDE_DIR="${ARMADILLO_INCLUDE_DIR}"
|
||||
-D OPENMP_FOUND="${OPENMP_FOUND}"
|
||||
-D CMAKE_SIZEOF_VOID_P="${CMAKE_SIZEOF_VOID_P}"
|
||||
-P CMake/CreateArmaConfigInfo.cmake
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMENT "Updating arma_config.hpp (if necessary)")
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
* Added Softmin activation function as layer in ann/layer.
|
||||
|
||||
* Fix spurious ARMA_64BIT_WORD compilation warnings on 32-bit systems (#2665).
|
||||
|
||||
### mlpack 3.4.1
|
||||
###### 2020-09-07
|
||||
* Fix incorrect parsing of required matrix/model parameters for command-line
|
||||
|
||||
@@ -20,9 +20,6 @@ add_executable(mlpack_test
|
||||
kde_test.cpp
|
||||
krann_search_test.cpp
|
||||
ksinit_test.cpp
|
||||
lars_test.cpp
|
||||
layer_names_test.cpp
|
||||
lin_alg_test.cpp
|
||||
linear_svm_test.cpp
|
||||
lmnn_test.cpp
|
||||
local_coordinate_coding_test.cpp
|
||||
@@ -45,7 +42,6 @@ add_executable(mlpack_test
|
||||
qdafn_test.cpp
|
||||
radical_test.cpp
|
||||
random_test.cpp
|
||||
range_search_test.cpp
|
||||
rectangle_tree_test.cpp
|
||||
reward_clipping_test.cpp
|
||||
rl_components_test.cpp
|
||||
@@ -88,7 +84,6 @@ add_executable(mlpack_test
|
||||
main_tests/nmf_test.cpp
|
||||
main_tests/perceptron_test.cpp
|
||||
main_tests/radical_test.cpp
|
||||
main_tests/range_search_test.cpp
|
||||
main_tests/test_helper.hpp
|
||||
)
|
||||
|
||||
@@ -127,6 +122,9 @@ add_executable(mlpack_catch_test
|
||||
kfn_test.cpp
|
||||
kmeans_test.cpp
|
||||
knn_test.cpp
|
||||
lars_test.cpp
|
||||
layer_names_test.cpp
|
||||
lin_alg_test.cpp
|
||||
linear_regression_test.cpp
|
||||
load_save_test.cpp
|
||||
loss_functions_test.cpp
|
||||
@@ -139,6 +137,7 @@ add_executable(mlpack_catch_test
|
||||
quic_svd_test.cpp
|
||||
random_forest_test.cpp
|
||||
randomized_svd_test.cpp
|
||||
range_search_test.cpp
|
||||
rbm_network_test.cpp
|
||||
recurrent_network_test.cpp
|
||||
regularized_svd_test.cpp
|
||||
@@ -179,6 +178,7 @@ add_executable(mlpack_catch_test
|
||||
main_tests/random_forest_test.cpp
|
||||
main_tests/softmax_regression_test.cpp
|
||||
main_tests/sparse_coding_test.cpp
|
||||
main_tests/range_search_test.cpp
|
||||
main_tests/test_helper.hpp
|
||||
)
|
||||
|
||||
@@ -232,7 +232,6 @@ set(parallel_tests
|
||||
"GMMTest;"
|
||||
"CFTest;"
|
||||
"HMMTest;"
|
||||
"LARSTest;"
|
||||
"LogisticRegressionTest;"
|
||||
"GmmTrainMainTest;"
|
||||
"LinearSVMTest")
|
||||
|
||||
@@ -10,19 +10,15 @@
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
|
||||
// Note: We don't use BOOST_REQUIRE_CLOSE in the code below because we need
|
||||
// to use FPC_WEAK, and it's not at all intuitive how to do that.
|
||||
#include <mlpack/methods/lars/lars.hpp>
|
||||
#include <mlpack/core/data/load.hpp>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_tools.hpp"
|
||||
#include "catch.hpp"
|
||||
#include "test_catch_tools.hpp"
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::regression;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(LARSTest);
|
||||
|
||||
void GenerateProblem(
|
||||
arma::mat& X, arma::rowvec& y, size_t nPoints, size_t nDims)
|
||||
{
|
||||
@@ -40,17 +36,18 @@ void LARSVerifyCorrectness(arma::vec beta, arma::vec errCorr, double lambda)
|
||||
if (beta(j) == 0)
|
||||
{
|
||||
// Make sure that |errCorr(j)| <= lambda.
|
||||
BOOST_REQUIRE_SMALL(std::max(fabs(errCorr(j)) - lambda, 0.0), tol);
|
||||
REQUIRE(std::max(fabs(errCorr(j)) - lambda, 0.0) ==
|
||||
Approx(0.0).margin(tol));
|
||||
}
|
||||
else if (beta(j) < 0)
|
||||
{
|
||||
// Make sure that errCorr(j) == lambda.
|
||||
BOOST_REQUIRE_SMALL(errCorr(j) - lambda, tol);
|
||||
REQUIRE(errCorr(j) - lambda == Approx(0.0).margin(tol));
|
||||
}
|
||||
else // beta(j) > 0
|
||||
{
|
||||
// Make sure that errCorr(j) == -lambda.
|
||||
BOOST_REQUIRE_SMALL(errCorr(j) + lambda, tol);
|
||||
REQUIRE(errCorr(j) + lambda == Approx(0.0).margin(tol));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,23 +82,23 @@ void LassoTest(size_t nPoints, size_t nDims, bool elasticNet, bool useCholesky)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(LARSTestLassoCholesky)
|
||||
TEST_CASE("LARSTestLassoCholesky", "[LARSTest]")
|
||||
{
|
||||
LassoTest(100, 10, false, true);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(LARSTestLassoGram)
|
||||
TEST_CASE("LARSTestLassoGram", "[LARSTest]")
|
||||
{
|
||||
LassoTest(100, 10, false, false);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(LARSTestElasticNetCholesky)
|
||||
TEST_CASE("LARSTestElasticNetCholesky", "[LARSTest]")
|
||||
{
|
||||
LassoTest(100, 10, true, true);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(LARSTestElasticNetGram)
|
||||
TEST_CASE("LARSTestElasticNetGram", "[LARSTest]")
|
||||
{
|
||||
LassoTest(100, 10, true, false);
|
||||
}
|
||||
@@ -109,7 +106,7 @@ BOOST_AUTO_TEST_CASE(LARSTestElasticNetGram)
|
||||
// Ensure that LARS doesn't crash when the data has linearly dependent features
|
||||
// (meaning that there is a singularity). This test uses the Cholesky
|
||||
// factorization.
|
||||
BOOST_AUTO_TEST_CASE(CholeskySingularityTest)
|
||||
TEST_CASE("CholeskySingularityTest", "[LARSTest]")
|
||||
{
|
||||
arma::mat X;
|
||||
arma::mat Y;
|
||||
@@ -133,7 +130,7 @@ BOOST_AUTO_TEST_CASE(CholeskySingularityTest)
|
||||
}
|
||||
|
||||
// Same as the above test but with no cholesky factorization.
|
||||
BOOST_AUTO_TEST_CASE(NoCholeskySingularityTest)
|
||||
TEST_CASE("NoCholeskySingularityTest", "[LARSTest]")
|
||||
{
|
||||
arma::mat X;
|
||||
arma::mat Y;
|
||||
@@ -158,7 +155,7 @@ BOOST_AUTO_TEST_CASE(NoCholeskySingularityTest)
|
||||
}
|
||||
|
||||
// Make sure that Predict() provides reasonable enough solutions.
|
||||
BOOST_AUTO_TEST_CASE(PredictTest)
|
||||
TEST_CASE("PredictTest", "[LARSTest]")
|
||||
{
|
||||
for (size_t i = 0; i < 2; ++i)
|
||||
{
|
||||
@@ -185,20 +182,20 @@ BOOST_AUTO_TEST_CASE(PredictTest)
|
||||
lars.Predict(X, predictions);
|
||||
arma::vec adjPred = X * predictions.t();
|
||||
|
||||
BOOST_REQUIRE_EQUAL(predictions.n_elem, 1000);
|
||||
REQUIRE(predictions.n_elem == 1000);
|
||||
for (size_t i = 0; i < betaOptPred.n_elem; ++i)
|
||||
{
|
||||
if (std::abs(betaOptPred[i]) < 1e-5)
|
||||
BOOST_REQUIRE_SMALL(adjPred[i], 1e-5);
|
||||
REQUIRE(adjPred[i] == Approx(0.0).margin(1e-5));
|
||||
else
|
||||
BOOST_REQUIRE_CLOSE(adjPred[i], betaOptPred[i], 1e-5);
|
||||
REQUIRE(adjPred[i] == Approx(betaOptPred[i]).epsilon(1e-7));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(PredictRowMajorTest)
|
||||
TEST_CASE("PredictRowMajorTest", "[LARSTest]")
|
||||
{
|
||||
arma::mat X;
|
||||
arma::rowvec y;
|
||||
@@ -217,20 +214,20 @@ BOOST_AUTO_TEST_CASE(PredictRowMajorTest)
|
||||
lars.Predict(X, colMajorPred);
|
||||
lars.Predict(X.t(), rowMajorPred, true);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(colMajorPred.n_elem, rowMajorPred.n_elem);
|
||||
REQUIRE(colMajorPred.n_elem == rowMajorPred.n_elem);
|
||||
for (size_t i = 0; i < colMajorPred.n_elem; ++i)
|
||||
{
|
||||
if (std::abs(colMajorPred[i]) < 1e-5)
|
||||
BOOST_REQUIRE_SMALL(rowMajorPred[i], 1e-5);
|
||||
REQUIRE(rowMajorPred[i] == Approx(0.0).margin(1e-5));
|
||||
else
|
||||
BOOST_REQUIRE_CLOSE(colMajorPred[i], rowMajorPred[i], 1e-5);
|
||||
REQUIRE(colMajorPred[i] == Approx(rowMajorPred[i]).epsilon(1e-7));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that if we train twice, there is no issue.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(RetrainTest)
|
||||
TEST_CASE("RetrainTest", "[LARSTest]")
|
||||
{
|
||||
arma::mat origX;
|
||||
arma::rowvec origY;
|
||||
@@ -257,7 +254,7 @@ BOOST_AUTO_TEST_CASE(RetrainTest)
|
||||
* Make sure if we train twice using the Cholesky decomposition, there is no
|
||||
* issue.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(RetrainCholeskyTest)
|
||||
TEST_CASE("RetrainCholeskyTest", "[LARSTest]")
|
||||
{
|
||||
arma::mat origX;
|
||||
arma::rowvec origY;
|
||||
@@ -284,7 +281,7 @@ BOOST_AUTO_TEST_CASE(RetrainCholeskyTest)
|
||||
* Make sure that we get correct solution coefficients when running training
|
||||
* and accessing solution coefficients separately.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(TrainingAndAccessingBetaTest)
|
||||
TEST_CASE("TrainingAndAccessingBetaTest", "[LARSTest]")
|
||||
{
|
||||
arma::mat X;
|
||||
arma::rowvec y;
|
||||
@@ -298,16 +295,16 @@ BOOST_AUTO_TEST_CASE(TrainingAndAccessingBetaTest)
|
||||
LARS lars2;
|
||||
lars2.Train(X, y);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(beta.n_elem, lars2.Beta().n_elem);
|
||||
REQUIRE(beta.n_elem == lars2.Beta().n_elem);
|
||||
for (size_t i = 0; i < beta.n_elem; ++i)
|
||||
BOOST_REQUIRE_CLOSE(beta[i], lars2.Beta()[i], 1e-5);
|
||||
REQUIRE(beta[i] == Approx(lars2.Beta()[i]).epsilon(1e-7));
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that we learn the same when running training separately and through
|
||||
* constructor. Test it with default parameters.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(TrainingConstructorWithDefaultsTest)
|
||||
TEST_CASE("TrainingConstructorWithDefaultsTest", "[LARSTest]")
|
||||
{
|
||||
arma::mat X;
|
||||
arma::rowvec y;
|
||||
@@ -320,16 +317,16 @@ BOOST_AUTO_TEST_CASE(TrainingConstructorWithDefaultsTest)
|
||||
|
||||
LARS lars2(X, y);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(beta.n_elem, lars2.Beta().n_elem);
|
||||
REQUIRE(beta.n_elem == lars2.Beta().n_elem);
|
||||
for (size_t i = 0; i < beta.n_elem; ++i)
|
||||
BOOST_REQUIRE_CLOSE(beta[i], lars2.Beta()[i], 1e-5);
|
||||
REQUIRE(beta[i] == Approx(lars2.Beta()[i]).epsilon(1e-7));
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that we learn the same when running training separately and through
|
||||
* constructor. Test it with non default parameters.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(TrainingConstructorWithNonDefaultsTest)
|
||||
TEST_CASE("TrainingConstructorWithNonDefaultsTest", "[LARSTest]")
|
||||
{
|
||||
arma::mat X;
|
||||
arma::rowvec y;
|
||||
@@ -347,15 +344,15 @@ BOOST_AUTO_TEST_CASE(TrainingConstructorWithNonDefaultsTest)
|
||||
|
||||
LARS lars2(X, y, transposeData, useCholesky, lambda1, lambda2);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(beta.n_elem, lars2.Beta().n_elem);
|
||||
REQUIRE(beta.n_elem == lars2.Beta().n_elem);
|
||||
for (size_t i = 0; i < beta.n_elem; ++i)
|
||||
BOOST_REQUIRE_CLOSE(beta[i], lars2.Beta()[i], 1e-5);
|
||||
REQUIRE(beta[i] == Approx(lars2.Beta()[i]).epsilon(1e-7));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that LARS::Train() returns finite error value.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(LARSTrainReturnCorrelation)
|
||||
TEST_CASE("LARSTrainReturnCorrelation", "[LARSTest]")
|
||||
{
|
||||
arma::mat X;
|
||||
arma::mat Y;
|
||||
@@ -373,35 +370,35 @@ BOOST_AUTO_TEST_CASE(LARSTrainReturnCorrelation)
|
||||
arma::vec betaOpt1;
|
||||
double error = lars1.Train(X, y, betaOpt1);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(std::isfinite(error), true);
|
||||
REQUIRE(std::isfinite(error) == true);
|
||||
|
||||
// Test without Cholesky decomposition and with lasso.
|
||||
LARS lars2(false, lambda1, 0.0);
|
||||
arma::vec betaOpt2;
|
||||
error = lars2.Train(X, y, betaOpt2);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(std::isfinite(error), true);
|
||||
REQUIRE(std::isfinite(error) == true);
|
||||
|
||||
// Test with Cholesky decomposition and with elasticnet.
|
||||
LARS lars3(true, lambda1, lambda2);
|
||||
arma::vec betaOpt3;
|
||||
error = lars3.Train(X, y, betaOpt3);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(std::isfinite(error), true);
|
||||
REQUIRE(std::isfinite(error) == true);
|
||||
|
||||
// Test without Cholesky decomposition and with elasticnet.
|
||||
LARS lars4(false, lambda1, lambda2);
|
||||
arma::vec betaOpt4;
|
||||
error = lars4.Train(X, y, betaOpt4);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(std::isfinite(error), true);
|
||||
REQUIRE(std::isfinite(error) == true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that LARS::ComputeError() returns error value less than 1
|
||||
* and greater than 0.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(LARSTestComputeError)
|
||||
TEST_CASE("LARSTestComputeError", "[LARSTest]")
|
||||
{
|
||||
arma::mat X;
|
||||
arma::mat Y;
|
||||
@@ -416,15 +413,15 @@ BOOST_AUTO_TEST_CASE(LARSTestComputeError)
|
||||
double train1 = lars1.Train(X, y, betaOpt1);
|
||||
double cost = lars1.ComputeError(X, y);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(cost <= 1, true);
|
||||
BOOST_REQUIRE_EQUAL(cost >= 0, true);
|
||||
BOOST_REQUIRE_EQUAL(cost == train1, true);
|
||||
REQUIRE(cost <= 1);
|
||||
REQUIRE(cost >= 0);
|
||||
REQUIRE(cost == train1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple test for LARS copy constructor.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(LARSCopyConstructorTest)
|
||||
TEST_CASE("LARSCopyConstructorTest", "[LARSTest]")
|
||||
{
|
||||
arma::mat features, Y;
|
||||
arma::rowvec targets;
|
||||
@@ -447,13 +444,13 @@ BOOST_AUTO_TEST_CASE(LARSCopyConstructorTest)
|
||||
// The output of both models should be the same.
|
||||
CheckMatrices(predictions, predictionsFromCopiedModel);
|
||||
// Check if we can train the model again.
|
||||
BOOST_REQUIRE_NO_THROW(models[0].Train(features, targets));
|
||||
REQUIRE_NOTHROW(models[0].Train(features, targets));
|
||||
|
||||
// Check if we can train the copied model.
|
||||
mlpack::regression::LARS glm2(false, 0.1, 0.1);
|
||||
models.emplace_back(glm2); // Call the copy constructor.
|
||||
BOOST_REQUIRE_NO_THROW(glm2.Train(features, targets));
|
||||
BOOST_REQUIRE_NO_THROW(models[1].Train(features, targets));
|
||||
REQUIRE_NOTHROW(glm2.Train(features, targets));
|
||||
REQUIRE_NOTHROW(models[1].Train(features, targets));
|
||||
|
||||
// Create a copy using assignment operator.
|
||||
mlpack::regression::LARS glm3 = glm2;
|
||||
@@ -462,5 +459,3 @@ BOOST_AUTO_TEST_CASE(LARSCopyConstructorTest)
|
||||
// The output of both models should be the same.
|
||||
CheckMatrices(predictions, predictionsFromCopiedModel);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END();
|
||||
|
||||
@@ -15,18 +15,15 @@
|
||||
#include <mlpack/methods/ann/layer/layer_types.hpp>
|
||||
#include <mlpack/methods/ann/layer_names.hpp>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_tools.hpp"
|
||||
#include "catch.hpp"
|
||||
|
||||
using namespace mlpack;
|
||||
using namespace ann;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(LayerNamesTest);
|
||||
|
||||
/**
|
||||
* Test if the LayerNameVisitor works properly.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(LayerNameVisitorTest)
|
||||
TEST_CASE("LayerNameVisitorTest", "[LayerNamesTest]")
|
||||
{
|
||||
LayerTypes<> atrousConvolution = new AtrousConvolution<>();
|
||||
LayerTypes<> alphaDropout = new AlphaDropout<>();
|
||||
@@ -63,70 +60,70 @@ BOOST_AUTO_TEST_CASE(LayerNameVisitorTest)
|
||||
// Bilinear interpolation is not yet supported by the string converter.
|
||||
LayerTypes<> unsupportedLayer = new BilinearInterpolation<>();
|
||||
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
atrousConvolution) == "atrousconvolution");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
alphaDropout) == "alphadropout");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
batchNorm) == "batchnorm");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
constant) == "constant");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
convolution) == "convolution");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
dropConnect) == "dropconnect");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
dropout) == "dropout");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
flexibleReLU) == "flexiblerelu");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
layerNorm) == "layernorm");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
linear) == "linear");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
linearNoBias) == "linearnobias");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
maxPooling) == "maxpooling");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
meanPooling) == "meanpooling");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
multiplyConstant) == "multiplyconstant");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
reLULayer) == "relu");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
transposedConvolution) == "transposedconvolution");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
identityLayer) == "identity");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
tanHLayer) == "tanh");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
eLU) == "elu");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
hardTanH) == "hardtanh");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
leakyReLU) == "leakyrelu");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
pReLU) == "prelu");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
sigmoidLayer) == "sigmoid");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
logSoftMax) == "logsoftmax");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
unsupportedLayer) == "unsupported");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
lstmLayer) == "lstm");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
creluLayer) == "crelu");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
highwayLayer) == "highway");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
gruLayer) == "gru");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
glimpseLayer) == "glimpse");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
fastlstmLayer) == "fastlstm");
|
||||
BOOST_REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
weightnormLayer) == "weightnorm");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
atrousConvolution) == "atrousconvolution");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
alphaDropout) == "alphadropout");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
batchNorm) == "batchnorm");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
constant) == "constant");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
convolution) == "convolution");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
dropConnect) == "dropconnect");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
dropout) == "dropout");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
flexibleReLU) == "flexiblerelu");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
layerNorm) == "layernorm");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
linear) == "linear");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
linearNoBias) == "linearnobias");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
maxPooling) == "maxpooling");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
meanPooling) == "meanpooling");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
multiplyConstant) == "multiplyconstant");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
reLULayer) == "relu");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
transposedConvolution) == "transposedconvolution");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
identityLayer) == "identity");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
tanHLayer) == "tanh");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
eLU) == "elu");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
hardTanH) == "hardtanh");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
leakyReLU) == "leakyrelu");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
pReLU) == "prelu");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
sigmoidLayer) == "sigmoid");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
logSoftMax) == "logsoftmax");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
unsupportedLayer) == "unsupported");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
lstmLayer) == "lstm");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
creluLayer) == "crelu");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
highwayLayer) == "highway");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
gruLayer) == "gru");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
glimpseLayer) == "glimpse");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
fastlstmLayer) == "fastlstm");
|
||||
REQUIRE(boost::apply_visitor(LayerNameVisitor(),
|
||||
weightnormLayer) == "weightnorm");
|
||||
// Delete all instances.
|
||||
boost::apply_visitor(DeleteVisitor(), atrousConvolution);
|
||||
boost::apply_visitor(DeleteVisitor(), alphaDropout);
|
||||
@@ -161,5 +158,3 @@ BOOST_AUTO_TEST_CASE(LayerNameVisitorTest)
|
||||
boost::apply_visitor(DeleteVisitor(), fastlstmLayer);
|
||||
boost::apply_visitor(DeleteVisitor(), weightnormLayer);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END();
|
||||
|
||||
@@ -14,20 +14,18 @@
|
||||
#include <mlpack/core.hpp>
|
||||
#include <mlpack/core/math/lin_alg.hpp>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_tools.hpp"
|
||||
#include "catch.hpp"
|
||||
#include "test_catch_tools.hpp"
|
||||
|
||||
using namespace arma;
|
||||
using namespace mlpack;
|
||||
using namespace mlpack::math;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(LinAlgTest);
|
||||
|
||||
/**
|
||||
* Test for linalg__private::Center(). There are no edge cases here, so we'll
|
||||
* just try it once for now.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(TestCenterA)
|
||||
TEST_CASE("TestCenterA", "[LinAlgTest]")
|
||||
{
|
||||
mat tmp(5, 5);
|
||||
// [[0 0 0 0 0]
|
||||
@@ -51,11 +49,16 @@ BOOST_AUTO_TEST_CASE(TestCenterA)
|
||||
// [-6 -3 0 3 6 ]
|
||||
// [-8 -4 0 4 8]]
|
||||
for (int row = 0; row < 5; row++)
|
||||
{
|
||||
for (int col = 0; col < 5; col++)
|
||||
BOOST_REQUIRE_CLOSE(tmp_out(row, col), (double) (col - 2) * row, 1e-5);
|
||||
{
|
||||
REQUIRE(tmp_out(row, col) ==
|
||||
Approx((double) (col - 2) * row).epsilon(1e-7));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestCenterB)
|
||||
TEST_CASE("TestCenterB", "[LinAlgTest]")
|
||||
{
|
||||
mat tmp(5, 6);
|
||||
for (int row = 0; row < 5; row++)
|
||||
@@ -74,11 +77,16 @@ BOOST_AUTO_TEST_CASE(TestCenterB)
|
||||
// [-7.5 -4.5 -1.5 1.5 1.5 4.5]
|
||||
// [-10 -6 -2 2 6 10 ]]
|
||||
for (int row = 0; row < 5; row++)
|
||||
{
|
||||
for (int col = 0; col < 6; col++)
|
||||
BOOST_REQUIRE_CLOSE(tmp_out(row, col), (double) (col - 2.5) * row, 1e-5);
|
||||
{
|
||||
REQUIRE(tmp_out(row, col) ==
|
||||
Approx((double) (col - 2.5) * row).epsilon(1e-7));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestOrthogonalize)
|
||||
TEST_CASE("TestOrthogonalize", "[LinAlgTest]")
|
||||
{
|
||||
// Generate a random matrix; then, orthogonalize it and test if it's
|
||||
// orthogonal.
|
||||
@@ -96,18 +104,18 @@ BOOST_AUTO_TEST_CASE(TestOrthogonalize)
|
||||
if (row == col)
|
||||
{
|
||||
if (std::abs(test(row, col)) > 1e-10)
|
||||
BOOST_REQUIRE_CLOSE(test(row, col), ival, 1e-10);
|
||||
REQUIRE(test(row, col) == Approx(ival).epsilon(1e-11));
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_REQUIRE_SMALL(test(row, col), 1e-10);
|
||||
REQUIRE(test(row, col) == Approx(0.0).margin(1e-10));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test RemoveRows().
|
||||
BOOST_AUTO_TEST_CASE(TestRemoveRows)
|
||||
TEST_CASE("TestRemoveRows", "[LinAlgTest]")
|
||||
{
|
||||
// Run this test several times.
|
||||
for (size_t run = 0; run < 10; ++run)
|
||||
@@ -150,7 +158,7 @@ BOOST_AUTO_TEST_CASE(TestRemoveRows)
|
||||
else
|
||||
{
|
||||
// Compare.
|
||||
BOOST_REQUIRE_EQUAL(accu(input.row(row) == output.row(outputRow)), 200);
|
||||
REQUIRE(accu(input.row(row) == output.row(outputRow)) == 200);
|
||||
|
||||
// Increment output row counter.
|
||||
++outputRow;
|
||||
@@ -159,7 +167,7 @@ BOOST_AUTO_TEST_CASE(TestRemoveRows)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestSvecSmat)
|
||||
TEST_CASE("TestSvecSmat", "[LinAlgTest]")
|
||||
{
|
||||
arma::mat X(3, 3);
|
||||
X(0, 0) = 0; X(0, 1) = 1, X(0, 2) = 2;
|
||||
@@ -168,23 +176,24 @@ BOOST_AUTO_TEST_CASE(TestSvecSmat)
|
||||
|
||||
arma::vec sx;
|
||||
Svec(X, sx);
|
||||
BOOST_REQUIRE_CLOSE(sx(0), 0, 1e-7);
|
||||
BOOST_REQUIRE_CLOSE(sx(1), M_SQRT2 * 1., 1e-7);
|
||||
BOOST_REQUIRE_CLOSE(sx(2), M_SQRT2 * 2., 1e-7);
|
||||
BOOST_REQUIRE_CLOSE(sx(3), 3., 1e-7);
|
||||
BOOST_REQUIRE_CLOSE(sx(4), M_SQRT2 * 4., 1e-7);
|
||||
BOOST_REQUIRE_CLOSE(sx(5), 5., 1e-7);
|
||||
REQUIRE(sx(0) == Approx(0).epsilon(1e-9));
|
||||
REQUIRE(sx(1) == Approx(M_SQRT2 * 1.).epsilon(1e-9));
|
||||
REQUIRE(sx(2) == Approx(M_SQRT2 * 2.).epsilon(1e-9));
|
||||
REQUIRE(sx(3) == Approx(3.).epsilon(1e-9));
|
||||
REQUIRE(sx(4) == Approx(M_SQRT2 * 4.).epsilon(1e-9));
|
||||
REQUIRE(sx(5) == Approx(5.).epsilon(1e-9));
|
||||
|
||||
arma::mat Xtest;
|
||||
Smat(sx, Xtest);
|
||||
BOOST_REQUIRE_EQUAL(Xtest.n_rows, 3);
|
||||
BOOST_REQUIRE_EQUAL(Xtest.n_cols, 3);
|
||||
REQUIRE(Xtest.n_rows == 3);
|
||||
REQUIRE(Xtest.n_cols == 3);
|
||||
for (size_t i = 0; i < 3; ++i)
|
||||
for (size_t j = 0; j < 3; ++j)
|
||||
BOOST_REQUIRE_CLOSE(X(i, j), Xtest(i, j), 1e-7);
|
||||
REQUIRE(X(i, j) == Approx(Xtest(i, j)).epsilon(1e-9));
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestSparseSvec)
|
||||
TEST_CASE("TestSparseSvec", "[LinAlgTest]")
|
||||
{
|
||||
arma::sp_mat X;
|
||||
X.zeros(3, 3);
|
||||
@@ -200,15 +209,15 @@ BOOST_AUTO_TEST_CASE(TestSparseSvec)
|
||||
const double v4 = sx(4);
|
||||
const double v5 = sx(5);
|
||||
|
||||
BOOST_REQUIRE_CLOSE(v0, 0, 1e-7);
|
||||
BOOST_REQUIRE_CLOSE(v1, M_SQRT2 * 1., 1e-7);
|
||||
BOOST_REQUIRE_CLOSE(v2, 0, 1e-7);
|
||||
BOOST_REQUIRE_CLOSE(v3, 0, 1e-7);
|
||||
BOOST_REQUIRE_CLOSE(v4, 0, 1e-7);
|
||||
BOOST_REQUIRE_CLOSE(v5, 0, 1e-7);
|
||||
REQUIRE(v0 == Approx(0).epsilon(1e-9));
|
||||
REQUIRE(v1 == Approx(M_SQRT2 * 1.).epsilon(1e-9));
|
||||
REQUIRE(v2 == Approx(0).epsilon(1e-9));
|
||||
REQUIRE(v3 == Approx(0).epsilon(1e-9));
|
||||
REQUIRE(v4 == Approx(0).epsilon(1e-9));
|
||||
REQUIRE(v5 == Approx(0).epsilon(1e-9));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestSymKronIdSimple)
|
||||
TEST_CASE("TestSymKronIdSimple", "[LinAlgTest]")
|
||||
{
|
||||
arma::mat A(3, 3);
|
||||
A(0, 0) = 1; A(0, 1) = 2, A(0, 2) = 3;
|
||||
@@ -226,12 +235,12 @@ BOOST_AUTO_TEST_CASE(TestSymKronIdSimple)
|
||||
arma::vec rhs;
|
||||
Svec(Rhs, rhs);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(lhs.n_elem, rhs.n_elem);
|
||||
REQUIRE(lhs.n_elem == rhs.n_elem);
|
||||
for (size_t j = 0; j < lhs.n_elem; ++j)
|
||||
BOOST_REQUIRE_CLOSE(lhs(j), rhs(j), 1e-5);
|
||||
REQUIRE(lhs(j) == Approx(rhs(j)).epsilon(1e-7));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestSymKronId)
|
||||
TEST_CASE("TestSymKronId", "[LinAlgTest]")
|
||||
{
|
||||
const size_t n = 10;
|
||||
arma::mat A = arma::randu<arma::mat>(n, n);
|
||||
@@ -252,10 +261,8 @@ BOOST_AUTO_TEST_CASE(TestSymKronId)
|
||||
arma::vec rhs;
|
||||
Svec(Rhs, rhs);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(lhs.n_elem, rhs.n_elem);
|
||||
REQUIRE(lhs.n_elem == rhs.n_elem);
|
||||
for (size_t j = 0; j < lhs.n_elem; ++j)
|
||||
BOOST_REQUIRE_CLOSE(lhs(j), rhs(j), 1e-5);
|
||||
REQUIRE(lhs(j) == Approx(rhs(j)).epsilon(1e-7));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END();
|
||||
|
||||
@@ -17,7 +17,7 @@ static const std::string testName = "RangeSearchMain";
|
||||
#include "test_helper.hpp"
|
||||
#include <mlpack/methods/range_search/range_search_main.cpp>
|
||||
#include "range_search_utils.hpp"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "../catch.hpp"
|
||||
|
||||
using namespace mlpack;
|
||||
|
||||
@@ -37,34 +37,35 @@ struct RangeSearchTestFixture
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(RangeSearchMainTest, RangeSearchTestFixture);
|
||||
|
||||
/**
|
||||
* Check that we have to specify a reference set or input model.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(RangeSearchNoReference)
|
||||
TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchNoReference",
|
||||
"[RangeSearchMainTest][BindingTests]")
|
||||
{
|
||||
Log::Fatal.ignoreInput = true;
|
||||
BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error);
|
||||
REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error);
|
||||
Log::Fatal.ignoreInput = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that we cannot pass an incorrect parameter.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(RangeSearchWrongParameter)
|
||||
TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchWrongParameter",
|
||||
"[RangeSearchMainTest][BindingTests]")
|
||||
{
|
||||
string wrongString = "abc";
|
||||
|
||||
Log::Fatal.ignoreInput = true;
|
||||
BOOST_REQUIRE_THROW(SetInputParam("RST", wrongString), std::runtime_error);
|
||||
REQUIRE_THROWS_AS(SetInputParam("RST", wrongString), std::runtime_error);
|
||||
Log::Fatal.ignoreInput = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that we have to specify a query if an input model is specified.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(RangeSearchInputModelNoQuery)
|
||||
TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchInputModelNoQuery",
|
||||
"[RangeSearchMainTest][BindingTests]")
|
||||
{
|
||||
arma::mat inputData;
|
||||
double minVal = 0, maxVal = 3;
|
||||
@@ -72,7 +73,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchInputModelNoQuery)
|
||||
string neighborsFile = "neighbors.csv";
|
||||
|
||||
if (!data::Load("iris.csv", inputData))
|
||||
BOOST_FAIL("Unable to load dataset iris.csv!");
|
||||
FAIL("Unable to load dataset iris.csv!");
|
||||
|
||||
SetInputParam("reference", move(inputData));
|
||||
SetInputParam("min", minVal);
|
||||
@@ -86,7 +87,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchInputModelNoQuery)
|
||||
SetInputParam("input_model", move(IO::GetParam<RSModel*>("output_model")));
|
||||
|
||||
Log::Fatal.ignoreInput = true;
|
||||
BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error);
|
||||
REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error);
|
||||
Log::Fatal.ignoreInput = false;
|
||||
|
||||
remove(neighborsFile.c_str());
|
||||
@@ -96,7 +97,8 @@ BOOST_AUTO_TEST_CASE(RangeSearchInputModelNoQuery)
|
||||
/**
|
||||
* Check that we cannot specify a tree type which is not available or wrong.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(RangeSearchDifferentTree)
|
||||
TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchDifferentTree",
|
||||
"[RangeSearchMainTest][BindingTests]")
|
||||
{
|
||||
arma::mat inputData;
|
||||
double minVal = 0, maxVal = 3;
|
||||
@@ -104,7 +106,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchDifferentTree)
|
||||
string neighborsFile = "neighbors.csv";
|
||||
string wrongTreeType = "RST";
|
||||
if (!data::Load("iris.csv", inputData))
|
||||
BOOST_FAIL("Unable to load dataset iris.csv!");
|
||||
FAIL("Unable to load dataset iris.csv!");
|
||||
|
||||
SetInputParam("reference", move(inputData));
|
||||
SetInputParam("min", minVal);
|
||||
@@ -114,7 +116,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchDifferentTree)
|
||||
SetInputParam("tree_type", wrongTreeType);
|
||||
|
||||
Log::Fatal.ignoreInput = true;
|
||||
BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error);
|
||||
REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error);
|
||||
Log::Fatal.ignoreInput = false;
|
||||
|
||||
remove(neighborsFile.c_str());
|
||||
@@ -124,7 +126,8 @@ BOOST_AUTO_TEST_CASE(RangeSearchDifferentTree)
|
||||
/**
|
||||
* Check that we cannot specify both a reference set and input model.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(RangeSearchBothReferenceAndModel)
|
||||
TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchBothReferenceAndModel",
|
||||
"[RangeSearchMainTest][BindingTests]")
|
||||
{
|
||||
arma::mat inputData, queryData;
|
||||
double minVal = 0, maxVal = 3;
|
||||
@@ -132,9 +135,9 @@ BOOST_AUTO_TEST_CASE(RangeSearchBothReferenceAndModel)
|
||||
string neighborsFile = "neighbors.csv";
|
||||
|
||||
if (!data::Load("iris.csv", inputData))
|
||||
BOOST_FAIL("Unable to load dataset iris.csv!");
|
||||
FAIL("Unable to load dataset iris.csv!");
|
||||
if (!data::Load("iris_test.csv", queryData))
|
||||
BOOST_FAIL("Unable to load dataset iris_test.csv!");
|
||||
FAIL("Unable to load dataset iris_test.csv!");
|
||||
|
||||
SetInputParam("reference", move(inputData));
|
||||
SetInputParam("min", minVal);
|
||||
@@ -149,7 +152,7 @@ BOOST_AUTO_TEST_CASE(RangeSearchBothReferenceAndModel)
|
||||
SetInputParam("query", move(queryData));
|
||||
|
||||
Log::Fatal.ignoreInput = true;
|
||||
BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error);
|
||||
REQUIRE_THROWS_AS(mlpackMain(), std::runtime_error);
|
||||
Log::Fatal.ignoreInput = false;
|
||||
|
||||
remove(neighborsFile.c_str());
|
||||
@@ -161,7 +164,8 @@ BOOST_AUTO_TEST_CASE(RangeSearchBothReferenceAndModel)
|
||||
* by comparing with pre-calculated neighbor and distance values, when no query
|
||||
* set is specified.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(RangeSearchTest)
|
||||
TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSearchTest",
|
||||
"[RangeSearchMainTest][BindingTests]")
|
||||
{
|
||||
arma::mat x = {{0, 3, 3, 4, 3, 1},
|
||||
{4, 4, 4, 5, 5, 2},
|
||||
@@ -208,7 +212,8 @@ BOOST_AUTO_TEST_CASE(RangeSearchTest)
|
||||
* Check that the correct output is returned for a small synthetic input case,
|
||||
* when a query set is provided.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(RangeSeachTestwithQuery)
|
||||
TEST_CASE_METHOD(RangeSearchTestFixture, "RangeSeachTestwithQuery",
|
||||
"[RangeSearchMainTest][BindingTests]")
|
||||
{
|
||||
arma::mat queryData = {{5, 3, 1}, {4, 2, 4}, {3, 1, 7}};
|
||||
arma::mat x = {{0, 3, 3, 4, 3, 1},
|
||||
@@ -252,7 +257,8 @@ BOOST_AUTO_TEST_CASE(RangeSeachTestwithQuery)
|
||||
* Train a model using a synthetic dataset and then output the model, and ensure
|
||||
* it can be used again.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(ModelCheck)
|
||||
TEST_CASE_METHOD(RangeSearchTestFixture, "ModelCheck",
|
||||
"[RangeSearchMainTest][BindingTests]")
|
||||
{
|
||||
arma::mat inputData, queryData;
|
||||
double minVal = 0, maxVal = 3;
|
||||
@@ -262,9 +268,9 @@ BOOST_AUTO_TEST_CASE(ModelCheck)
|
||||
vector<vector<double>> distances, distancetemp;
|
||||
|
||||
if (!data::Load("iris.csv", inputData))
|
||||
BOOST_FAIL("Unable to load dataset iris.csv!");
|
||||
FAIL("Unable to load dataset iris.csv!");
|
||||
if (!data::Load("iris_test.csv", queryData))
|
||||
BOOST_FAIL("Unable to load dataset iris_test.csv!");
|
||||
FAIL("Unable to load dataset iris_test.csv!");
|
||||
|
||||
SetInputParam("reference", move(inputData));
|
||||
SetInputParam("min", minVal);
|
||||
@@ -292,8 +298,8 @@ BOOST_AUTO_TEST_CASE(ModelCheck)
|
||||
CheckMatrices(neighbors, neighborsTemp);
|
||||
CheckMatrices(distances, distancetemp);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(ModelToString(outputModel),
|
||||
ModelToString(IO::GetParam<RSModel*>("output_model")));
|
||||
REQUIRE(ModelToString(outputModel) ==
|
||||
ModelToString(IO::GetParam<RSModel*>("output_model")));
|
||||
|
||||
remove(neighborsFile.c_str());
|
||||
remove(distanceFile.c_str());
|
||||
@@ -303,11 +309,12 @@ BOOST_AUTO_TEST_CASE(ModelCheck)
|
||||
* Check that the models are different but the results are the same for three
|
||||
* different leaf size parameters.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(LeafValueTesting)
|
||||
TEST_CASE_METHOD(RangeSearchTestFixture, "LeafValueTesting",
|
||||
"[RangeSearchMainTest][BindingTests]")
|
||||
{
|
||||
arma::mat inputData;
|
||||
if (!data::Load("iris.csv", inputData))
|
||||
BOOST_FAIL("Unable to load dataset iris.csv!");
|
||||
FAIL("Unable to load dataset iris.csv!");
|
||||
|
||||
string distanceFile = "distances.csv";
|
||||
string neighborsFile = "neighbors.csv";
|
||||
@@ -349,8 +356,8 @@ BOOST_AUTO_TEST_CASE(LeafValueTesting)
|
||||
CheckMatrices(neighbors, neighborsTemp);
|
||||
CheckMatrices(distances, distancestemp);
|
||||
|
||||
BOOST_REQUIRE_NE(ModelToString(outputModel1),
|
||||
ModelToString(IO::GetParam<RSModel*>("output_model")));
|
||||
REQUIRE(ModelToString(outputModel1) !=
|
||||
ModelToString(IO::GetParam<RSModel*>("output_model")));
|
||||
|
||||
if (i != leafSizes.size() - 1)
|
||||
delete IO::GetParam<RSModel*>("output_model");
|
||||
@@ -367,7 +374,8 @@ BOOST_AUTO_TEST_CASE(LeafValueTesting)
|
||||
* different tree types. We use the default kd-tree as the base model to
|
||||
* compare against.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(TreeTypeTesting)
|
||||
TEST_CASE_METHOD(RangeSearchTestFixture, "TreeTypeTesting",
|
||||
"[RangeSearchMainTest][BindingTests]")
|
||||
{
|
||||
string distanceFile = "distances.csv";
|
||||
string neighborsFile = "neighbors.csv";
|
||||
@@ -381,9 +389,9 @@ BOOST_AUTO_TEST_CASE(TreeTypeTesting)
|
||||
"max-rp", "ub", "oct"};
|
||||
|
||||
if (!data::Load("iris.csv", inputData))
|
||||
BOOST_FAIL("Unable to load dataset iris.csv!");
|
||||
FAIL("Unable to load dataset iris.csv!");
|
||||
if (!data::Load("iris_test.csv", queryData))
|
||||
BOOST_FAIL("Unable to load dataset iris_test.csv!");
|
||||
FAIL("Unable to load dataset iris_test.csv!");
|
||||
|
||||
// Define base parameters with the kd-tree.
|
||||
SetInputParam("tree_type", trees[0]);
|
||||
@@ -403,9 +411,9 @@ BOOST_AUTO_TEST_CASE(TreeTypeTesting)
|
||||
for (size_t i = 1; i < trees.size(); ++i)
|
||||
{
|
||||
if (!data::Load("iris.csv", inputData))
|
||||
BOOST_FAIL("Unable to load dataset iris.csv!");
|
||||
FAIL("Unable to load dataset iris.csv!");
|
||||
if (!data::Load("iris_test.csv", queryData))
|
||||
BOOST_FAIL("Unable to load dataset iris_test.csv!");
|
||||
FAIL("Unable to load dataset iris_test.csv!");
|
||||
|
||||
SetInputParam("min", minVal);
|
||||
SetInputParam("max", maxVal);
|
||||
@@ -422,8 +430,8 @@ BOOST_AUTO_TEST_CASE(TreeTypeTesting)
|
||||
|
||||
CheckMatrices(neighbors, neighborsTemp);
|
||||
CheckMatrices(distances, distancestemp);
|
||||
BOOST_REQUIRE_NE(ModelToString(outputModel1),
|
||||
ModelToString(IO::GetParam<RSModel*>("output_model")));
|
||||
REQUIRE(ModelToString(outputModel1) !=
|
||||
ModelToString(IO::GetParam<RSModel*>("output_model")));
|
||||
|
||||
if (i != trees.size() - 1)
|
||||
delete IO::GetParam<RSModel*>("output_model");
|
||||
@@ -439,7 +447,8 @@ BOOST_AUTO_TEST_CASE(TreeTypeTesting)
|
||||
* Project the data onto a random basis and ensure that this gives identical
|
||||
* results to non-projected data but different models.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(RandomBasisTesting)
|
||||
TEST_CASE_METHOD(RangeSearchTestFixture, "RandomBasisTesting",
|
||||
"[RangeSearchMainTest][BindingTests]")
|
||||
{
|
||||
string distanceFile = "distances.csv";
|
||||
string neighborsFile = "neighbors.csv";
|
||||
@@ -447,9 +456,9 @@ BOOST_AUTO_TEST_CASE(RandomBasisTesting)
|
||||
|
||||
arma::mat queryData, inputData;
|
||||
if (!data::Load("iris.csv", inputData))
|
||||
BOOST_FAIL("Unable to load dataset iris.csv!");
|
||||
FAIL("Unable to load dataset iris.csv!");
|
||||
if (!data::Load("iris_test.csv", queryData))
|
||||
BOOST_FAIL("Unable to load dataset iris_test.csv!");
|
||||
FAIL("Unable to load dataset iris_test.csv!");
|
||||
|
||||
SetInputParam("min", minVal);
|
||||
SetInputParam("max", maxVal);
|
||||
@@ -470,8 +479,8 @@ BOOST_AUTO_TEST_CASE(RandomBasisTesting)
|
||||
|
||||
mlpackMain();
|
||||
|
||||
BOOST_REQUIRE_NE(ModelToString(outputModel),
|
||||
ModelToString(IO::GetParam<RSModel*>("output_model")));
|
||||
REQUIRE(ModelToString(outputModel) !=
|
||||
ModelToString(IO::GetParam<RSModel*>("output_model")));
|
||||
|
||||
delete outputModel;
|
||||
|
||||
@@ -482,7 +491,8 @@ BOOST_AUTO_TEST_CASE(RandomBasisTesting)
|
||||
/**
|
||||
* Ensure that naive mode gives the same result, but different models.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(NaiveModeTest)
|
||||
TEST_CASE_METHOD(RangeSearchTestFixture, "NaiveModeTest",
|
||||
"[RangeSearchMainTest][BindingTests]")
|
||||
{
|
||||
string distanceFile = "distances.csv";
|
||||
string neighborsFile = "neighbors.csv";
|
||||
@@ -493,9 +503,9 @@ BOOST_AUTO_TEST_CASE(NaiveModeTest)
|
||||
vector<vector<double>> distances, distancestemp;
|
||||
|
||||
if (!data::Load("iris.csv", inputData))
|
||||
BOOST_FAIL("Unable to load dataset iris.csv!");
|
||||
FAIL("Unable to load dataset iris.csv!");
|
||||
if (!data::Load("iris_test.csv", queryData))
|
||||
BOOST_FAIL("Unable to load dataset iris_test.csv!");
|
||||
FAIL("Unable to load dataset iris_test.csv!");
|
||||
|
||||
SetInputParam("min", minVal);
|
||||
SetInputParam("max", maxVal);
|
||||
@@ -524,8 +534,8 @@ BOOST_AUTO_TEST_CASE(NaiveModeTest)
|
||||
CheckMatrices(neighbors, neighborsTemp);
|
||||
CheckMatrices(distances, distancestemp);
|
||||
|
||||
BOOST_REQUIRE_NE(ModelToString(outputModel),
|
||||
ModelToString(IO::GetParam<RSModel*>("output_model")));
|
||||
REQUIRE(ModelToString(outputModel) !=
|
||||
ModelToString(IO::GetParam<RSModel*>("output_model")));
|
||||
|
||||
delete outputModel;
|
||||
|
||||
@@ -536,7 +546,8 @@ BOOST_AUTO_TEST_CASE(NaiveModeTest)
|
||||
/**
|
||||
* Ensure that single-tree mode gives the same result but different models.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(SingleModeTest)
|
||||
TEST_CASE_METHOD(RangeSearchTestFixture, "SingleModeTest",
|
||||
"[RangeSearchMainTest][BindingTests]")
|
||||
{
|
||||
string distanceFile = "distances.csv";
|
||||
string neighborsFile = "neighbors.csv";
|
||||
@@ -547,9 +558,9 @@ BOOST_AUTO_TEST_CASE(SingleModeTest)
|
||||
vector<vector<double>> distances, distancestemp;
|
||||
|
||||
if (!data::Load("iris.csv", inputData))
|
||||
BOOST_FAIL("Unable to load dataset iris.csv!");
|
||||
FAIL("Unable to load dataset iris.csv!");
|
||||
if (!data::Load("iris_test.csv", queryData))
|
||||
BOOST_FAIL("Unable to load dataset iris_test.csv!");
|
||||
FAIL("Unable to load dataset iris_test.csv!");
|
||||
|
||||
SetInputParam("min", minVal);
|
||||
SetInputParam("max", maxVal);
|
||||
@@ -577,13 +588,11 @@ BOOST_AUTO_TEST_CASE(SingleModeTest)
|
||||
|
||||
CheckMatrices(neighbors, neighborsTemp);
|
||||
CheckMatrices(distances, distancestemp);
|
||||
BOOST_REQUIRE_NE(ModelToString(outputModel),
|
||||
ModelToString(IO::GetParam<RSModel*>("output_model")));
|
||||
REQUIRE(ModelToString(outputModel) !=
|
||||
ModelToString(IO::GetParam<RSModel*>("output_model")));
|
||||
|
||||
delete outputModel;
|
||||
|
||||
remove(neighborsFile.c_str());
|
||||
remove(distanceFile.c_str());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END();
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
#ifndef MLPACK_TESTS_MAIN_TESTS_RANGE_SEARCH_TEST_UTILS_HPP
|
||||
#define MLPACK_TESTS_MAIN_TESTS_RANGE_SEARCH_TEST_UTILS_HPP
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <mlpack/methods/range_search/rs_model.hpp>
|
||||
#include <mlpack/core.hpp>
|
||||
#include <mlpack/core/util/mlpack_main.hpp>
|
||||
#include "../catch.hpp"
|
||||
|
||||
/**
|
||||
* Convert a model to a string using the text_oarchive of boost::serialization.
|
||||
@@ -42,15 +42,15 @@ inline void CheckMatrices(std::vector<std::vector<double>>& vec1,
|
||||
std::vector<std::vector<double>>& vec2,
|
||||
const double tolerance = 1e-3)
|
||||
{
|
||||
BOOST_REQUIRE_EQUAL(vec1.size() , vec2.size());
|
||||
REQUIRE(vec1.size() == vec2.size());
|
||||
for (size_t i = 0; i < vec1.size(); ++i)
|
||||
{
|
||||
BOOST_REQUIRE_EQUAL(vec1[i].size(), vec2[i].size());
|
||||
REQUIRE(vec1[i].size() == vec2[i].size());
|
||||
std::sort(vec1[i].begin(), vec1[i].end());
|
||||
std::sort(vec2[i].begin(), vec2[i].end());
|
||||
for (size_t j = 0 ; j < vec1[i].size(); ++j)
|
||||
{
|
||||
BOOST_REQUIRE_CLOSE(vec1[i][j], vec2[i][j], tolerance);
|
||||
REQUIRE(vec1[i][j] == Approx(vec2[i][j]).epsilon(tolerance));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,15 +64,15 @@ inline void CheckMatrices(std::vector<std::vector<double>>& vec1,
|
||||
inline void CheckMatrices(std::vector<std::vector<size_t>>& vec1,
|
||||
std::vector<std::vector<size_t>>& vec2)
|
||||
{
|
||||
BOOST_REQUIRE_EQUAL(vec1.size() , vec2.size());
|
||||
REQUIRE(vec1.size() == vec2.size());
|
||||
for (size_t i = 0; i < vec1.size(); ++i)
|
||||
{
|
||||
BOOST_REQUIRE_EQUAL(vec1[i].size(), vec2[i].size());
|
||||
REQUIRE(vec1[i].size() == vec2[i].size());
|
||||
std::sort(vec1[i].begin(), vec1[i].end());
|
||||
std::sort(vec2[i].begin(), vec2[i].end());
|
||||
for (size_t j = 0; j < vec1[i].size(); ++j)
|
||||
{
|
||||
BOOST_REQUIRE_EQUAL(vec1[i][j], vec2[i][j]);
|
||||
REQUIRE(vec1[i][j] == vec2[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user