mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 08:34:37 +08:00
A bunch of minor changes.
1. Fix a typo in auto_diff_cost_function.h 2. Fix and update Solver::Summary::FullReport() text labels. 3. Add logging of the number of residual and jacobian evaluations to the full report. The GradientProblemSolver already does this. Change-Id: I41059af5f0ebe0417accbbc30b0808a4b04b9edb
This commit is contained in:
@@ -2045,10 +2045,18 @@ The three arrays will be:
|
||||
|
||||
Time (in seconds) spent evaluating the residual vector.
|
||||
|
||||
.. member:: int Solver::Summary::num_residual_evaluations
|
||||
|
||||
Number of times only the residuals were evaluated.
|
||||
|
||||
.. member:: double Solver::Summary::jacobian_evaluation_time_in_seconds
|
||||
|
||||
Time (in seconds) spent evaluating the Jacobian matrix.
|
||||
|
||||
.. member:: int Solver::Summary::num_jacobian_evaluations
|
||||
|
||||
Number of times only the Jacobian and the residuals were evaluated.
|
||||
|
||||
.. member:: double Solver::Summary::inner_iteration_time_in_seconds
|
||||
|
||||
Time (in seconds) spent doing inner iterations.
|
||||
|
||||
@@ -197,7 +197,7 @@ class AutoDiffCostFunction : public SizedCostFunction<kNumResiduals,
|
||||
// Implementation details follow; clients of the autodiff cost function should
|
||||
// not have to examine below here.
|
||||
//
|
||||
// To handle varardic cost functions, some template magic is needed. It's
|
||||
// To handle variadic cost functions, some template magic is needed. It's
|
||||
// mostly hidden inside autodiff.h.
|
||||
virtual bool Evaluate(double const* const* parameters,
|
||||
double* residuals,
|
||||
|
||||
@@ -844,9 +844,15 @@ class CERES_EXPORT Solver {
|
||||
// Time (in seconds) spent evaluating the residual vector.
|
||||
double residual_evaluation_time_in_seconds;
|
||||
|
||||
// Number of residual only evaluations.
|
||||
int num_residual_evaluations;
|
||||
|
||||
// Time (in seconds) spent evaluating the jacobian matrix.
|
||||
double jacobian_evaluation_time_in_seconds;
|
||||
|
||||
// Number of Jacobian (and residual) evaluations.
|
||||
int num_jacobian_evaluations;
|
||||
|
||||
// Time (in seconds) spent doing inner iterations.
|
||||
double inner_iteration_time_in_seconds;
|
||||
|
||||
|
||||
@@ -44,6 +44,12 @@ namespace internal {
|
||||
// Struct used by various objects to report statistics and other
|
||||
// information about their execution. e.g., ExecutionSummary::times
|
||||
// can be used for reporting times associated with various activities.
|
||||
//
|
||||
// TODO(https://github.com/ceres-solver/ceres-solver/issues/340):
|
||||
// Replace the two maps by one to save on a lookup, since the usage
|
||||
// pattern is to keep track of the calls and the time increment at the
|
||||
// same time.
|
||||
//
|
||||
class ExecutionSummary {
|
||||
public:
|
||||
void IncrementTimeBy(const std::string& name, const double value) {
|
||||
@@ -76,6 +82,7 @@ class ScopedExecutionTimer {
|
||||
|
||||
~ScopedExecutionTimer() {
|
||||
summary_->IncrementTimeBy(name_, WallTimeInSeconds() - start_time_);
|
||||
summary_->IncrementCall(name_);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -67,8 +67,6 @@ class GradientProblemEvaluator : public Evaluator {
|
||||
ScopedExecutionTimer call_type_timer(
|
||||
gradient == NULL ? "Evaluator::Residual" : "Evaluator::Jacobian",
|
||||
&execution_summary_);
|
||||
execution_summary_.IncrementCall(gradient == NULL ? "Evaluator::Residual"
|
||||
: "Evaluator::Jacobian");
|
||||
return problem_.Evaluate(state, cost, gradient);
|
||||
}
|
||||
|
||||
|
||||
@@ -276,7 +276,7 @@ string GradientProblemSolver::Summary::FullReport() const {
|
||||
StringAppendF(&report, "\n Cost evaluation %23.6f (%d)\n",
|
||||
cost_evaluation_time_in_seconds,
|
||||
num_cost_evaluations);
|
||||
StringAppendF(&report, " Gradient evaluation %23.6f (%d)\n",
|
||||
StringAppendF(&report, " Gradient & cost evaluation %16.6f (%d)\n",
|
||||
gradient_evaluation_time_in_seconds,
|
||||
num_gradient_evaluations);
|
||||
StringAppendF(&report, " Polynomial minimization %17.6f\n",
|
||||
|
||||
@@ -404,6 +404,13 @@ void PostSolveSummarize(const internal::PreprocessedProblem& pp,
|
||||
FindWithDefault(evaluator_time_statistics, "Evaluator::Residual", 0.0);
|
||||
summary->jacobian_evaluation_time_in_seconds =
|
||||
FindWithDefault(evaluator_time_statistics, "Evaluator::Jacobian", 0.0);
|
||||
|
||||
const map<string, int>& evaluator_call_statistics =
|
||||
pp.evaluator->CallStatistics();
|
||||
summary->num_residual_evaluations =
|
||||
FindWithDefault(evaluator_call_statistics, "Evaluator::Residual", 0);
|
||||
summary->num_jacobian_evaluations =
|
||||
FindWithDefault(evaluator_call_statistics, "Evaluator::Jacobian", 0);
|
||||
}
|
||||
|
||||
// Again, like the evaluator, there may or may not be a linear
|
||||
@@ -627,7 +634,9 @@ Solver::Summary::Summary()
|
||||
total_time_in_seconds(-1.0),
|
||||
linear_solver_time_in_seconds(-1.0),
|
||||
residual_evaluation_time_in_seconds(-1.0),
|
||||
num_residual_evaluations(-1),
|
||||
jacobian_evaluation_time_in_seconds(-1.0),
|
||||
num_jacobian_evaluations(-1),
|
||||
inner_iteration_time_in_seconds(-1.0),
|
||||
line_search_cost_evaluation_time_in_seconds(-1.0),
|
||||
line_search_gradient_evaluation_time_in_seconds(-1.0),
|
||||
@@ -696,7 +705,7 @@ string Solver::Summary::FullReport() const {
|
||||
}
|
||||
StringAppendF(&report, "Residual blocks % 25d% 25d\n",
|
||||
num_residual_blocks, num_residual_blocks_reduced);
|
||||
StringAppendF(&report, "Residual % 25d% 25d\n",
|
||||
StringAppendF(&report, "Residuals % 25d% 25d\n",
|
||||
num_residuals, num_residuals_reduced);
|
||||
|
||||
if (minimizer_type == TRUST_REGION) {
|
||||
@@ -866,14 +875,14 @@ string Solver::Summary::FullReport() const {
|
||||
StringAppendF(&report, "Preprocessor %25.6f\n",
|
||||
preprocessor_time_in_seconds);
|
||||
|
||||
StringAppendF(&report, "\n Residual evaluation %23.6f\n",
|
||||
residual_evaluation_time_in_seconds);
|
||||
StringAppendF(&report, "\n Residual only evaluation %18.6f (%d)\n",
|
||||
residual_evaluation_time_in_seconds, num_residual_evaluations);
|
||||
if (line_search_used) {
|
||||
StringAppendF(&report, " Line search cost evaluation %10.6f\n",
|
||||
line_search_cost_evaluation_time_in_seconds);
|
||||
}
|
||||
StringAppendF(&report, " Jacobian evaluation %23.6f\n",
|
||||
jacobian_evaluation_time_in_seconds);
|
||||
StringAppendF(&report, " Jacobian & residual evaluation %12.6f (%d)\n",
|
||||
jacobian_evaluation_time_in_seconds, num_jacobian_evaluations);
|
||||
if (line_search_used) {
|
||||
StringAppendF(&report, " Line search gradient evaluation %6.6f\n",
|
||||
line_search_gradient_evaluation_time_in_seconds);
|
||||
|
||||
Reference in New Issue
Block a user