Skip to content

Commit

Permalink
Merge pull request #585 from borglab/feature/lm-iteration-hook
Browse files Browse the repository at this point in the history
Avoid redundant calls to error() in NonLinearOptimizer
  • Loading branch information
varunagrawal authored Nov 8, 2020
2 parents 8d6bbd9 + c5c54da commit a765231
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions gtsam/nonlinear/NonlinearOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,24 @@ void NonlinearOptimizer::defaultOptimize() {
}

// Iterative loop
double newError = currentError; // used to avoid repeated calls to error()
do {
// Do next iteration
currentError = error(); // TODO(frank): don't do this twice at first !? Computed above!
currentError = newError;
iterate();
tictoc_finishedIteration();

// Update newError for either printouts or conditional-end checks:
newError = error();

// Maybe show output
if (params.verbosity >= NonlinearOptimizerParams::VALUES)
values().print("newValues");
if (params.verbosity >= NonlinearOptimizerParams::ERROR)
cout << "newError: " << error() << endl;
cout << "newError: " << newError << endl;
} while (iterations() < params.maxIterations &&
!checkConvergence(params.relativeErrorTol, params.absoluteErrorTol, params.errorTol,
currentError, error(), params.verbosity) && std::isfinite(currentError));
currentError, newError, params.verbosity) && std::isfinite(currentError));

// Printing if verbose
if (params.verbosity >= NonlinearOptimizerParams::TERMINATION) {
Expand Down

0 comments on commit a765231

Please sign in to comment.