blob: 1093bad08b0e142e747b5784c8251639aab0aa0e [file] [log] [blame]
Sameer Agarwalf4d01642012-11-26 12:55:58 -08001// Ceres Solver - A fast non-linear least squares minimizer
2// Copyright 2012 Google Inc. All rights reserved.
3// http://code.google.com/p/ceres-solver/
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are met:
7//
8// * Redistributions of source code must retain the above copyright notice,
9// this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above copyright notice,
11// this list of conditions and the following disclaimer in the documentation
12// and/or other materials provided with the distribution.
13// * Neither the name of Google Inc. nor the names of its contributors may be
14// used to endorse or promote products derived from this software without
15// specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27// POSSIBILITY OF SUCH DAMAGE.
28//
29// Author: sameeragarwal@google.com (Sameer Agarwal)
30//
31// Generic loop for line search based optimization algorithms.
32//
33// This is primarily inpsired by the minFunc packaged written by Mark
34// Schmidt.
35//
36// http://www.di.ens.fr/~mschmidt/Software/minFunc.html
37//
38// For details on the theory and implementation see "Numerical
39// Optimization" by Nocedal & Wright.
40
Sameer Agarwal8140f0f2013-03-12 09:45:08 -070041#ifndef CERES_NO_LINE_SEARCH_MINIMIZER
42
Sameer Agarwalf4d01642012-11-26 12:55:58 -080043#include "ceres/line_search_minimizer.h"
44
45#include <algorithm>
46#include <cstdlib>
47#include <cmath>
Sameer Agarwalf4d01642012-11-26 12:55:58 -080048#include <string>
49#include <vector>
Sameer Agarwalf4d01642012-11-26 12:55:58 -080050
51#include "Eigen/Dense"
52#include "ceres/array_utils.h"
53#include "ceres/evaluator.h"
54#include "ceres/internal/eigen.h"
Sameer Agarwal9883fc32012-11-30 12:32:43 -080055#include "ceres/internal/port.h"
Sameer Agarwalf4d01642012-11-26 12:55:58 -080056#include "ceres/internal/scoped_ptr.h"
57#include "ceres/line_search.h"
Sameer Agarwal9883fc32012-11-30 12:32:43 -080058#include "ceres/line_search_direction.h"
Sameer Agarwalf4d01642012-11-26 12:55:58 -080059#include "ceres/stringprintf.h"
60#include "ceres/types.h"
61#include "ceres/wall_time.h"
62#include "glog/logging.h"
63
64namespace ceres {
65namespace internal {
66namespace {
67// Small constant for various floating point issues.
Sameer Agarwalc89ea4b2013-01-09 16:09:35 -080068// TODO(sameeragarwal): Change to a better name if this has only one
69// use.
Sameer Agarwalf4d01642012-11-26 12:55:58 -080070const double kEpsilon = 1e-12;
Sameer Agarwalc89ea4b2013-01-09 16:09:35 -080071
Sameer Agarwala8d9ca82013-09-05 22:08:57 -070072// TODO(sameeragarwal): I think there is a small bug here, in that if
73// the evaluation fails, then the state can contain garbage. Look at
74// this more carefully.
Sameer Agarwal9883fc32012-11-30 12:32:43 -080075bool Evaluate(Evaluator* evaluator,
76 const Vector& x,
77 LineSearchMinimizer::State* state) {
78 const bool status = evaluator->Evaluate(x.data(),
79 &(state->cost),
80 NULL,
81 state->gradient.data(),
82 NULL);
83 if (status) {
84 state->gradient_squared_norm = state->gradient.squaredNorm();
85 state->gradient_max_norm = state->gradient.lpNorm<Eigen::Infinity>();
Sameer Agarwalf4d01642012-11-26 12:55:58 -080086 }
Sameer Agarwal9883fc32012-11-30 12:32:43 -080087
88 return status;
Sameer Agarwalf4d01642012-11-26 12:55:58 -080089}
90
Sameer Agarwal9883fc32012-11-30 12:32:43 -080091} // namespace
Sameer Agarwalf4d01642012-11-26 12:55:58 -080092
93void LineSearchMinimizer::Minimize(const Minimizer::Options& options,
94 double* parameters,
95 Solver::Summary* summary) {
Sameer Agarwal2d785d62013-09-04 23:34:29 -070096 const bool is_not_silent = !options.is_silent;
Sameer Agarwalf4d01642012-11-26 12:55:58 -080097 double start_time = WallTimeInSeconds();
98 double iteration_start_time = start_time;
Sameer Agarwalf4d01642012-11-26 12:55:58 -080099
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800100 Evaluator* evaluator = CHECK_NOTNULL(options.evaluator);
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800101 const int num_parameters = evaluator->NumParameters();
102 const int num_effective_parameters = evaluator->NumEffectiveParameters();
103
104 summary->termination_type = NO_CONVERGENCE;
105 summary->num_successful_steps = 0;
106 summary->num_unsuccessful_steps = 0;
107
108 VectorRef x(parameters, num_parameters);
109
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800110 State current_state(num_parameters, num_effective_parameters);
111 State previous_state(num_parameters, num_effective_parameters);
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800112
113 Vector delta(num_effective_parameters);
114 Vector x_plus_delta(num_parameters);
115
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800116 IterationSummary iteration_summary;
117 iteration_summary.iteration = 0;
118 iteration_summary.step_is_valid = false;
119 iteration_summary.step_is_successful = false;
120 iteration_summary.cost_change = 0.0;
121 iteration_summary.gradient_max_norm = 0.0;
Sameer Agarwal4d2df0c2013-09-13 12:54:03 -0700122 iteration_summary.gradient_norm = 0.0;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800123 iteration_summary.step_norm = 0.0;
124 iteration_summary.linear_solver_iterations = 0;
125 iteration_summary.step_solver_time_in_seconds = 0;
126
127 // Do initial cost and Jacobian evaluation.
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800128 if (!Evaluate(evaluator, x, &current_state)) {
Sameer Agarwal2d785d62013-09-04 23:34:29 -0700129 LOG_IF(WARNING, is_not_silent)
130 << "Terminating: Cost and gradient evaluation failed.";
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800131 summary->termination_type = NUMERICAL_FAILURE;
132 return;
133 }
134
Sameer Agarwalf102a682013-02-11 15:08:40 -0800135 summary->initial_cost = current_state.cost + summary->fixed_cost;
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800136 iteration_summary.cost = current_state.cost + summary->fixed_cost;
Sameer Agarwalf102a682013-02-11 15:08:40 -0800137
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800138 iteration_summary.gradient_max_norm = current_state.gradient_max_norm;
Sameer Agarwal4d2df0c2013-09-13 12:54:03 -0700139 iteration_summary.gradient_norm = sqrt(current_state.gradient_squared_norm);
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800140
141 // The initial gradient max_norm is bounded from below so that we do
142 // not divide by zero.
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800143 const double initial_gradient_max_norm =
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800144 max(iteration_summary.gradient_max_norm, kEpsilon);
145 const double absolute_gradient_tolerance =
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800146 options.gradient_tolerance * initial_gradient_max_norm;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800147
148 if (iteration_summary.gradient_max_norm <= absolute_gradient_tolerance) {
Sameer Agarwal2d785d62013-09-04 23:34:29 -0700149 VLOG_IF(1, is_not_silent)
150 << "Terminating: Gradient tolerance reached."
151 << "Relative gradient max norm: "
152 << iteration_summary.gradient_max_norm / initial_gradient_max_norm
153 << " <= " << options.gradient_tolerance;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800154 summary->termination_type = GRADIENT_TOLERANCE;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800155 return;
156 }
157
158 iteration_summary.iteration_time_in_seconds =
159 WallTimeInSeconds() - iteration_start_time;
160 iteration_summary.cumulative_time_in_seconds =
161 WallTimeInSeconds() - start_time
162 + summary->preprocessor_time_in_seconds;
163 summary->iterations.push_back(iteration_summary);
164
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800165 LineSearchDirection::Options line_search_direction_options;
166 line_search_direction_options.num_parameters = num_effective_parameters;
167 line_search_direction_options.type = options.line_search_direction_type;
168 line_search_direction_options.nonlinear_conjugate_gradient_type =
169 options.nonlinear_conjugate_gradient_type;
170 line_search_direction_options.max_lbfgs_rank = options.max_lbfgs_rank;
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100171 line_search_direction_options.use_approximate_eigenvalue_bfgs_scaling =
172 options.use_approximate_eigenvalue_bfgs_scaling;
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800173 scoped_ptr<LineSearchDirection> line_search_direction(
174 LineSearchDirection::Create(line_search_direction_options));
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800175
176 LineSearchFunction line_search_function(evaluator);
Sameer Agarwal09244012013-06-30 14:33:23 -0700177
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800178 LineSearch::Options line_search_options;
Sameer Agarwal09244012013-06-30 14:33:23 -0700179 line_search_options.interpolation_type =
180 options.line_search_interpolation_type;
181 line_search_options.min_step_size = options.min_line_search_step_size;
182 line_search_options.sufficient_decrease =
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100183 options.line_search_sufficient_function_decrease;
184 line_search_options.max_step_contraction =
185 options.max_line_search_step_contraction;
186 line_search_options.min_step_contraction =
187 options.min_line_search_step_contraction;
188 line_search_options.max_num_iterations =
189 options.max_num_line_search_step_size_iterations;
190 line_search_options.sufficient_curvature_decrease =
191 options.line_search_sufficient_curvature_decrease;
192 line_search_options.max_step_expansion =
193 options.max_line_search_step_expansion;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800194 line_search_options.function = &line_search_function;
195
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100196 scoped_ptr<LineSearch>
197 line_search(LineSearch::Create(options.line_search_type,
198 line_search_options,
199 &summary->error));
200 if (line_search.get() == NULL) {
Sameer Agarwal2d785d62013-09-04 23:34:29 -0700201 LOG_IF(ERROR, is_not_silent)
202 << "Ceres bug: Unable to create a LineSearch object, please "
203 << "contact the developers!, error: " << summary->error;
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100204 summary->termination_type = DID_NOT_RUN;
205 return;
206 }
207
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800208 LineSearch::Summary line_search_summary;
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100209 int num_line_search_direction_restarts = 0;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800210
211 while (true) {
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800212 if (!RunCallbacks(options.callbacks, iteration_summary, summary)) {
213 return;
214 }
215
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800216 iteration_start_time = WallTimeInSeconds();
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800217 if (iteration_summary.iteration >= options.max_num_iterations) {
Sameer Agarwal2d785d62013-09-04 23:34:29 -0700218 VLOG_IF(1, is_not_silent)
219 << "Terminating: Maximum number of iterations reached.";
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800220 summary->termination_type = NO_CONVERGENCE;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800221 break;
222 }
223
224 const double total_solver_time = iteration_start_time - start_time +
225 summary->preprocessor_time_in_seconds;
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800226 if (total_solver_time >= options.max_solver_time_in_seconds) {
Sameer Agarwal2d785d62013-09-04 23:34:29 -0700227 VLOG_IF(1, is_not_silent) << "Terminating: Maximum solver time reached.";
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800228 summary->termination_type = NO_CONVERGENCE;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800229 break;
230 }
231
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800232 iteration_summary = IterationSummary();
233 iteration_summary.iteration = summary->iterations.back().iteration + 1;
Sameer Agarwal1c70ae92013-06-30 12:50:43 -0700234 iteration_summary.step_is_valid = false;
235 iteration_summary.step_is_successful = false;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800236
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800237 bool line_search_status = true;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800238 if (iteration_summary.iteration == 1) {
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800239 current_state.search_direction = -current_state.gradient;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800240 } else {
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800241 line_search_status = line_search_direction->NextDirection(
242 previous_state,
243 current_state,
244 &current_state.search_direction);
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800245 }
246
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100247 if (!line_search_status &&
248 num_line_search_direction_restarts >=
249 options.max_num_line_search_direction_restarts) {
250 // Line search direction failed to generate a new direction, and we
251 // have already reached our specified maximum number of restarts,
252 // terminate optimization.
253 summary->error =
254 StringPrintf("Line search direction failure: specified "
255 "max_num_line_search_direction_restarts: %d reached.",
256 options.max_num_line_search_direction_restarts);
Sameer Agarwal2d785d62013-09-04 23:34:29 -0700257 LOG_IF(WARNING, is_not_silent) << summary->error
258 << " terminating optimization.";
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100259 summary->termination_type = NUMERICAL_FAILURE;
260 break;
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100261 } else if (!line_search_status) {
262 // Restart line search direction with gradient descent on first iteration
263 // as we have not yet reached our maximum number of restarts.
264 CHECK_LT(num_line_search_direction_restarts,
265 options.max_num_line_search_direction_restarts);
266
267 ++num_line_search_direction_restarts;
Sameer Agarwal2d785d62013-09-04 23:34:29 -0700268 LOG_IF(WARNING, is_not_silent)
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100269 << "Line search direction algorithm: "
Sameer Agarwal2d785d62013-09-04 23:34:29 -0700270 << LineSearchDirectionTypeToString(
271 options.line_search_direction_type)
272 << ", failed to produce a valid new direction at "
273 << "iteration: " << iteration_summary.iteration
274 << ". Restarting, number of restarts: "
275 << num_line_search_direction_restarts << " / "
276 << options.max_num_line_search_direction_restarts
277 << " [max].";
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100278 line_search_direction.reset(
279 LineSearchDirection::Create(line_search_direction_options));
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800280 current_state.search_direction = -current_state.gradient;
281 }
282
283 line_search_function.Init(x, current_state.search_direction);
284 current_state.directional_derivative =
285 current_state.gradient.dot(current_state.search_direction);
286
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800287 // TODO(sameeragarwal): Refactor this into its own object and add
288 // explanations for the various choices.
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100289 //
290 // Note that we use !line_search_status to ensure that we treat cases when
291 // we restarted the line search direction equivalently to the first
292 // iteration.
293 const double initial_step_size =
294 (iteration_summary.iteration == 1 || !line_search_status)
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800295 ? min(1.0, 1.0 / current_state.gradient_max_norm)
296 : min(1.0, 2.0 * (current_state.cost - previous_state.cost) /
297 current_state.directional_derivative);
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100298 // By definition, we should only ever go forwards along the specified search
299 // direction in a line search, most likely cause for this being violated
300 // would be a numerical failure in the line search direction calculation.
301 if (initial_step_size < 0.0) {
302 summary->error =
303 StringPrintf("Numerical failure in line search, initial_step_size is "
304 "negative: %.5e, directional_derivative: %.5e, "
305 "(current_cost - previous_cost): %.5e",
306 initial_step_size, current_state.directional_derivative,
307 (current_state.cost - previous_state.cost));
Sameer Agarwal2d785d62013-09-04 23:34:29 -0700308 LOG_IF(WARNING, is_not_silent) << summary->error;
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100309 summary->termination_type = NUMERICAL_FAILURE;
310 break;
311 }
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800312
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100313 line_search->Search(initial_step_size,
314 current_state.cost,
315 current_state.directional_derivative,
316 &line_search_summary);
Alex Stewart7124c342013-11-07 16:10:02 +0000317 if (!line_search_summary.success) {
318 summary->error =
319 StringPrintf("Numerical failure in line search, failed to find "
320 "a valid step size, (did not run out of iterations) "
321 "using initial_step_size: %.5e, initial_cost: %.5e, "
322 "initial_gradient: %.5e.",
323 initial_step_size, current_state.cost,
324 current_state.directional_derivative);
325 LOG_IF(WARNING, is_not_silent) << summary->error;
326 summary->termination_type = NUMERICAL_FAILURE;
327 break;
328 }
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800329
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800330 current_state.step_size = line_search_summary.optimal_step_size;
331 delta = current_state.step_size * current_state.search_direction;
332
333 previous_state = current_state;
Sameer Agarwal1c70ae92013-06-30 12:50:43 -0700334 iteration_summary.step_solver_time_in_seconds =
335 WallTimeInSeconds() - iteration_start_time;
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800336
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800337 // TODO(sameeragarwal): Collect stats.
Alex Stewart7124c342013-11-07 16:10:02 +0000338 //
339 // TODO(sameeragarwal): This call to Plus() directly updates the parameter
340 // vector via the VectorRef x. This is incorrect as we check the
341 // gradient and cost changes to determine if the step is accepted
342 // later, as such we could mutate x with a step that is not
343 // subsequently accepted, thus it is possible that
344 // summary->iterations.end()->x != x at termination.
Sameer Agarwala8d9ca82013-09-05 22:08:57 -0700345 if (!evaluator->Plus(x.data(), delta.data(), x_plus_delta.data())) {
Sameer Agarwal2d785d62013-09-04 23:34:29 -0700346 LOG_IF(WARNING, is_not_silent)
347 << "x_plus_delta = Plus(x, delta) failed. ";
Sameer Agarwala8d9ca82013-09-05 22:08:57 -0700348 } else if (!Evaluate(evaluator, x_plus_delta, &current_state)) {
Sameer Agarwal2d785d62013-09-04 23:34:29 -0700349 LOG_IF(WARNING, is_not_silent) << "Step failed to evaluate. ";
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800350 } else {
351 x = x_plus_delta;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800352 }
353
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800354 iteration_summary.gradient_max_norm = current_state.gradient_max_norm;
Sameer Agarwal4d2df0c2013-09-13 12:54:03 -0700355 iteration_summary.gradient_norm = sqrt(current_state.gradient_squared_norm);
356
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800357 if (iteration_summary.gradient_max_norm <= absolute_gradient_tolerance) {
Sameer Agarwal2d785d62013-09-04 23:34:29 -0700358 VLOG_IF(1, is_not_silent)
359 << "Terminating: Gradient tolerance reached."
360 << "Relative gradient max norm: "
361 << (iteration_summary.gradient_max_norm /
362 initial_gradient_max_norm)
363 << " <= " << options.gradient_tolerance;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800364 summary->termination_type = GRADIENT_TOLERANCE;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800365 break;
366 }
367
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800368 iteration_summary.cost_change = previous_state.cost - current_state.cost;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800369 const double absolute_function_tolerance =
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800370 options.function_tolerance * previous_state.cost;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800371 if (fabs(iteration_summary.cost_change) < absolute_function_tolerance) {
Sameer Agarwal2d785d62013-09-04 23:34:29 -0700372 VLOG_IF(1, is_not_silent)
373 << "Terminating. Function tolerance reached. "
374 << "|cost_change|/cost: "
375 << fabs(iteration_summary.cost_change) / previous_state.cost
376 << " <= " << options.function_tolerance;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800377 summary->termination_type = FUNCTION_TOLERANCE;
378 return;
379 }
380
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800381 iteration_summary.cost = current_state.cost + summary->fixed_cost;
382 iteration_summary.step_norm = delta.norm();
383 iteration_summary.step_is_valid = true;
384 iteration_summary.step_is_successful = true;
385 iteration_summary.step_norm = delta.norm();
386 iteration_summary.step_size = current_state.step_size;
387 iteration_summary.line_search_function_evaluations =
Alex Stewart9aa0e3c2013-07-05 20:22:37 +0100388 line_search_summary.num_function_evaluations;
389 iteration_summary.line_search_gradient_evaluations =
390 line_search_summary.num_gradient_evaluations;
391 iteration_summary.line_search_iterations =
392 line_search_summary.num_iterations;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800393 iteration_summary.iteration_time_in_seconds =
394 WallTimeInSeconds() - iteration_start_time;
395 iteration_summary.cumulative_time_in_seconds =
396 WallTimeInSeconds() - start_time
397 + summary->preprocessor_time_in_seconds;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800398
Sameer Agarwal9883fc32012-11-30 12:32:43 -0800399 summary->iterations.push_back(iteration_summary);
Sameer Agarwal1c70ae92013-06-30 12:50:43 -0700400 ++summary->num_successful_steps;
Sameer Agarwalf4d01642012-11-26 12:55:58 -0800401 }
402}
403
404} // namespace internal
405} // namespace ceres
Sameer Agarwal8140f0f2013-03-12 09:45:08 -0700406
Sameer Agarwal700d50d2013-03-12 16:12:42 -0700407#endif // CERES_NO_LINE_SEARCH_MINIMIZER