From 920d86ce354e86eb8131bc4520164cb5978a444a Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Sun, 7 Mar 2010 17:51:46 +0000 Subject: [PATCH] Both GaussNewton and LM now exit immediately if initial error=ERROR --- cpp/NonlinearOptimizer-inl.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cpp/NonlinearOptimizer-inl.h b/cpp/NonlinearOptimizer-inl.h index 285b4a127..634b1860b 100644 --- a/cpp/NonlinearOptimizer-inl.h +++ b/cpp/NonlinearOptimizer-inl.h @@ -101,6 +101,13 @@ namespace gtsam { verbosityLevel verbosity, int maxIterations) const { static W writer(error_); + // check if we're already close enough + if (error_ < absoluteThreshold) { + if (verbosity >= ERROR) cout << "Exiting, as error = " << error_ + << " < absoluteThreshold (" << absoluteThreshold << ")" << endl; + return *this; + } + // linearize, solve, update NonlinearOptimizer next = iterate(verbosity); @@ -191,8 +198,11 @@ namespace gtsam { verbosityLevel verbosity, int maxIterations, double lambdaFactor) const { // check if we're already close enough - if (error_ < absoluteThreshold) + if (error_ < absoluteThreshold) { + if (verbosity >= ERROR) cout << "Exiting, as error = " << error_ + << " < absoluteThreshold (" << absoluteThreshold << ")" << endl; return *this; + } // do one iteration of LM NonlinearOptimizer next = iterateLM(verbosity, lambdaFactor);