~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to extern/libmv/third_party/ceres/internal/ceres/solver.cc

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-19 11:24:23 UTC
  • mfrom: (14.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20140219112423-rkmaz2m7ha06d4tk
Tags: 2.69-3ubuntu1
* Merge with Debian; remaining changes:
  - Configure without OpenImageIO on armhf, as it is not available on
    Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
      fixed_cost(-1.0),
92
92
      num_successful_steps(-1),
93
93
      num_unsuccessful_steps(-1),
 
94
      num_inner_iteration_steps(-1),
94
95
      preprocessor_time_in_seconds(-1.0),
95
96
      minimizer_time_in_seconds(-1.0),
96
97
      postprocessor_time_in_seconds(-1.0),
98
99
      linear_solver_time_in_seconds(-1.0),
99
100
      residual_evaluation_time_in_seconds(-1.0),
100
101
      jacobian_evaluation_time_in_seconds(-1.0),
 
102
      inner_iteration_time_in_seconds(-1.0),
101
103
      num_parameter_blocks(-1),
102
104
      num_parameters(-1),
103
105
      num_effective_parameters(-1),
114
116
      num_linear_solver_threads_used(-1),
115
117
      linear_solver_type_given(SPARSE_NORMAL_CHOLESKY),
116
118
      linear_solver_type_used(SPARSE_NORMAL_CHOLESKY),
 
119
      inner_iterations_given(false),
 
120
      inner_iterations_used(false),
117
121
      preconditioner_type(IDENTITY),
118
122
      trust_region_strategy_type(LEVENBERG_MARQUARDT),
119
 
      inner_iterations(false),
120
 
      sparse_linear_algebra_library(SUITE_SPARSE),
 
123
      dense_linear_algebra_library_type(EIGEN),
 
124
      sparse_linear_algebra_library_type(SUITE_SPARSE),
121
125
      line_search_direction_type(LBFGS),
122
126
      line_search_type(ARMIJO) {
123
127
}
149
153
};
150
154
 
151
155
using internal::StringAppendF;
 
156
using internal::StringPrintf;
152
157
 
153
158
string Solver::Summary::FullReport() const {
154
159
  string report =
184
189
                  num_residuals, num_residuals_reduced);
185
190
  }
186
191
 
187
 
  // TODO(sameeragarwal): Refactor this into separate functions.
188
 
 
189
192
  if (minimizer_type == TRUST_REGION) {
 
193
    // TRUST_SEARCH HEADER
190
194
    StringAppendF(&report, "\nMinimizer                 %19s\n",
191
195
                  "TRUST_REGION");
 
196
 
 
197
    if (linear_solver_type_used == DENSE_NORMAL_CHOLESKY ||
 
198
        linear_solver_type_used == DENSE_SCHUR ||
 
199
        linear_solver_type_used == DENSE_QR) {
 
200
      StringAppendF(&report, "\nDense linear algebra library  %15s\n",
 
201
                    DenseLinearAlgebraLibraryTypeToString(
 
202
                        dense_linear_algebra_library_type));
 
203
    }
 
204
 
192
205
    if (linear_solver_type_used == SPARSE_NORMAL_CHOLESKY ||
193
206
        linear_solver_type_used == SPARSE_SCHUR ||
194
207
        (linear_solver_type_used == ITERATIVE_SCHUR &&
195
208
         (preconditioner_type == CLUSTER_JACOBI ||
196
209
          preconditioner_type == CLUSTER_TRIDIAGONAL))) {
197
 
      StringAppendF(&report, "\nSparse Linear Algebra Library %15s\n",
 
210
      StringAppendF(&report, "\nSparse linear algebra library %15s\n",
198
211
                    SparseLinearAlgebraLibraryTypeToString(
199
 
                                sparse_linear_algebra_library));
 
212
                        sparse_linear_algebra_library_type));
200
213
    }
201
214
 
202
 
    StringAppendF(&report, "Trust Region Strategy     %19s",
 
215
    StringAppendF(&report, "Trust region strategy     %19s",
203
216
                  TrustRegionStrategyTypeToString(
204
217
                      trust_region_strategy_type));
205
218
    if (trust_region_strategy_type == DOGLEG) {
222
235
      StringAppendF(&report, "Preconditioner      %25s%25s\n",
223
236
                    PreconditionerTypeToString(preconditioner_type),
224
237
                    PreconditionerTypeToString(preconditioner_type));
225
 
    } else {
226
 
      StringAppendF(&report, "Preconditioner      %25s%25s\n",
227
 
                    "N/A", "N/A");
228
238
    }
229
239
 
230
 
    StringAppendF(&report, "Threads:            % 25d% 25d\n",
 
240
    StringAppendF(&report, "Threads             % 25d% 25d\n",
231
241
                  num_threads_given, num_threads_used);
232
242
    StringAppendF(&report, "Linear solver threads % 23d% 25d\n",
233
243
                  num_linear_solver_threads_given,
244
254
                    used.c_str());
245
255
    }
246
256
 
247
 
    if (inner_iterations) {
 
257
    if (inner_iterations_given) {
 
258
      StringAppendF(&report,
 
259
                    "Use inner iterations     %20s     %20s\n",
 
260
                    inner_iterations_given ? "True" : "False",
 
261
                    inner_iterations_used ? "True" : "False");
 
262
    }
 
263
 
 
264
    if (inner_iterations_used) {
248
265
      string given;
249
266
      StringifyOrdering(inner_iteration_ordering_given, &given);
250
267
      string used;
254
271
                  given.c_str(),
255
272
                  used.c_str());
256
273
    }
257
 
 
258
 
    if (termination_type == DID_NOT_RUN) {
259
 
      CHECK(!error.empty())
260
 
          << "Solver terminated with DID_NOT_RUN but the solver did not "
261
 
          << "return a reason. This is a Ceres error. Please report this "
262
 
          << "to the Ceres team";
263
 
      StringAppendF(&report, "Termination:           %20s\n",
264
 
                    "DID_NOT_RUN");
265
 
      StringAppendF(&report, "Reason: %s\n", error.c_str());
266
 
      return report;
267
 
    }
268
 
 
269
 
    StringAppendF(&report, "\nCost:\n");
270
 
    StringAppendF(&report, "Initial        % 30e\n", initial_cost);
271
 
    if (termination_type != NUMERICAL_FAILURE &&
272
 
        termination_type != USER_ABORT) {
273
 
      StringAppendF(&report, "Final          % 30e\n", final_cost);
274
 
      StringAppendF(&report, "Change         % 30e\n",
275
 
                    initial_cost - final_cost);
276
 
    }
277
 
 
278
 
    StringAppendF(&report, "\nNumber of iterations:\n");
279
 
    StringAppendF(&report, "Successful               % 20d\n",
 
274
  } else {
 
275
    // LINE_SEARCH HEADER
 
276
    StringAppendF(&report, "\nMinimizer                 %19s\n", "LINE_SEARCH");
 
277
 
 
278
 
 
279
    string line_search_direction_string;
 
280
    if (line_search_direction_type == LBFGS) {
 
281
      line_search_direction_string = StringPrintf("LBFGS (%d)", max_lbfgs_rank);
 
282
    } else if (line_search_direction_type == NONLINEAR_CONJUGATE_GRADIENT) {
 
283
      line_search_direction_string =
 
284
          NonlinearConjugateGradientTypeToString(
 
285
              nonlinear_conjugate_gradient_type);
 
286
    } else {
 
287
      line_search_direction_string =
 
288
          LineSearchDirectionTypeToString(line_search_direction_type);
 
289
    }
 
290
 
 
291
    StringAppendF(&report, "Line search direction     %19s\n",
 
292
                  line_search_direction_string.c_str());
 
293
 
 
294
    const string line_search_type_string =
 
295
        StringPrintf("%s %s",
 
296
                     LineSearchInterpolationTypeToString(
 
297
                         line_search_interpolation_type),
 
298
                     LineSearchTypeToString(line_search_type));
 
299
    StringAppendF(&report, "Line search type          %19s\n",
 
300
                  line_search_type_string.c_str());
 
301
    StringAppendF(&report, "\n");
 
302
 
 
303
    StringAppendF(&report, "%45s    %21s\n", "Given",  "Used");
 
304
    StringAppendF(&report, "Threads             % 25d% 25d\n",
 
305
                  num_threads_given, num_threads_used);
 
306
  }
 
307
 
 
308
  if (termination_type == DID_NOT_RUN) {
 
309
    CHECK(!error.empty())
 
310
        << "Solver terminated with DID_NOT_RUN but the solver did not "
 
311
        << "return a reason. This is a Ceres error. Please report this "
 
312
        << "to the Ceres team";
 
313
    StringAppendF(&report, "Termination:           %20s\n",
 
314
                  "DID_NOT_RUN");
 
315
    StringAppendF(&report, "Reason: %s\n", error.c_str());
 
316
    return report;
 
317
  }
 
318
 
 
319
  StringAppendF(&report, "\nCost:\n");
 
320
  StringAppendF(&report, "Initial        % 30e\n", initial_cost);
 
321
  if (termination_type != NUMERICAL_FAILURE &&
 
322
      termination_type != USER_ABORT) {
 
323
    StringAppendF(&report, "Final          % 30e\n", final_cost);
 
324
    StringAppendF(&report, "Change         % 30e\n",
 
325
                  initial_cost - final_cost);
 
326
  }
 
327
 
 
328
  StringAppendF(&report, "\nMinimizer iterations         % 16d\n",
 
329
                num_successful_steps + num_unsuccessful_steps);
 
330
 
 
331
  // Successful/Unsuccessful steps only matter in the case of the
 
332
  // trust region solver. Line search terminates when it encounters
 
333
  // the first unsuccessful step.
 
334
  if (minimizer_type == TRUST_REGION) {
 
335
    StringAppendF(&report, "Successful steps               % 14d\n",
280
336
                  num_successful_steps);
281
 
    StringAppendF(&report, "Unsuccessful             % 20d\n",
 
337
    StringAppendF(&report, "Unsuccessful steps             % 14d\n",
282
338
                  num_unsuccessful_steps);
283
 
    StringAppendF(&report, "Total                    % 20d\n",
284
 
                  num_successful_steps + num_unsuccessful_steps);
285
 
 
286
 
    StringAppendF(&report, "\nTime (in seconds):\n");
287
 
    StringAppendF(&report, "Preprocessor        %25.3f\n",
288
 
                  preprocessor_time_in_seconds);
289
 
    StringAppendF(&report, "\n  Residual Evaluations %22.3f\n",
290
 
                  residual_evaluation_time_in_seconds);
291
 
    StringAppendF(&report, "  Jacobian Evaluations %22.3f\n",
292
 
                  jacobian_evaluation_time_in_seconds);
293
 
    StringAppendF(&report, "  Linear Solver       %23.3f\n",
 
339
  }
 
340
  if (inner_iterations_used) {
 
341
    StringAppendF(&report, "Steps with inner iterations    % 14d\n",
 
342
                  num_inner_iteration_steps);
 
343
  }
 
344
 
 
345
  StringAppendF(&report, "\nTime (in seconds):\n");
 
346
  StringAppendF(&report, "Preprocessor        %25.3f\n",
 
347
                preprocessor_time_in_seconds);
 
348
 
 
349
  StringAppendF(&report, "\n  Residual evaluation %23.3f\n",
 
350
                residual_evaluation_time_in_seconds);
 
351
  StringAppendF(&report, "  Jacobian evaluation %23.3f\n",
 
352
                jacobian_evaluation_time_in_seconds);
 
353
 
 
354
  if (minimizer_type == TRUST_REGION) {
 
355
    StringAppendF(&report, "  Linear solver       %23.3f\n",
294
356
                  linear_solver_time_in_seconds);
295
 
    StringAppendF(&report, "Minimizer           %25.3f\n\n",
296
 
                  minimizer_time_in_seconds);
297
 
 
298
 
    StringAppendF(&report, "Postprocessor        %24.3f\n",
299
 
                  postprocessor_time_in_seconds);
300
 
 
301
 
    StringAppendF(&report, "Total               %25.3f\n\n",
302
 
                  total_time_in_seconds);
303
 
 
304
 
    StringAppendF(&report, "Termination:        %25s\n",
305
 
                  SolverTerminationTypeToString(termination_type));
306
 
  } else {
307
 
    // LINE_SEARCH
308
 
    StringAppendF(&report, "\nMinimizer                 %19s\n", "LINE_SEARCH");
309
 
    if (line_search_direction_type == LBFGS) {
310
 
      StringAppendF(&report, "Line search direction     %19s(%d)\n",
311
 
                    LineSearchDirectionTypeToString(line_search_direction_type),
312
 
                    max_lbfgs_rank);
313
 
    } else {
314
 
      StringAppendF(&report, "Line search direction     %19s\n",
315
 
                    LineSearchDirectionTypeToString(
316
 
                        line_search_direction_type));
317
 
    }
318
 
    StringAppendF(&report, "Line search type          %19s\n",
319
 
                  LineSearchTypeToString(line_search_type));
320
 
 
321
 
    StringAppendF(&report, "\n");
322
 
 
323
 
    StringAppendF(&report, "%45s    %21s\n", "Given",  "Used");
324
 
    StringAppendF(&report, "Threads:            % 25d% 25d\n",
325
 
                  num_threads_given, num_threads_used);
326
 
 
327
 
    if (termination_type == DID_NOT_RUN) {
328
 
      CHECK(!error.empty())
329
 
          << "Solver terminated with DID_NOT_RUN but the solver did not "
330
 
          << "return a reason. This is a Ceres error. Please report this "
331
 
          << "to the Ceres team";
332
 
      StringAppendF(&report, "Termination:           %20s\n",
333
 
                    "DID_NOT_RUN");
334
 
      StringAppendF(&report, "Reason: %s\n", error.c_str());
335
 
      return report;
336
 
    }
337
 
 
338
 
    StringAppendF(&report, "\nCost:\n");
339
 
    StringAppendF(&report, "Initial        % 30e\n", initial_cost);
340
 
    if (termination_type != NUMERICAL_FAILURE &&
341
 
        termination_type != USER_ABORT) {
342
 
      StringAppendF(&report, "Final          % 30e\n", final_cost);
343
 
      StringAppendF(&report, "Change         % 30e\n",
344
 
                    initial_cost - final_cost);
345
 
    }
346
 
 
347
 
    StringAppendF(&report, "\nNumber of iterations:    % 20d\n",
348
 
                  static_cast<int>(iterations.size() - 1));
349
 
 
350
 
    StringAppendF(&report, "\nTime (in seconds):\n");
351
 
    StringAppendF(&report, "Preprocessor        %25.3f\n",
352
 
                  preprocessor_time_in_seconds);
353
 
    StringAppendF(&report, "\n  Residual Evaluations %22.3f\n",
354
 
                  residual_evaluation_time_in_seconds);
355
 
    StringAppendF(&report, "  Jacobian Evaluations %22.3f\n",
356
 
                  jacobian_evaluation_time_in_seconds);
357
 
    StringAppendF(&report, "Minimizer           %25.3f\n\n",
358
 
                  minimizer_time_in_seconds);
359
 
 
360
 
    StringAppendF(&report, "Postprocessor        %24.3f\n",
361
 
                  postprocessor_time_in_seconds);
362
 
 
363
 
    StringAppendF(&report, "Total               %25.3f\n\n",
364
 
                  total_time_in_seconds);
365
 
 
366
 
    StringAppendF(&report, "Termination:        %25s\n",
367
 
                  SolverTerminationTypeToString(termination_type));
368
 
  }
369
 
 
 
357
  }
 
358
 
 
359
  if (inner_iterations_used) {
 
360
    StringAppendF(&report, "  Inner iterations    %23.3f\n",
 
361
                  inner_iteration_time_in_seconds);
 
362
  }
 
363
 
 
364
  StringAppendF(&report, "Minimizer           %25.3f\n\n",
 
365
                minimizer_time_in_seconds);
 
366
 
 
367
  StringAppendF(&report, "Postprocessor        %24.3f\n",
 
368
                postprocessor_time_in_seconds);
 
369
 
 
370
  StringAppendF(&report, "Total               %25.3f\n\n",
 
371
                total_time_in_seconds);
 
372
 
 
373
  StringAppendF(&report, "Termination:        %25s\n",
 
374
                SolverTerminationTypeToString(termination_type));
370
375
  return report;
371
376
};
372
377