blob: afa440073e198f6d84d0ceda13a00608d511a68a [file] [log] [blame]
Sameer Agarwalaa9a83c2012-05-29 17:40:17 -07001// 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#ifndef CERES_INTERNAL_TRUST_REGION_STRATEGY_H_
32#define CERES_INTERNAL_TRUST_REGION_STRATEGY_H_
33
34#include "ceres/linear_solver.h"
35
36namespace ceres {
37namespace internal {
38
39// Interface for classes implementing various trust region strategies
40// for nonlinear least squares problems.
41//
42// The object is expected to maintain and update a trust region
43// radius, which it then uses to solve for the trust region step using
44// the jacobian matrix and residual vector.
45//
46// Here the term trust region radius is used loosely, as the strategy
47// is free to treat it as guidance and violate it as need be. e.g.,
48// the LevenbergMarquardtStrategy uses the inverse of the trust region
49// radius to scale the damping term, which controls the step size, but
50// does not set a hard limit on its size.
51class TrustRegionStrategy {
52public:
53 struct Options {
54 Options()
55 : trust_region_strategy_type(LEVENBERG_MARQUARDT),
56 initial_radius(1e4),
57 max_radius(1e32),
58 lm_min_diagonal(1e-6),
59 lm_max_diagonal(1e32) {
60 }
61
62 TrustRegionStrategyType trust_region_strategy_type;
63 // Linear solver used for actually solving the trust region step.
64 LinearSolver* linear_solver;
65 double initial_radius;
66 double max_radius;
67
68 // Minimum and maximum values of the diagonal damping matrix used
69 // by LevenbergMarquardtStrategy.
70 double lm_min_diagonal;
71 double lm_max_diagonal;
72 };
73
74 // Per solve options.
75 struct PerSolveOptions {
76 // Forcing sequence for inexact solves.
77 double eta;
78 };
79
80 ~TrustRegionStrategy();
81
82 // Use the current radius to solve for the trust region step.
83 virtual LinearSolver::Summary ComputeStep(
84 const PerSolveOptions& per_solve_options,
85 SparseMatrix* jacobian,
86 const double* residuals,
87 double* step) = 0;
88
89 // Inform the strategy that the current step has been accepted, and
90 // that the ratio of the decrease in the non-linear objective to the
91 // decrease in the trust region model is step_quality.
92 virtual void StepAccepted(double step_quality) = 0;
93
94 // Inform the strategy that the current step has been rejected, and
95 // that the ratio of the decrease in the non-linear objective to the
96 // decrease in the trust region model is step_quality.
97 virtual void StepRejected(double step_quality) = 0;
98
99 // Current trust region radius.
100 virtual double Radius() const = 0;
101
102 // Factory.
103 static TrustRegionStrategy* Create(const Options& options);
104};
105
106} // namespace internal
107} // namespace ceres
108
109#endif // CERES_INTERNAL_TRUST_REGION_STRATEGY_H_