[mlpack] 36/44: Refactor test to handle random failures.

Barak A. Pearlmutter barak+git at pearlmutter.net
Mon Feb 15 19:35:55 UTC 2016


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to tag mlpack-1.0.11
in repository mlpack.

commit 4d6ed991ea256beebde9916c99745b3575a93e54
Author: Ryan Curtin <ryan at ratml.org>
Date:   Mon Dec 8 18:46:52 2014 +0000

    Refactor test to handle random failures.
---
 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();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list