[mlpack] 69/149: 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.

Barak A. Pearlmutter barak+git at pearlmutter.net
Sat May 2 09:11:10 UTC 2015


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

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit 68784d2a3a222cabc7ebd8fdced6b90ffe3f8ca1
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
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.
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@17297 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 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.

-- 
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