NonlinearOptimizerParams.cpp
Go to the documentation of this file.
1 
12 
13 namespace gtsam {
14 
15 /* ************************************************************************* */
17  const std::string &src) {
18  std::string s = src;
19  // Convert to upper case
20  std::transform(s.begin(), s.end(), s.begin(), ::toupper);
21  if (s == "SILENT")
23  if (s == "ERROR")
25  if (s == "VALUES")
27  if (s == "DELTA")
29  if (s == "LINEAR")
31  if (s == "TERMINATION")
33 
34  /* default is silent */
36 }
37 
38 /* ************************************************************************* */
40  Verbosity value) {
41  std::string s;
42  switch (value) {
44  s = "SILENT";
45  break;
47  s = "TERMINATION";
48  break;
50  s = "ERROR";
51  break;
53  s = "VALUES";
54  break;
56  s = "DELTA";
57  break;
59  s = "LINEAR";
60  break;
61  default:
62  s = "UNDEFINED";
63  break;
64  }
65  return s;
66 }
67 
68 /* ************************************************************************* */
70  const std::shared_ptr<IterativeOptimizationParameters> params) {
72 }
73 
74 /* ************************************************************************* */
75 void NonlinearOptimizerParams::print(const std::string& str) const {
76 
77  //NonlinearOptimizerParams::print(str);
78  std::cout << str << "\n";
79  std::cout << "relative decrease threshold: " << relativeErrorTol << "\n";
80  std::cout << "absolute decrease threshold: " << absoluteErrorTol << "\n";
81  std::cout << " total error threshold: " << errorTol << "\n";
82  std::cout << " maximum iterations: " << maxIterations << "\n";
83  std::cout << " verbosity: " << verbosityTranslator(verbosity)
84  << "\n";
85  std::cout.flush();
86 
87  switch (linearSolverType) {
89  std::cout << " linear solver type: MULTIFRONTAL CHOLESKY\n";
90  break;
91  case MULTIFRONTAL_QR:
92  std::cout << " linear solver type: MULTIFRONTAL QR\n";
93  break;
95  std::cout << " linear solver type: SEQUENTIAL CHOLESKY\n";
96  break;
97  case SEQUENTIAL_QR:
98  std::cout << " linear solver type: SEQUENTIAL QR\n";
99  break;
100  case CHOLMOD:
101  std::cout << " linear solver type: CHOLMOD\n";
102  break;
103  case Iterative:
104  std::cout << " linear solver type: ITERATIVE\n";
105  break;
106  default:
107  std::cout << " linear solver type: (invalid)\n";
108  break;
109  }
110 
111  switch (orderingType){
112  case Ordering::COLAMD:
113  std::cout << " ordering: COLAMD\n";
114  break;
115  case Ordering::METIS:
116  std::cout << " ordering: METIS\n";
117  break;
118  default:
119  std::cout << " ordering: custom\n";
120  break;
121  }
122 
123  std::cout.flush();
124 }
125 
126 /* ************************************************************************* */
128  double tol) const {
129  // Check for equality of shared ptrs
130  bool iterative_params_equal = iterativeParams == other.iterativeParams;
131  // Check equality of components
132  if (iterativeParams && other.iterativeParams) {
133  iterative_params_equal = iterativeParams->equals(*other.iterativeParams);
134  } else {
135  // Check if either is null. If both are null, then true
136  iterative_params_equal = !iterativeParams && !other.iterativeParams;
137  }
138 
139  return maxIterations == other.getMaxIterations() &&
140  std::abs(relativeErrorTol - other.getRelativeErrorTol()) <= tol &&
141  std::abs(absoluteErrorTol - other.getAbsoluteErrorTol()) <= tol &&
142  std::abs(errorTol - other.getErrorTol()) <= tol &&
143  verbosityTranslator(verbosity) == other.getVerbosity() &&
144  orderingType == other.orderingType && ordering == other.ordering &&
145  linearSolverType == other.linearSolverType && iterative_params_equal;
146 }
147 
148 /* ************************************************************************* */
150  LinearSolverType linearSolverType) const {
151  switch (linearSolverType) {
153  return "MULTIFRONTAL_CHOLESKY";
154  case MULTIFRONTAL_QR:
155  return "MULTIFRONTAL_QR";
156  case SEQUENTIAL_CHOLESKY:
157  return "SEQUENTIAL_CHOLESKY";
158  case SEQUENTIAL_QR:
159  return "SEQUENTIAL_QR";
160  case Iterative:
161  return "ITERATIVE";
162  case CHOLMOD:
163  return "CHOLMOD";
164  default:
165  throw std::invalid_argument(
166  "Unknown linear solver type in SuccessiveLinearizationOptimizer");
167  }
168 }
169 
170 /* ************************************************************************* */
172  const std::string& linearSolverType) const {
173  if (linearSolverType == "MULTIFRONTAL_CHOLESKY")
174  return MULTIFRONTAL_CHOLESKY;
175  if (linearSolverType == "MULTIFRONTAL_QR")
176  return MULTIFRONTAL_QR;
177  if (linearSolverType == "SEQUENTIAL_CHOLESKY")
178  return SEQUENTIAL_CHOLESKY;
179  if (linearSolverType == "SEQUENTIAL_QR")
180  return SEQUENTIAL_QR;
181  if (linearSolverType == "ITERATIVE")
182  return Iterative;
183  if (linearSolverType == "CHOLMOD")
184  return CHOLMOD;
185  throw std::invalid_argument(
186  "Unknown linear solver type in SuccessiveLinearizationOptimizer");
187 }
188 
189 /* ************************************************************************* */
192  switch (type) {
193  case Ordering::METIS:
194  return "METIS";
195  case Ordering::COLAMD:
196  return "COLAMD";
197  default:
198  if (ordering)
199  return "CUSTOM";
200  else
201  throw std::invalid_argument(
202  "Invalid ordering type: You must provide an ordering for a custom ordering type. See setOrdering");
203  }
204 }
205 
206 /* ************************************************************************* */
208  const std::string& type) const {
209  if (type == "METIS")
210  return Ordering::METIS;
211  if (type == "COLAMD")
212  return Ordering::COLAMD;
213  throw std::invalid_argument(
214  "Invalid ordering type: You must provide an ordering for a custom ordering type. See setOrdering");
215 }
216 
217 
218 } // namespace
gtsam::NonlinearOptimizerParams::MULTIFRONTAL_QR
@ MULTIFRONTAL_QR
Definition: NonlinearOptimizerParams.h:100
gtsam::NonlinearOptimizerParams::absoluteErrorTol
double absoluteErrorTol
The maximum absolute error decrease to stop iterating (default 1e-5)
Definition: NonlinearOptimizerParams.h:44
s
RealScalar s
Definition: level1_cplx_impl.h:126
gtsam::NonlinearOptimizerParams::iterativeParams
IterativeOptimizationParameters::shared_ptr iterativeParams
The container for iterativeOptimization parameters. used in CG Solvers.
Definition: NonlinearOptimizerParams.h:109
gtsam::NonlinearOptimizerParams::SILENT
@ SILENT
Definition: NonlinearOptimizerParams.h:39
gtsam::NonlinearOptimizerParams::Verbosity
Verbosity
Definition: NonlinearOptimizerParams.h:38
type
Definition: pytypes.h:1525
gtsam::NonlinearOptimizerParams::verbosity
Verbosity verbosity
The printing verbosity during optimization (default SILENT)
Definition: NonlinearOptimizerParams.h:46
vanilla::params
static const SmartProjectionParams params
Definition: smartFactorScenarios.h:69
gtsam::NonlinearOptimizerParams::SEQUENTIAL_CHOLESKY
@ SEQUENTIAL_CHOLESKY
Definition: NonlinearOptimizerParams.h:101
gtsam::NonlinearOptimizerParams::SEQUENTIAL_QR
@ SEQUENTIAL_QR
Definition: NonlinearOptimizerParams.h:102
gtsam::NonlinearOptimizerParams::orderingType
Ordering::OrderingType orderingType
The method of ordering use during variable elimination (default COLAMD)
Definition: NonlinearOptimizerParams.h:47
gtsam::NonlinearOptimizerParams::CHOLMOD
@ CHOLMOD
Definition: NonlinearOptimizerParams.h:104
gtsam::NonlinearOptimizerParams::orderingTypeTranslator
std::string orderingTypeTranslator(Ordering::OrderingType type) const
Definition: NonlinearOptimizerParams.cpp:190
gtsam::NonlinearOptimizerParams
Definition: NonlinearOptimizerParams.h:35
gtsam::NonlinearOptimizerParams::TERMINATION
@ TERMINATION
Definition: NonlinearOptimizerParams.h:39
gtsam::NonlinearOptimizerParams::equals
bool equals(const NonlinearOptimizerParams &other, double tol=1e-9) const
Definition: NonlinearOptimizerParams.cpp:127
transform
EIGEN_DONT_INLINE void transform(const Transformation &t, Data &data)
Definition: geometry.cpp:25
gtsam::NonlinearOptimizerParams::LinearSolverType
LinearSolverType
Definition: NonlinearOptimizerParams.h:98
str
Definition: pytypes.h:1558
gtsam::Ordering::OrderingType
OrderingType
Type of ordering to use.
Definition: inference/Ordering.h:40
gtsam::NonlinearOptimizerParams::print
virtual void print(const std::string &str="") const
Definition: NonlinearOptimizerParams.cpp:75
gtsam::NonlinearOptimizerParams::LINEAR
@ LINEAR
Definition: NonlinearOptimizerParams.h:39
gtsam
traits
Definition: SFMdata.h:40
gtsam::Ordering::METIS
@ METIS
Definition: inference/Ordering.h:41
gtsam::NonlinearOptimizerParams::Iterative
@ Iterative
Definition: NonlinearOptimizerParams.h:103
gtsam::NonlinearOptimizerParams::verbosityTranslator
static Verbosity verbosityTranslator(const std::string &s)
Definition: NonlinearOptimizerParams.cpp:16
gtsam::NonlinearOptimizerParams::relativeErrorTol
double relativeErrorTol
The maximum relative error decrease to stop iterating (default 1e-5)
Definition: NonlinearOptimizerParams.h:43
gtsam::NonlinearOptimizerParams::maxIterations
size_t maxIterations
The maximum iterations to stop iterating (default 100)
Definition: NonlinearOptimizerParams.h:42
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::NonlinearOptimizerParams::errorTol
double errorTol
The maximum total error to stop iterating (default 0.0)
Definition: NonlinearOptimizerParams.h:45
abs
#define abs(x)
Definition: datatypes.h:17
gtsam::NonlinearOptimizerParams::ERROR
@ ERROR
Definition: NonlinearOptimizerParams.h:39
gtsam::NonlinearOptimizerParams::DELTA
@ DELTA
Definition: NonlinearOptimizerParams.h:39
gtsam::NonlinearOptimizerParams::ordering
std::optional< Ordering > ordering
The optional variable elimination ordering, or empty to use COLAMD (default: empty)
Definition: NonlinearOptimizerParams.h:108
NonlinearOptimizerParams.h
Parameters for nonlinear optimization.
gtsam::Ordering::COLAMD
@ COLAMD
Definition: inference/Ordering.h:41
gtsam::NonlinearOptimizerParams::linearSolverTranslator
std::string linearSolverTranslator(LinearSolverType linearSolverType) const
Definition: NonlinearOptimizerParams.cpp:149
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::NonlinearOptimizerParams::setIterativeParams
void setIterativeParams(const std::shared_ptr< IterativeOptimizationParameters > params)
Definition: NonlinearOptimizerParams.cpp:69
gtsam::NonlinearOptimizerParams::linearSolverType
LinearSolverType linearSolverType
The type of linear solver to use in the nonlinear optimizer.
Definition: NonlinearOptimizerParams.h:107
gtsam::NonlinearOptimizerParams::MULTIFRONTAL_CHOLESKY
@ MULTIFRONTAL_CHOLESKY
Definition: NonlinearOptimizerParams.h:99


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:12:24