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 | |
| 40 | namespace ceres { |
| 41 | |
| 42 | // Basic integer types. These typedefs are in the Ceres namespace to avoid |
| 43 | // conflicts with other packages having similar typedefs. |
| 44 | typedef short int16; |
| 45 | typedef 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. |
| 51 | enum Ownership { |
| 52 | DO_NOT_TAKE_OWNERSHIP, |
| 53 | TAKE_OWNERSHIP |
| 54 | }; |
| 55 | |
| 56 | // TODO(keir): Considerably expand the explanations of each solver type. |
| 57 | enum 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 Mierle | e2a6cdc | 2012-05-07 06:39:56 -0700 | [diff] [blame] | 86 | // Conjugate gradients on the normal equations. |
| 87 | CGNR |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | enum 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 Agarwal | b051873 | 2012-05-29 00:27:57 -0700 | [diff] [blame] | 113 | enum 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 Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 122 | enum 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 | |
| 142 | enum 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. |
| 156 | enum LoggingType { |
| 157 | SILENT, |
Sameer Agarwal | 6447219 | 2012-05-03 21:53:07 -0700 | [diff] [blame] | 158 | PER_MINIMIZER_ITERATION |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
Sameer Agarwal | fa01519 | 2012-06-11 14:21:42 -0700 | [diff] [blame] | 161 | // Ceres supports different strategies for computing the trust region |
| 162 | // step. |
Sameer Agarwal | aa9a83c | 2012-05-29 17:40:17 -0700 | [diff] [blame] | 163 | enum TrustRegionStrategyType { |
Sameer Agarwal | fa01519 | 2012-06-11 14:21:42 -0700 | [diff] [blame] | 164 | // 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 Agarwal | aa9a83c | 2012-05-29 17:40:17 -0700 | [diff] [blame] | 167 | LEVENBERG_MARQUARDT, |
Sameer Agarwal | fa01519 | 2012-06-11 14:21:42 -0700 | [diff] [blame] | 168 | |
| 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 Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | enum 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 Agarwal | 6447219 | 2012-05-03 21:53:07 -0700 | [diff] [blame] | 220 | USER_SUCCESS |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 221 | }; |
| 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. |
| 227 | enum 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 Agarwal | 82f4b88 | 2012-05-06 21:05:28 -0700 | [diff] [blame] | 243 | // The format in which linear least squares problems should be logged |
| 244 | // when Solver::Options::lsqp_iterations_to_dump is non-empty. |
| 245 | enum 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 Mierle | fdeb577 | 2012-05-09 07:38:07 -0700 | [diff] [blame] | 270 | // 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. |
| 273 | enum DimensionType { |
| 274 | DYNAMIC = -1 |
| 275 | }; |
| 276 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 277 | const char* LinearSolverTypeToString(LinearSolverType type); |
| 278 | const char* PreconditionerTypeToString(PreconditionerType type); |
Sameer Agarwal | b051873 | 2012-05-29 00:27:57 -0700 | [diff] [blame] | 279 | const char* SparseLinearAlgebraLibraryTypeToString( |
| 280 | SparseLinearAlgebraLibraryType type); |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 281 | const char* LinearSolverTerminationTypeToString( |
| 282 | LinearSolverTerminationType type); |
| 283 | const char* OrderingTypeToString(OrderingType type); |
| 284 | const char* SolverTerminationTypeToString(SolverTerminationType type); |
Sameer Agarwal | fa01519 | 2012-06-11 14:21:42 -0700 | [diff] [blame] | 285 | const char* SparseLinearAlgebraLibraryTypeToString( |
| 286 | SparseLinearAlgebraLibraryType type); |
| 287 | const char* TrustRegionStrategyTypeToString( TrustRegionStrategyType type); |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 288 | bool IsSchurType(LinearSolverType type); |
| 289 | |
| 290 | } // namespace ceres |
| 291 | |
| 292 | #endif // CERES_PUBLIC_TYPES_H_ |