[mlpack-git] master: Fix logistic regression tests by enforcing a tighter tolerance for SGD convergence. The changes introduced to SGD in r17196 to cause SGD to shuffle also caused situations where SGD can converge way too early, causing the two tests to fail. Tightening the tolerance to 1e-10 appears to be the solution to this issue. (82188da)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:02:21 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

>---------------------------------------------------------------

commit 82188dad0b887a6773a616313717f0b301743a99
Author: Ryan Curtin <ryan at ratml.org>
Date:   Wed Nov 5 19:27:15 2014 +0000

    Fix logistic regression tests by enforcing a tighter tolerance for SGD
    convergence.  The changes introduced to SGD in r17196 to cause SGD to shuffle
    also caused situations where SGD can converge way too early, causing the two
    tests to fail.  Tightening the tolerance to 1e-10 appears to be the solution to
    this issue.


>---------------------------------------------------------------

82188dad0b887a6773a616313717f0b301743a99
 src/mlpack/tests/logistic_regression_test.cpp | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/mlpack/tests/logistic_regression_test.cpp b/src/mlpack/tests/logistic_regression_test.cpp
index f12db1a..69dabb4 100644
--- a/src/mlpack/tests/logistic_regression_test.cpp
+++ b/src/mlpack/tests/logistic_regression_test.cpp
@@ -495,8 +495,11 @@ BOOST_AUTO_TEST_CASE(LogisticRegressionSGDSimpleTest)
                  "1 2 3");
   arma::vec responses("1 1 0");
 
-  // Create a logistic regression object using SGD.
-  LogisticRegression<SGD> lr(data, responses);
+  // Create a logistic regression object using a custom SGD object with a much
+  // smaller tolerance.
+  LogisticRegressionFunction lrf(data, responses, 0.001);
+  SGD<LogisticRegressionFunction> sgd(lrf, 0.01, 100000, 1e-10);
+  LogisticRegression<SGD> lr(sgd);
 
   // Test sigmoid function.
   arma::vec sigmoids = 1 / (1 + arma::exp(-lr.Parameters()[0]
@@ -536,13 +539,17 @@ BOOST_AUTO_TEST_CASE(LogisticRegressionLBFGSRegularizationSimpleTest)
 // regularization.
 BOOST_AUTO_TEST_CASE(LogisticRegressionSGDRegularizationSimpleTest)
 {
+  math::RandomSeed(std::time(NULL));
   // Very simple fake dataset.
   arma::mat data("1 2 3;"
                  "1 2 3");
   arma::vec responses("1 1 0");
 
-  // Create a logistic regression object using SGD.
-  LogisticRegression<SGD> lr(data, responses, 0.001);
+  // Create a logistic regression object using custom SGD with a much smaller
+  // tolerance.
+  LogisticRegressionFunction lrf(data, responses, 0.001);
+  SGD<LogisticRegressionFunction> sgd(lrf, 0.01, 100000, 1e-10);
+  LogisticRegression<SGD> lr(sgd);
 
   // Test sigmoid function.
   arma::vec sigmoids = 1 / (1 + arma::exp(-lr.Parameters()[0]
@@ -582,7 +589,6 @@ BOOST_AUTO_TEST_CASE(LogisticRegressionLBFGSGaussianTest)
 
   // Ensure that the error is close to zero.
   const double acc = lr.ComputeAccuracy(data, responses);
-
   BOOST_REQUIRE_CLOSE(acc, 100.0, 0.3); // 0.3% error tolerance.
 
   // Create a test set.



More information about the mlpack-git mailing list