Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 1 | // 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 | |
Sameer Agarwal | cbae856 | 2012-09-02 13:50:43 -0700 | [diff] [blame] | 40 | #include "ceres/internal/port.h" |
| 41 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 42 | namespace ceres { |
| 43 | |
| 44 | // Basic integer types. These typedefs are in the Ceres namespace to avoid |
| 45 | // conflicts with other packages having similar typedefs. |
| 46 | typedef short int16; |
| 47 | typedef int int32; |
| 48 | |
| 49 | // Argument type used in interfaces that can optionally take ownership |
| 50 | // of a passed in argument. If TAKE_OWNERSHIP is passed, the called |
| 51 | // object takes ownership of the pointer argument, and will call |
| 52 | // delete on it upon completion. |
| 53 | enum Ownership { |
| 54 | DO_NOT_TAKE_OWNERSHIP, |
| 55 | TAKE_OWNERSHIP |
| 56 | }; |
| 57 | |
| 58 | // TODO(keir): Considerably expand the explanations of each solver type. |
| 59 | enum LinearSolverType { |
| 60 | // These solvers are for general rectangular systems formed from the |
| 61 | // normal equations A'A x = A'b. They are direct solvers and do not |
| 62 | // assume any special problem structure. |
| 63 | |
Sameer Agarwal | b9f15a5 | 2012-08-18 13:06:19 -0700 | [diff] [blame] | 64 | // Solve the normal equations using a dense Cholesky solver; based |
| 65 | // on Eigen. |
| 66 | DENSE_NORMAL_CHOLESKY, |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 67 | |
| 68 | // Solve the normal equations using a dense QR solver; based on |
| 69 | // Eigen. |
| 70 | DENSE_QR, |
| 71 | |
Sameer Agarwal | b9f15a5 | 2012-08-18 13:06:19 -0700 | [diff] [blame] | 72 | // Solve the normal equations using a sparse cholesky solver; requires |
| 73 | // SuiteSparse or CXSparse. |
| 74 | SPARSE_NORMAL_CHOLESKY, |
| 75 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 76 | // Specialized solvers, specific to problems with a generalized |
| 77 | // bi-partitite structure. |
| 78 | |
| 79 | // Solves the reduced linear system using a dense Cholesky solver; |
| 80 | // based on Eigen. |
| 81 | DENSE_SCHUR, |
| 82 | |
| 83 | // Solves the reduced linear system using a sparse Cholesky solver; |
| 84 | // based on CHOLMOD. |
| 85 | SPARSE_SCHUR, |
| 86 | |
| 87 | // Solves the reduced linear system using Conjugate Gradients, based |
| 88 | // on a new Ceres implementation. Suitable for large scale |
| 89 | // problems. |
| 90 | ITERATIVE_SCHUR, |
| 91 | |
Keir Mierle | e2a6cdc | 2012-05-07 06:39:56 -0700 | [diff] [blame] | 92 | // Conjugate gradients on the normal equations. |
| 93 | CGNR |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | enum PreconditionerType { |
| 97 | // Trivial preconditioner - the identity matrix. |
| 98 | IDENTITY, |
| 99 | |
| 100 | // Block diagonal of the Gauss-Newton Hessian. |
| 101 | JACOBI, |
| 102 | |
| 103 | // Block diagonal of the Schur complement. This preconditioner may |
| 104 | // only be used with the ITERATIVE_SCHUR solver. Requires |
| 105 | // SuiteSparse/CHOLMOD. |
| 106 | SCHUR_JACOBI, |
| 107 | |
| 108 | // Visibility clustering based preconditioners. |
| 109 | // |
| 110 | // These preconditioners are well suited for Structure from Motion |
| 111 | // problems, particularly problems arising from community photo |
| 112 | // collections. These preconditioners use the visibility structure |
| 113 | // of the scene to determine the sparsity structure of the |
| 114 | // preconditioner. Requires SuiteSparse/CHOLMOD. |
| 115 | CLUSTER_JACOBI, |
| 116 | CLUSTER_TRIDIAGONAL |
| 117 | }; |
| 118 | |
Sameer Agarwal | b051873 | 2012-05-29 00:27:57 -0700 | [diff] [blame] | 119 | enum SparseLinearAlgebraLibraryType { |
| 120 | // High performance sparse Cholesky factorization and approximate |
| 121 | // minimum degree ordering. |
| 122 | SUITE_SPARSE, |
| 123 | |
| 124 | // A lightweight replacment for SuiteSparse. |
| 125 | CX_SPARSE |
| 126 | }; |
| 127 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 128 | enum LinearSolverTerminationType { |
| 129 | // Termination criterion was met. For factorization based solvers |
| 130 | // the tolerance is assumed to be zero. Any user provided values are |
| 131 | // ignored. |
| 132 | TOLERANCE, |
| 133 | |
| 134 | // Solver ran for max_num_iterations and terminated before the |
| 135 | // termination tolerance could be satified. |
| 136 | MAX_ITERATIONS, |
| 137 | |
| 138 | // Solver is stuck and further iterations will not result in any |
| 139 | // measurable progress. |
| 140 | STAGNATION, |
| 141 | |
| 142 | // Solver failed. Solver was terminated due to numerical errors. The |
| 143 | // exact cause of failure depends on the particular solver being |
| 144 | // used. |
| 145 | FAILURE |
| 146 | }; |
| 147 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 148 | // Logging options |
| 149 | // The options get progressively noisier. |
| 150 | enum LoggingType { |
| 151 | SILENT, |
Sameer Agarwal | 6447219 | 2012-05-03 21:53:07 -0700 | [diff] [blame] | 152 | PER_MINIMIZER_ITERATION |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 153 | }; |
| 154 | |
Sameer Agarwal | f4d0164 | 2012-11-26 12:55:58 -0800 | [diff] [blame] | 155 | enum MinimizerType { |
| 156 | LINE_SEARCH, |
| 157 | TRUST_REGION |
| 158 | }; |
| 159 | |
| 160 | enum LineSearchDirectionType { |
| 161 | // Negative of the gradient. |
| 162 | STEEPEST_DESCENT, |
| 163 | |
| 164 | // A generalization of the Conjugate Gradient method to non-linear |
| 165 | // functions. The generalization can be performed in a number of |
| 166 | // different ways, resulting in a variety of search directions. The |
| 167 | // precise choice of the non-linear conjugate gradient algorithm |
Sameer Agarwal | c89ea4b | 2013-01-09 16:09:35 -0800 | [diff] [blame] | 168 | // used is determined by NonlinerConjuateGradientType. |
Sameer Agarwal | f4d0164 | 2012-11-26 12:55:58 -0800 | [diff] [blame] | 169 | NONLINEAR_CONJUGATE_GRADIENT, |
Sameer Agarwal | 3e8d192 | 2012-11-28 17:20:22 -0800 | [diff] [blame] | 170 | |
| 171 | // A limited memory approximation to the inverse Hessian is |
| 172 | // maintained and used to compute a quasi-Newton step. |
| 173 | // |
| 174 | // For more details see |
| 175 | // |
| 176 | // Nocedal, J. (1980). "Updating Quasi-Newton Matrices with Limited |
| 177 | // Storage". Mathematics of Computation 35 (151): 773–782. |
| 178 | // |
| 179 | // Byrd, R. H.; Nocedal, J.; Schnabel, R. B. (1994). |
| 180 | // "Representations of Quasi-Newton Matrices and their use in |
| 181 | // Limited Memory Methods". Mathematical Programming 63 (4): |
| 182 | // 129–156. |
| 183 | LBFGS, |
Sameer Agarwal | f4d0164 | 2012-11-26 12:55:58 -0800 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | // Nonliner conjugate gradient methods are a generalization of the |
| 187 | // method of Conjugate Gradients for linear systems. The |
| 188 | // generalization can be carried out in a number of different ways |
| 189 | // leading to number of different rules for computing the search |
| 190 | // direction. Ceres provides a number of different variants. For more |
| 191 | // details see Numerical Optimization by Nocedal & Wright. |
| 192 | enum NonlinearConjugateGradientType { |
| 193 | FLETCHER_REEVES, |
| 194 | POLAK_RIBIRERE, |
Sameer Agarwal | 1afd498 | 2012-11-29 10:28:11 -0800 | [diff] [blame] | 195 | HESTENES_STIEFEL, |
Sameer Agarwal | f4d0164 | 2012-11-26 12:55:58 -0800 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | enum LineSearchType { |
| 199 | // Backtracking line search with polynomial interpolation or |
| 200 | // bisection. |
Sameer Agarwal | 1afd498 | 2012-11-29 10:28:11 -0800 | [diff] [blame] | 201 | ARMIJO, |
Sameer Agarwal | f4d0164 | 2012-11-26 12:55:58 -0800 | [diff] [blame] | 202 | }; |
| 203 | |
Sameer Agarwal | fa01519 | 2012-06-11 14:21:42 -0700 | [diff] [blame] | 204 | // Ceres supports different strategies for computing the trust region |
| 205 | // step. |
Sameer Agarwal | aa9a83c | 2012-05-29 17:40:17 -0700 | [diff] [blame] | 206 | enum TrustRegionStrategyType { |
Sameer Agarwal | fa01519 | 2012-06-11 14:21:42 -0700 | [diff] [blame] | 207 | // The default trust region strategy is to use the step computation |
| 208 | // used in the Levenberg-Marquardt algorithm. For more details see |
| 209 | // levenberg_marquardt_strategy.h |
Sameer Agarwal | aa9a83c | 2012-05-29 17:40:17 -0700 | [diff] [blame] | 210 | LEVENBERG_MARQUARDT, |
Sameer Agarwal | fa01519 | 2012-06-11 14:21:42 -0700 | [diff] [blame] | 211 | |
| 212 | // Powell's dogleg algorithm interpolates between the Cauchy point |
| 213 | // and the Gauss-Newton step. It is particularly useful if the |
| 214 | // LEVENBERG_MARQUARDT algorithm is making a large number of |
| 215 | // unsuccessful steps. For more details see dogleg_strategy.h. |
| 216 | // |
| 217 | // NOTES: |
| 218 | // |
| 219 | // 1. This strategy has not been experimented with or tested as |
| 220 | // extensively as LEVENBERG_MARQUARDT, and therefore it should be |
| 221 | // considered EXPERIMENTAL for now. |
| 222 | // |
| 223 | // 2. For now this strategy should only be used with exact |
| 224 | // factorization based linear solvers, i.e., SPARSE_SCHUR, |
| 225 | // DENSE_SCHUR, DENSE_QR and SPARSE_NORMAL_CHOLESKY. |
| 226 | DOGLEG |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 227 | }; |
| 228 | |
Markus Moll | 51cf7cb | 2012-08-20 20:10:20 +0200 | [diff] [blame] | 229 | // Ceres supports two different dogleg strategies. |
| 230 | // The "traditional" dogleg method by Powell and the |
| 231 | // "subspace" method described in |
| 232 | // R. H. Byrd, R. B. Schnabel, and G. A. Shultz, |
| 233 | // "Approximate solution of the trust region problem by minimization |
| 234 | // over two-dimensional subspaces", Mathematical Programming, |
| 235 | // 40 (1988), pp. 247--263 |
| 236 | enum DoglegType { |
| 237 | // The traditional approach constructs a dogleg path |
| 238 | // consisting of two line segments and finds the furthest |
| 239 | // point on that path that is still inside the trust region. |
| 240 | TRADITIONAL_DOGLEG, |
| 241 | |
| 242 | // The subspace approach finds the exact minimum of the model |
| 243 | // constrained to the subspace spanned by the dogleg path. |
| 244 | SUBSPACE_DOGLEG |
| 245 | }; |
| 246 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 247 | enum SolverTerminationType { |
| 248 | // The minimizer did not run at all; usually due to errors in the user's |
| 249 | // Problem or the solver options. |
| 250 | DID_NOT_RUN, |
| 251 | |
| 252 | // The solver ran for maximum number of iterations specified by the |
| 253 | // user, but none of the convergence criterion specified by the user |
| 254 | // were met. |
| 255 | NO_CONVERGENCE, |
| 256 | |
| 257 | // Minimizer terminated because |
| 258 | // (new_cost - old_cost) < function_tolerance * old_cost; |
| 259 | FUNCTION_TOLERANCE, |
| 260 | |
| 261 | // Minimizer terminated because |
| 262 | // max_i |gradient_i| < gradient_tolerance * max_i|initial_gradient_i| |
| 263 | GRADIENT_TOLERANCE, |
| 264 | |
| 265 | // Minimized terminated because |
| 266 | // |step|_2 <= parameter_tolerance * ( |x|_2 + parameter_tolerance) |
| 267 | PARAMETER_TOLERANCE, |
| 268 | |
| 269 | // The minimizer terminated because it encountered a numerical error |
| 270 | // that it could not recover from. |
| 271 | NUMERICAL_FAILURE, |
| 272 | |
| 273 | // Using an IterationCallback object, user code can control the |
| 274 | // minimizer. The following enums indicate that the user code was |
| 275 | // responsible for termination. |
| 276 | |
| 277 | // User's IterationCallback returned SOLVER_ABORT. |
| 278 | USER_ABORT, |
| 279 | |
| 280 | // User's IterationCallback returned SOLVER_TERMINATE_SUCCESSFULLY |
Sameer Agarwal | 6447219 | 2012-05-03 21:53:07 -0700 | [diff] [blame] | 281 | USER_SUCCESS |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 282 | }; |
| 283 | |
| 284 | // Enums used by the IterationCallback instances to indicate to the |
| 285 | // solver whether it should continue solving, the user detected an |
| 286 | // error or the solution is good enough and the solver should |
| 287 | // terminate. |
| 288 | enum CallbackReturnType { |
| 289 | // Continue solving to next iteration. |
| 290 | SOLVER_CONTINUE, |
| 291 | |
| 292 | // Terminate solver, and do not update the parameter blocks upon |
| 293 | // return. Unless the user has set |
| 294 | // Solver:Options:::update_state_every_iteration, in which case the |
| 295 | // state would have been updated every iteration |
| 296 | // anyways. Solver::Summary::termination_type is set to USER_ABORT. |
| 297 | SOLVER_ABORT, |
| 298 | |
| 299 | // Terminate solver, update state and |
| 300 | // return. Solver::Summary::termination_type is set to USER_SUCCESS. |
| 301 | SOLVER_TERMINATE_SUCCESSFULLY |
| 302 | }; |
| 303 | |
Sameer Agarwal | 82f4b88 | 2012-05-06 21:05:28 -0700 | [diff] [blame] | 304 | // The format in which linear least squares problems should be logged |
| 305 | // when Solver::Options::lsqp_iterations_to_dump is non-empty. |
| 306 | enum DumpFormatType { |
| 307 | // Print the linear least squares problem in a human readable format |
| 308 | // to stderr. The Jacobian is printed as a dense matrix. The vectors |
| 309 | // D, x and f are printed as dense vectors. This should only be used |
| 310 | // for small problems. |
| 311 | CONSOLE, |
| 312 | |
| 313 | // Write out the linear least squares problem to the directory |
| 314 | // pointed to by Solver::Options::lsqp_dump_directory as a protocol |
| 315 | // buffer. linear_least_squares_problems.h/cc contains routines for |
| 316 | // loading these problems. For details on the on disk format used, |
| 317 | // see matrix.proto. The files are named lm_iteration_???.lsqp. |
| 318 | PROTOBUF, |
| 319 | |
| 320 | // Write out the linear least squares problem to the directory |
| 321 | // pointed to by Solver::Options::lsqp_dump_directory as text files |
| 322 | // which can be read into MATLAB/Octave. The Jacobian is dumped as a |
| 323 | // text file containing (i,j,s) triplets, the vectors D, x and f are |
| 324 | // dumped as text files containing a list of their values. |
| 325 | // |
| 326 | // A MATLAB/octave script called lm_iteration_???.m is also output, |
| 327 | // which can be used to parse and load the problem into memory. |
| 328 | TEXTFILE |
| 329 | }; |
| 330 | |
Keir Mierle | fdeb577 | 2012-05-09 07:38:07 -0700 | [diff] [blame] | 331 | // For SizedCostFunction and AutoDiffCostFunction, DYNAMIC can be specified for |
| 332 | // the number of residuals. If specified, then the number of residuas for that |
| 333 | // cost function can vary at runtime. |
| 334 | enum DimensionType { |
| 335 | DYNAMIC = -1 |
| 336 | }; |
| 337 | |
Sameer Agarwal | 2fc0ed6 | 2013-01-15 11:34:10 -0800 | [diff] [blame] | 338 | enum NumericDiffMethod { |
| 339 | CENTRAL, |
| 340 | FORWARD |
| 341 | }; |
| 342 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 343 | const char* LinearSolverTypeToString(LinearSolverType type); |
Sameer Agarwal | cbae856 | 2012-09-02 13:50:43 -0700 | [diff] [blame] | 344 | bool StringToLinearSolverType(string value, LinearSolverType* type); |
| 345 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 346 | const char* PreconditionerTypeToString(PreconditionerType type); |
Sameer Agarwal | cbae856 | 2012-09-02 13:50:43 -0700 | [diff] [blame] | 347 | bool StringToPreconditionerType(string value, PreconditionerType* type); |
| 348 | |
Sameer Agarwal | b051873 | 2012-05-29 00:27:57 -0700 | [diff] [blame] | 349 | const char* SparseLinearAlgebraLibraryTypeToString( |
| 350 | SparseLinearAlgebraLibraryType type); |
Sameer Agarwal | cbae856 | 2012-09-02 13:50:43 -0700 | [diff] [blame] | 351 | bool StringToSparseLinearAlgebraLibraryType( |
| 352 | string value, |
| 353 | SparseLinearAlgebraLibraryType* type); |
| 354 | |
Sameer Agarwal | cbae856 | 2012-09-02 13:50:43 -0700 | [diff] [blame] | 355 | const char* TrustRegionStrategyTypeToString(TrustRegionStrategyType type); |
| 356 | bool StringToTrustRegionStrategyType(string value, |
| 357 | TrustRegionStrategyType* type); |
| 358 | |
| 359 | const char* DoglegTypeToString(DoglegType type); |
| 360 | bool StringToDoglegType(string value, DoglegType* type); |
| 361 | |
Sameer Agarwal | 1afd498 | 2012-11-29 10:28:11 -0800 | [diff] [blame] | 362 | const char* MinimizerTypeToString(MinimizerType type); |
| 363 | bool StringToMinimizerType(string value, MinimizerType* type); |
| 364 | |
| 365 | const char* LineSearchDirectionTypeToString(LineSearchDirectionType type); |
| 366 | bool StringToLineSearchDirectionType(string value, |
| 367 | LineSearchDirectionType* type); |
| 368 | |
| 369 | const char* LineSearchTypeToString(LineSearchType type); |
| 370 | bool StringToLineSearchType(string value, LineSearchType* type); |
| 371 | |
| 372 | const char* NonlinearConjugateGradientTypeToString( |
| 373 | NonlinearConjugateGradientType type); |
| 374 | bool StringToNonlinearConjugateGradientType( |
| 375 | string value, NonlinearConjugateGradientType* type); |
| 376 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 377 | const char* LinearSolverTerminationTypeToString( |
| 378 | LinearSolverTerminationType type); |
Sameer Agarwal | cbae856 | 2012-09-02 13:50:43 -0700 | [diff] [blame] | 379 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 380 | const char* SolverTerminationTypeToString(SolverTerminationType type); |
Sameer Agarwal | 14ee795 | 2012-09-06 11:05:32 -0700 | [diff] [blame] | 381 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 382 | bool IsSchurType(LinearSolverType type); |
Sameer Agarwal | 14ee795 | 2012-09-06 11:05:32 -0700 | [diff] [blame] | 383 | bool IsSparseLinearAlgebraLibraryTypeAvailable( |
| 384 | SparseLinearAlgebraLibraryType type); |
| 385 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 386 | |
| 387 | } // namespace ceres |
| 388 | |
| 389 | #endif // CERES_PUBLIC_TYPES_H_ |