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 
27 #include <string>
28 #include <optional>
29 
30 namespace gtsam {
31 
35 class GTSAM_EXPORT NonlinearOptimizerParams {
36 public:
38  enum Verbosity {
39  SILENT, TERMINATION, ERROR, VALUES, DELTA, LINEAR
40  };
41 
42  size_t maxIterations = 100;
43  double relativeErrorTol = 1e-5;
44  double absoluteErrorTol = 1e-5;
45  double errorTol = 0.0;
46  Verbosity verbosity = SILENT;
48 
49  size_t getMaxIterations() const { return maxIterations; }
50  double getRelativeErrorTol() const { return relativeErrorTol; }
51  double getAbsoluteErrorTol() const { return absoluteErrorTol; }
52  double getErrorTol() const { return errorTol; }
53  std::string getVerbosity() const { return verbosityTranslator(verbosity); }
54 
55  void setMaxIterations(int value) { maxIterations = value; }
56  void setRelativeErrorTol(double value) { relativeErrorTol = value; }
57  void setAbsoluteErrorTol(double value) { absoluteErrorTol = value; }
58  void setErrorTol(double value) { errorTol = value; }
59  void setVerbosity(const std::string& src) {
60  verbosity = verbosityTranslator(src);
61  }
62 
63  static Verbosity verbosityTranslator(const std::string &s) ;
64  static std::string verbosityTranslator(Verbosity value) ;
65 
68  using IterationHook = std::function<
69  void(size_t /*iteration*/, double/*errorBefore*/, double/*errorAfter*/)>;
70 
96 
103  Iterative, /* Experimental Flag */
104  CHOLMOD, /* Experimental Flag */
105  };
106 
107  LinearSolverType linearSolverType = MULTIFRONTAL_CHOLESKY;
108  std::optional<Ordering> ordering;
110 
111  NonlinearOptimizerParams() = default;
113  }
114 
115  virtual void print(const std::string& str = "") const;
116 
117  bool equals(const NonlinearOptimizerParams& other, double tol = 1e-9) const;
118 
119  inline bool isMultifrontal() const {
120  return (linearSolverType == MULTIFRONTAL_CHOLESKY)
121  || (linearSolverType == MULTIFRONTAL_QR);
122  }
123 
124  inline bool isSequential() const {
125  return (linearSolverType == SEQUENTIAL_CHOLESKY)
126  || (linearSolverType == SEQUENTIAL_QR);
127  }
128 
129  inline bool isCholmod() const {
130  return (linearSolverType == CHOLMOD);
131  }
132 
133  inline bool isIterative() const {
134  return (linearSolverType == Iterative);
135  }
136 
138  switch (linearSolverType) {
139  case MULTIFRONTAL_CHOLESKY:
140  case SEQUENTIAL_CHOLESKY:
142 
143  case MULTIFRONTAL_QR:
144  case SEQUENTIAL_QR:
145  return EliminateQR;
146 
147  default:
148  throw std::runtime_error(
149  "Nonlinear optimization parameter \"factorization\" is invalid");
150  }
151  }
152 
153  std::string getLinearSolverType() const {
154  return linearSolverTranslator(linearSolverType);
155  }
156 
157  void setLinearSolverType(const std::string& solver) {
158  linearSolverType = linearSolverTranslator(solver);
159  }
160 
161  void setIterativeParams(const std::shared_ptr<IterativeOptimizationParameters> params);
162 
164  this->ordering = ordering;
165  this->orderingType = Ordering::CUSTOM;
166  }
167 
168  std::string getOrderingType() const {
169  return orderingTypeTranslator(orderingType);
170  }
171 
172  // Note that if you want to use a custom ordering, you must set the ordering directly, this will switch to custom type
173  void setOrderingType(const std::string& ordering){
174  orderingType = orderingTypeTranslator(ordering);
175  }
176 
177 private:
178  std::string linearSolverTranslator(LinearSolverType linearSolverType) const;
179  LinearSolverType linearSolverTranslator(const std::string& linearSolverType) const;
180  std::string orderingTypeTranslator(Ordering::OrderingType type) const;
181  Ordering::OrderingType orderingTypeTranslator(const std::string& type) const;
182 };
183 
184 // For backward compatibility:
186 
187 } /* namespace gtsam */
gtsam::NonlinearOptimizerParams::MULTIFRONTAL_QR
@ MULTIFRONTAL_QR
Definition: NonlinearOptimizerParams.h:100
gtsam::NonlinearOptimizerParams::isSequential
bool isSequential() const
Definition: NonlinearOptimizerParams.h:124
GaussianFactorGraph.h
Linear Factor Graph where all factors are Gaussians.
gtsam::IterativeOptimizationParameters::shared_ptr
std::shared_ptr< IterativeOptimizationParameters > shared_ptr
Definition: IterativeSolver.h:45
SubgraphSolver.h
Subgraph Solver from IROS 2010.
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::NonlinearOptimizerParams::setVerbosity
void setVerbosity(const std::string &src)
Definition: NonlinearOptimizerParams.h:59
gtsam::NonlinearOptimizerParams::iterativeParams
IterativeOptimizationParameters::shared_ptr iterativeParams
The container for iterativeOptimization parameters. used in CG Solvers.
Definition: NonlinearOptimizerParams.h:109
gtsam::NonlinearOptimizerParams::Verbosity
Verbosity
Definition: NonlinearOptimizerParams.h:38
type
Definition: pytypes.h:1525
gtsam::NonlinearOptimizerParams::setRelativeErrorTol
void setRelativeErrorTol(double value)
Definition: NonlinearOptimizerParams.h:56
gtsam::NonlinearOptimizerParams::setLinearSolverType
void setLinearSolverType(const std::string &solver)
Definition: NonlinearOptimizerParams.h:157
gtsam::Ordering::CUSTOM
@ CUSTOM
Definition: inference/Ordering.h:41
gtsam::NonlinearOptimizerParams::setOrderingType
void setOrderingType(const std::string &ordering)
Definition: NonlinearOptimizerParams.h:173
vanilla::params
static const SmartProjectionParams params
Definition: smartFactorScenarios.h:69
gtsam::NonlinearOptimizerParams::setOrdering
void setOrdering(const Ordering &ordering)
Definition: NonlinearOptimizerParams.h:163
gtsam::NonlinearOptimizerParams::iterationHook
IterationHook iterationHook
Definition: NonlinearOptimizerParams.h:95
solver
BiCGSTAB< SparseMatrix< double > > solver
Definition: BiCGSTAB_simple.cpp:5
gtsam::NonlinearOptimizerParams::SEQUENTIAL_CHOLESKY
@ SEQUENTIAL_CHOLESKY
Definition: NonlinearOptimizerParams.h:101
gtsam::NonlinearOptimizerParams::SEQUENTIAL_QR
@ SEQUENTIAL_QR
Definition: NonlinearOptimizerParams.h:102
gtsam::NonlinearOptimizerParams::getVerbosity
std::string getVerbosity() const
Definition: NonlinearOptimizerParams.h:53
gtsam::EliminatePreferCholesky
std::pair< std::shared_ptr< GaussianConditional >, std::shared_ptr< GaussianFactor > > EliminatePreferCholesky(const GaussianFactorGraph &factors, const Ordering &keys)
Definition: HessianFactor.cpp:540
gtsam::NonlinearOptimizerParams::getMaxIterations
size_t getMaxIterations() const
Definition: NonlinearOptimizerParams.h:49
gtsam::NonlinearOptimizerParams::CHOLMOD
@ CHOLMOD
Definition: NonlinearOptimizerParams.h:104
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
gtsam::NonlinearOptimizerParams::IterationHook
std::function< void(size_t, double, double)> IterationHook
Definition: NonlinearOptimizerParams.h:69
gtsam::NonlinearOptimizerParams
Definition: NonlinearOptimizerParams.h:35
gtsam::NonlinearOptimizerParams::getLinearSolverType
std::string getLinearSolverType() const
Definition: NonlinearOptimizerParams.h:153
gtsam::NonlinearOptimizerParams::isIterative
bool isIterative() const
Definition: NonlinearOptimizerParams.h:133
gtsam::NonlinearOptimizerParams::setErrorTol
void setErrorTol(double value)
Definition: NonlinearOptimizerParams.h:58
gtsam::NonlinearOptimizerParams::LinearSolverType
LinearSolverType
Definition: NonlinearOptimizerParams.h:98
ordering
static enum @1096 ordering
gtsam::equals
Definition: Testable.h:112
str
Definition: pytypes.h:1558
gtsam::NonlinearOptimizerParams::getOrderingType
std::string getOrderingType() const
Definition: NonlinearOptimizerParams.h:168
gtsam::Ordering::OrderingType
OrderingType
Type of ordering to use.
Definition: inference/Ordering.h:40
gtsam::NonlinearOptimizerParams::~NonlinearOptimizerParams
virtual ~NonlinearOptimizerParams()
Definition: NonlinearOptimizerParams.h:112
gtsam::NonlinearOptimizerParams::getRelativeErrorTol
double getRelativeErrorTol() const
Definition: NonlinearOptimizerParams.h:50
gtsam
traits
Definition: SFMdata.h:40
gtsam::NonlinearOptimizerParams::Iterative
@ Iterative
Definition: NonlinearOptimizerParams.h:103
gtsam::NonlinearOptimizerParams::isMultifrontal
bool isMultifrontal() const
Definition: NonlinearOptimizerParams.h:119
gtsam::NonlinearOptimizerParams::getAbsoluteErrorTol
double getAbsoluteErrorTol() const
Definition: NonlinearOptimizerParams.h:51
gtsam::EliminateableFactorGraph< GaussianFactorGraph >::Eliminate
std::function< EliminationResult(const FactorGraphType &, const Ordering &)> Eliminate
The function type that does a single dense elimination step on a subgraph.
Definition: EliminateableFactorGraph.h:88
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::NonlinearOptimizerParams::setMaxIterations
void setMaxIterations(int value)
Definition: NonlinearOptimizerParams.h:55
gtsam::NonlinearOptimizerParams::setAbsoluteErrorTol
void setAbsoluteErrorTol(double value)
Definition: NonlinearOptimizerParams.h:57
gtsam::NonlinearOptimizerParams::ordering
std::optional< Ordering > ordering
The optional variable elimination ordering, or empty to use COLAMD (default: empty)
Definition: NonlinearOptimizerParams.h:108
gtsam::NonlinearOptimizerParams::getErrorTol
double getErrorTol() const
Definition: NonlinearOptimizerParams.h:52
gtsam::NonlinearOptimizerParams::isCholmod
bool isCholmod() const
Definition: NonlinearOptimizerParams.h:129
gtsam::NonlinearOptimizerParams::getEliminationFunction
GaussianFactorGraph::Eliminate getEliminationFunction() const
Definition: NonlinearOptimizerParams.h:137
gtsam::Ordering
Definition: inference/Ordering.h:33
gtsam::Ordering::COLAMD
@ COLAMD
Definition: inference/Ordering.h:41
gtsam::NonlinearOptimizerParams::VALUES
@ VALUES
Definition: NonlinearOptimizerParams.h:39
test_callbacks.value
value
Definition: test_callbacks.py:160
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
gtsam::SuccessiveLinearizationParams
NonlinearOptimizerParams SuccessiveLinearizationParams
Definition: NonlinearOptimizerParams.h:185
gtsam::EliminateQR
std::pair< GaussianConditional::shared_ptr, JacobianFactor::shared_ptr > EliminateQR(const GaussianFactorGraph &factors, const Ordering &keys)
Definition: JacobianFactor.cpp:778
gtsam::NonlinearOptimizerParams::MULTIFRONTAL_CHOLESKY
@ MULTIFRONTAL_CHOLESKY
Definition: NonlinearOptimizerParams.h:99


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:33:51