[mlpack-git] mlpack-1.0.x: Refactor test to handle random failures. (4d6ed99)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:07:37 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : mlpack-1.0.x
Link : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40
>---------------------------------------------------------------
commit 4d6ed991ea256beebde9916c99745b3575a93e54
Author: Ryan Curtin <ryan at ratml.org>
Date: Mon Dec 8 18:46:52 2014 +0000
Refactor test to handle random failures.
>---------------------------------------------------------------
4d6ed991ea256beebde9916c99745b3575a93e54
src/mlpack/tests/quic_svd_test.cpp | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/src/mlpack/tests/quic_svd_test.cpp b/src/mlpack/tests/quic_svd_test.cpp
index 54e2e3c..5ea94ac 100644
--- a/src/mlpack/tests/quic_svd_test.cpp
+++ b/src/mlpack/tests/quic_svd_test.cpp
@@ -40,18 +40,31 @@ BOOST_AUTO_TEST_CASE(QUICSVDReconstructionError)
arma::mat dataset;
data::Load("test_data_3_1000.csv", dataset);
- // Obtain the SVD using default parameters.
- arma::mat u, v, sigma;
- QUIC_SVD quicsvd(dataset, u, v, sigma);
-
- // Reconstruct the matrix using the SVD.
- arma::mat reconstruct;
- reconstruct = u * sigma * v.t();
-
- // The relative reconstruction error should be small.
- double relativeError = arma::norm(dataset - reconstruct, "frob") /
- arma::norm(dataset, "frob");
- BOOST_REQUIRE_SMALL(relativeError, 1e-5);
+ // Since QUIC-SVD may have random errors, run up to three trials to get a good
+ // results.
+ size_t successes = 0;
+ size_t trial = 0;
+
+ while (trial < 3 && successes < 1)
+ {
+ // Obtain the SVD using default parameters.
+ arma::mat u, v, sigma;
+ QUIC_SVD quicsvd(dataset, u, v, sigma);
+
+ // Reconstruct the matrix using the SVD.
+ arma::mat reconstruct;
+ reconstruct = u * sigma * v.t();
+
+ // The relative reconstruction error should be small.
+ double relativeError = arma::norm(dataset - reconstruct, "frob") /
+ arma::norm(dataset, "frob");
+ if (relativeError < 1e-5)
+ ++successes;
+
+ ++trial;
+ }
+
+ BOOST_REQUIRE_GE(successes, 1);
}
BOOST_AUTO_TEST_SUITE_END();
More information about the mlpack-git
mailing list