blob: 0dcb354e5b2f9461b64842d310f1a41819274b17 [file] [log] [blame]
Keir Mierle8ebb0732012-04-30 23:09:08 -07001// Ceres Solver - A fast non-linear least squares minimizer
2// Copyright 2010, 2011, 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// Enums and other top level class definitions.
32//
33// Note: internal/types.cc defines stringification routines for some
34// of these enums. Please update those routines if you extend or
35// remove enums from here.
36
37#ifndef CERES_PUBLIC_TYPES_H_
38#define CERES_PUBLIC_TYPES_H_
39
40namespace ceres {
41
42// Basic integer types. These typedefs are in the Ceres namespace to avoid
43// conflicts with other packages having similar typedefs.
44typedef short int16;
45typedef int int32;
46
47// Argument type used in interfaces that can optionally take ownership
48// of a passed in argument. If TAKE_OWNERSHIP is passed, the called
49// object takes ownership of the pointer argument, and will call
50// delete on it upon completion.
51enum Ownership {
52 DO_NOT_TAKE_OWNERSHIP,
53 TAKE_OWNERSHIP
54};
55
56// TODO(keir): Considerably expand the explanations of each solver type.
57enum LinearSolverType {
58 // These solvers are for general rectangular systems formed from the
59 // normal equations A'A x = A'b. They are direct solvers and do not
60 // assume any special problem structure.
61
62 // Solve the normal equations using a sparse cholesky solver; based
63 // on CHOLMOD.
64 SPARSE_NORMAL_CHOLESKY,
65
66 // Solve the normal equations using a dense QR solver; based on
67 // Eigen.
68 DENSE_QR,
69
70 // Specialized solvers, specific to problems with a generalized
71 // bi-partitite structure.
72
73 // Solves the reduced linear system using a dense Cholesky solver;
74 // based on Eigen.
75 DENSE_SCHUR,
76
77 // Solves the reduced linear system using a sparse Cholesky solver;
78 // based on CHOLMOD.
79 SPARSE_SCHUR,
80
81 // Solves the reduced linear system using Conjugate Gradients, based
82 // on a new Ceres implementation. Suitable for large scale
83 // problems.
84 ITERATIVE_SCHUR,
85
Keir Mierlee2a6cdc2012-05-07 06:39:56 -070086 // Conjugate gradients on the normal equations.
87 CGNR
Keir Mierle8ebb0732012-04-30 23:09:08 -070088};
89
90enum PreconditionerType {
91 // Trivial preconditioner - the identity matrix.
92 IDENTITY,
93
94 // Block diagonal of the Gauss-Newton Hessian.
95 JACOBI,
96
97 // Block diagonal of the Schur complement. This preconditioner may
98 // only be used with the ITERATIVE_SCHUR solver. Requires
99 // SuiteSparse/CHOLMOD.
100 SCHUR_JACOBI,
101
102 // Visibility clustering based preconditioners.
103 //
104 // These preconditioners are well suited for Structure from Motion
105 // problems, particularly problems arising from community photo
106 // collections. These preconditioners use the visibility structure
107 // of the scene to determine the sparsity structure of the
108 // preconditioner. Requires SuiteSparse/CHOLMOD.
109 CLUSTER_JACOBI,
110 CLUSTER_TRIDIAGONAL
111};
112
Sameer Agarwalb0518732012-05-29 00:27:57 -0700113enum SparseLinearAlgebraLibraryType {
114 // High performance sparse Cholesky factorization and approximate
115 // minimum degree ordering.
116 SUITE_SPARSE,
117
118 // A lightweight replacment for SuiteSparse.
119 CX_SPARSE
120};
121
Keir Mierle8ebb0732012-04-30 23:09:08 -0700122enum LinearSolverTerminationType {
123 // Termination criterion was met. For factorization based solvers
124 // the tolerance is assumed to be zero. Any user provided values are
125 // ignored.
126 TOLERANCE,
127
128 // Solver ran for max_num_iterations and terminated before the
129 // termination tolerance could be satified.
130 MAX_ITERATIONS,
131
132 // Solver is stuck and further iterations will not result in any
133 // measurable progress.
134 STAGNATION,
135
136 // Solver failed. Solver was terminated due to numerical errors. The
137 // exact cause of failure depends on the particular solver being
138 // used.
139 FAILURE
140};
141
142enum OrderingType {
143 // The order in which the parameter blocks were defined.
144 NATURAL,
145
146 // Use the ordering specificed in the vector ordering.
147 USER,
148
149 // Automatically figure out the best ordering to use the schur
150 // complement based solver.
151 SCHUR
152};
153
154// Logging options
155// The options get progressively noisier.
156enum LoggingType {
157 SILENT,
Sameer Agarwal64472192012-05-03 21:53:07 -0700158 PER_MINIMIZER_ITERATION
Keir Mierle8ebb0732012-04-30 23:09:08 -0700159};
160
Sameer Agarwalfa015192012-06-11 14:21:42 -0700161// Ceres supports different strategies for computing the trust region
162// step.
Sameer Agarwalaa9a83c2012-05-29 17:40:17 -0700163enum TrustRegionStrategyType {
Sameer Agarwalfa015192012-06-11 14:21:42 -0700164 // The default trust region strategy is to use the step computation
165 // used in the Levenberg-Marquardt algorithm. For more details see
166 // levenberg_marquardt_strategy.h
Sameer Agarwalaa9a83c2012-05-29 17:40:17 -0700167 LEVENBERG_MARQUARDT,
Sameer Agarwalfa015192012-06-11 14:21:42 -0700168
169 // Powell's dogleg algorithm interpolates between the Cauchy point
170 // and the Gauss-Newton step. It is particularly useful if the
171 // LEVENBERG_MARQUARDT algorithm is making a large number of
172 // unsuccessful steps. For more details see dogleg_strategy.h.
173 //
174 // NOTES:
175 //
176 // 1. This strategy has not been experimented with or tested as
177 // extensively as LEVENBERG_MARQUARDT, and therefore it should be
178 // considered EXPERIMENTAL for now.
179 //
180 // 2. For now this strategy should only be used with exact
181 // factorization based linear solvers, i.e., SPARSE_SCHUR,
182 // DENSE_SCHUR, DENSE_QR and SPARSE_NORMAL_CHOLESKY.
183 DOGLEG
Keir Mierle8ebb0732012-04-30 23:09:08 -0700184};
185
186enum SolverTerminationType {
187 // The minimizer did not run at all; usually due to errors in the user's
188 // Problem or the solver options.
189 DID_NOT_RUN,
190
191 // The solver ran for maximum number of iterations specified by the
192 // user, but none of the convergence criterion specified by the user
193 // were met.
194 NO_CONVERGENCE,
195
196 // Minimizer terminated because
197 // (new_cost - old_cost) < function_tolerance * old_cost;
198 FUNCTION_TOLERANCE,
199
200 // Minimizer terminated because
201 // max_i |gradient_i| < gradient_tolerance * max_i|initial_gradient_i|
202 GRADIENT_TOLERANCE,
203
204 // Minimized terminated because
205 // |step|_2 <= parameter_tolerance * ( |x|_2 + parameter_tolerance)
206 PARAMETER_TOLERANCE,
207
208 // The minimizer terminated because it encountered a numerical error
209 // that it could not recover from.
210 NUMERICAL_FAILURE,
211
212 // Using an IterationCallback object, user code can control the
213 // minimizer. The following enums indicate that the user code was
214 // responsible for termination.
215
216 // User's IterationCallback returned SOLVER_ABORT.
217 USER_ABORT,
218
219 // User's IterationCallback returned SOLVER_TERMINATE_SUCCESSFULLY
Sameer Agarwal64472192012-05-03 21:53:07 -0700220 USER_SUCCESS
Keir Mierle8ebb0732012-04-30 23:09:08 -0700221};
222
223// Enums used by the IterationCallback instances to indicate to the
224// solver whether it should continue solving, the user detected an
225// error or the solution is good enough and the solver should
226// terminate.
227enum CallbackReturnType {
228 // Continue solving to next iteration.
229 SOLVER_CONTINUE,
230
231 // Terminate solver, and do not update the parameter blocks upon
232 // return. Unless the user has set
233 // Solver:Options:::update_state_every_iteration, in which case the
234 // state would have been updated every iteration
235 // anyways. Solver::Summary::termination_type is set to USER_ABORT.
236 SOLVER_ABORT,
237
238 // Terminate solver, update state and
239 // return. Solver::Summary::termination_type is set to USER_SUCCESS.
240 SOLVER_TERMINATE_SUCCESSFULLY
241};
242
Sameer Agarwal82f4b882012-05-06 21:05:28 -0700243// The format in which linear least squares problems should be logged
244// when Solver::Options::lsqp_iterations_to_dump is non-empty.
245enum DumpFormatType {
246 // Print the linear least squares problem in a human readable format
247 // to stderr. The Jacobian is printed as a dense matrix. The vectors
248 // D, x and f are printed as dense vectors. This should only be used
249 // for small problems.
250 CONSOLE,
251
252 // Write out the linear least squares problem to the directory
253 // pointed to by Solver::Options::lsqp_dump_directory as a protocol
254 // buffer. linear_least_squares_problems.h/cc contains routines for
255 // loading these problems. For details on the on disk format used,
256 // see matrix.proto. The files are named lm_iteration_???.lsqp.
257 PROTOBUF,
258
259 // Write out the linear least squares problem to the directory
260 // pointed to by Solver::Options::lsqp_dump_directory as text files
261 // which can be read into MATLAB/Octave. The Jacobian is dumped as a
262 // text file containing (i,j,s) triplets, the vectors D, x and f are
263 // dumped as text files containing a list of their values.
264 //
265 // A MATLAB/octave script called lm_iteration_???.m is also output,
266 // which can be used to parse and load the problem into memory.
267 TEXTFILE
268};
269
Keir Mierlefdeb5772012-05-09 07:38:07 -0700270// For SizedCostFunction and AutoDiffCostFunction, DYNAMIC can be specified for
271// the number of residuals. If specified, then the number of residuas for that
272// cost function can vary at runtime.
273enum DimensionType {
274 DYNAMIC = -1
275};
276
Keir Mierle8ebb0732012-04-30 23:09:08 -0700277const char* LinearSolverTypeToString(LinearSolverType type);
278const char* PreconditionerTypeToString(PreconditionerType type);
Sameer Agarwalb0518732012-05-29 00:27:57 -0700279const char* SparseLinearAlgebraLibraryTypeToString(
280 SparseLinearAlgebraLibraryType type);
Keir Mierle8ebb0732012-04-30 23:09:08 -0700281const char* LinearSolverTerminationTypeToString(
282 LinearSolverTerminationType type);
283const char* OrderingTypeToString(OrderingType type);
284const char* SolverTerminationTypeToString(SolverTerminationType type);
Sameer Agarwalfa015192012-06-11 14:21:42 -0700285const char* SparseLinearAlgebraLibraryTypeToString(
286 SparseLinearAlgebraLibraryType type);
287const char* TrustRegionStrategyTypeToString( TrustRegionStrategyType type);
Keir Mierle8ebb0732012-04-30 23:09:08 -0700288bool IsSchurType(LinearSolverType type);
289
290} // namespace ceres
291
292#endif // CERES_PUBLIC_TYPES_H_