gtsam  4.0.0
gtsam
NonlinearOptimizerParams.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
22 #pragma once
23 
26 #include <boost/optional.hpp>
27 #include <string>
28 
29 namespace gtsam {
30 
34 class GTSAM_EXPORT NonlinearOptimizerParams {
35 public:
37  enum Verbosity {
38  SILENT, TERMINATION, ERROR, VALUES, DELTA, LINEAR
39  };
40 
41  size_t maxIterations;
44  double errorTol;
47 
49  maxIterations(100), relativeErrorTol(1e-5), absoluteErrorTol(1e-5), errorTol(
50  0.0), verbosity(SILENT), orderingType(Ordering::COLAMD),
51  linearSolverType(MULTIFRONTAL_CHOLESKY) {}
52 
53  virtual ~NonlinearOptimizerParams() {
54  }
55  virtual void print(const std::string& str = "") const;
56 
57  size_t getMaxIterations() const { return maxIterations; }
58  double getRelativeErrorTol() const { return relativeErrorTol; }
59  double getAbsoluteErrorTol() const { return absoluteErrorTol; }
60  double getErrorTol() const { return errorTol; }
61  std::string getVerbosity() const { return verbosityTranslator(verbosity); }
62 
63  void setMaxIterations(int value) { maxIterations = value; }
64  void setRelativeErrorTol(double value) { relativeErrorTol = value; }
65  void setAbsoluteErrorTol(double value) { absoluteErrorTol = value; }
66  void setErrorTol(double value) { errorTol = value; }
67  void setVerbosity(const std::string& src) {
68  verbosity = verbosityTranslator(src);
69  }
70 
71  static Verbosity verbosityTranslator(const std::string &s) ;
72  static std::string verbosityTranslator(Verbosity value) ;
73 
76  MULTIFRONTAL_CHOLESKY,
77  MULTIFRONTAL_QR,
78  SEQUENTIAL_CHOLESKY,
79  SEQUENTIAL_QR,
80  Iterative, /* Experimental Flag */
81  CHOLMOD, /* Experimental Flag */
82  };
83 
85  boost::optional<Ordering> ordering;
86  IterativeOptimizationParameters::shared_ptr iterativeParams;
87 
88  inline bool isMultifrontal() const {
89  return (linearSolverType == MULTIFRONTAL_CHOLESKY)
90  || (linearSolverType == MULTIFRONTAL_QR);
91  }
92 
93  inline bool isSequential() const {
94  return (linearSolverType == SEQUENTIAL_CHOLESKY)
95  || (linearSolverType == SEQUENTIAL_QR);
96  }
97 
98  inline bool isCholmod() const {
99  return (linearSolverType == CHOLMOD);
100  }
101 
102  inline bool isIterative() const {
103  return (linearSolverType == Iterative);
104  }
105 
106  GaussianFactorGraph::Eliminate getEliminationFunction() const {
107  switch (linearSolverType) {
108  case MULTIFRONTAL_CHOLESKY:
109  case SEQUENTIAL_CHOLESKY:
110  return EliminatePreferCholesky;
111 
112  case MULTIFRONTAL_QR:
113  case SEQUENTIAL_QR:
114  return EliminateQR;
115 
116  default:
117  throw std::runtime_error(
118  "Nonlinear optimization parameter \"factorization\" is invalid");
119  }
120  }
121 
122  std::string getLinearSolverType() const {
123  return linearSolverTranslator(linearSolverType);
124  }
125 
126  void setLinearSolverType(const std::string& solver) {
127  linearSolverType = linearSolverTranslator(solver);
128  }
129 
130  void setIterativeParams(const boost::shared_ptr<IterativeOptimizationParameters> params);
131 
132  void setOrdering(const Ordering& ordering) {
133  this->ordering = ordering;
134  this->orderingType = Ordering::CUSTOM;
135  }
136 
137  std::string getOrderingType() const {
138  return orderingTypeTranslator(orderingType);
139  }
140 
141  // Note that if you want to use a custom ordering, you must set the ordering directly, this will switch to custom type
142  void setOrderingType(const std::string& ordering){
143  orderingType = orderingTypeTranslator(ordering);
144  }
145 
146 private:
147  std::string linearSolverTranslator(LinearSolverType linearSolverType) const;
148  LinearSolverType linearSolverTranslator(const std::string& linearSolverType) const;
149  std::string orderingTypeTranslator(Ordering::OrderingType type) const;
150  Ordering::OrderingType orderingTypeTranslator(const std::string& type) const;
151 };
152 
153 // For backward compatibility:
154 typedef NonlinearOptimizerParams SuccessiveLinearizationParams;
155 
156 } /* namespace gtsam */
double absoluteErrorTol
The maximum absolute error decrease to stop iterating (default 1e-5)
Definition: NonlinearOptimizerParams.h:43
LinearSolverType linearSolverType
The type of linear solver to use in the nonlinear optimizer.
Definition: NonlinearOptimizerParams.h:84
Ordering::OrderingType orderingType
The method of ordering use during variable elimination (default COLAMD)
Definition: NonlinearOptimizerParams.h:46
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:141
LinearSolverType
See NonlinearOptimizerParams::linearSolverType.
Definition: NonlinearOptimizerParams.h:75
size_t maxIterations
The maximum iterations to stop iterating (default 100)
Definition: NonlinearOptimizerParams.h:41
std::pair< GaussianConditional::shared_ptr, JacobianFactor::shared_ptr > EliminateQR(const GaussianFactorGraph &factors, const Ordering &keys)
Multiply all factors and eliminate the given keys from the resulting factor using a QR variant that h...
Definition: JacobianFactor.cpp:721
Verbosity
See NonlinearOptimizerParams::verbosity.
Definition: NonlinearOptimizerParams.h:37
boost::optional< Ordering > ordering
The variable elimination ordering, or empty to use COLAMD (default: empty)
Definition: NonlinearOptimizerParams.h:85
double errorTol
The maximum total error to stop iterating (default 0.0)
Definition: NonlinearOptimizerParams.h:44
Verbosity verbosity
The printing verbosity during optimization (default SILENT)
Definition: NonlinearOptimizerParams.h:45
OrderingType
Type of ordering to use.
Definition: Ordering.h:41
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Subgraph Solver from IROS 2010.
The common parameters for Nonlinear optimizers.
Definition: NonlinearOptimizerParams.h:34
Linear Factor Graph where all factors are Gaussians.
boost::function< EliminationResult(const FactorGraphType &, const Ordering &)> Eliminate
The function type that does a single dense elimination step on a subgraph.
Definition: EliminateableFactorGraph.h:89
IterativeOptimizationParameters::shared_ptr iterativeParams
The container for iterativeOptimization parameters. used in CG Solvers.
Definition: NonlinearOptimizerParams.h:86
Definition: Ordering.h:34
double relativeErrorTol
The maximum relative error decrease to stop iterating (default 1e-5)
Definition: NonlinearOptimizerParams.h:42