Make LineSearchMinizer work correctly with negative valued functions.

When reasoning about the function_tolerance based convergence,
LineSearchMinimizer assumed that the objective function is
positive. This used to be the case when LineSearchMinimizer was used
for minimizing non-linear least squares problems. However, with
GradientProblemSolver, the objective function can be negative (for
example when maximizing a function).

This change the minimizer to use the absolute value of the change
from one iteration to another.

https://github.com/ceres-solver/ceres-solver/issues/478

Change-Id: I831e2db96b092374e167c582ab1480b1831d5650
This commit is contained in:
Sameer Agarwal
2019-05-13 10:20:50 -07:00
parent 3ff12a878b
commit 3e2cdca542
+8 -8
View File
@@ -429,14 +429,14 @@ void LineSearchMinimizer::Minimize(const Minimizer::Options& options,
}
const double absolute_function_tolerance =
options.function_tolerance * previous_state.cost;
if (fabs(iteration_summary.cost_change) <= absolute_function_tolerance) {
summary->message =
StringPrintf("Function tolerance reached. "
"|cost_change|/cost: %e <= %e",
fabs(iteration_summary.cost_change) /
previous_state.cost,
options.function_tolerance);
options.function_tolerance * std::abs(previous_state.cost);
if (std::abs(iteration_summary.cost_change) <=
absolute_function_tolerance) {
summary->message = StringPrintf(
"Function tolerance reached. "
"|cost_change|/cost: %e <= %e",
std::abs(iteration_summary.cost_change) / previous_state.cost,
options.function_tolerance);
summary->termination_type = CONVERGENCE;
VLOG_IF(1, is_not_silent) << "Terminating: " << summary->message;
break;