[mlpack-git] master: Break the optimization if we encounter a NaN value. (62a7f8d)

gitdub at mlpack.org gitdub at mlpack.org
Wed Aug 24 11:58:08 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/1c77230c7d3b9c45fb102cd3c632d9c7248e085e...62a7f8db54f214b1ed75ea86b8162907985f1fd2

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

commit 62a7f8db54f214b1ed75ea86b8162907985f1fd2
Author: Ryan Curtin <ryan at ratml.org>
Date:   Wed Aug 24 11:57:53 2016 -0400

    Break the optimization if we encounter a NaN value.


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

62a7f8db54f214b1ed75ea86b8162907985f1fd2
 src/mlpack/core/optimizers/lbfgs/lbfgs_impl.hpp | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/mlpack/core/optimizers/lbfgs/lbfgs_impl.hpp b/src/mlpack/core/optimizers/lbfgs/lbfgs_impl.hpp
index 918d0b2..81d3ab3 100644
--- a/src/mlpack/core/optimizers/lbfgs/lbfgs_impl.hpp
+++ b/src/mlpack/core/optimizers/lbfgs/lbfgs_impl.hpp
@@ -221,15 +221,7 @@ bool L_BFGS<FunctionType>::LineSearch(double& functionValue,
     const bool cond2 = (stepSize > maxStep);
     const bool cond3 = (numIterations >= maxLineSearchTrials);
     if (cond1 || cond2 || cond3)
-    {
-      if (cond1)
-        Log::Debug << "stepSize < minStep" << std::endl;
-      if (cond2)
-        Log::Debug << "stepSize > maxStep" << std::endl;
-      if (cond3)
-        Log::Debug << "numIterations >= maxLineSearchTrials (stepSize=" << stepSize << ")" << std::endl;
       break;
-    }
 
     // Scale the step size.
     stepSize *= width;
@@ -403,6 +395,15 @@ double L_BFGS<FunctionType>::Optimize(arma::mat& iterate,
       break;
     }
 
+    // Break if the objective is not a number.
+    if (std::isnan(functionValue))
+    {
+      Log::Warn << "L-BFGS terminated with objective " << functionValue << "; "
+          << "are the objective and gradient functions implemented correctly?"
+          << std::endl;
+      break;
+    }
+
     // Choose the scaling factor.
     double scalingFactor = ChooseScalingFactor(itNum, gradient);
 
@@ -431,7 +432,7 @@ double L_BFGS<FunctionType>::Optimize(arma::mat& iterate,
     }
 
     // If we can't make progress on the gradient, then we'll also accept
-    // a stable function value
+    // a stable function value.
     const double denom =
       std::max(
         std::max(fabs(prevFunctionValue), fabs(functionValue)),




More information about the mlpack-git mailing list