DoglegOptimizer.cpp
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 
26 
27 namespace gtsam {
28 
29 /* ************************************************************************* */
30 DoglegParams::VerbosityDL DoglegParams::verbosityDLTranslator(const std::string &verbosityDL) const {
31  std::string s = verbosityDL;
32  // convert to upper case
33  std::transform(s.begin(), s.end(), s.begin(), ::toupper);
34  if (s == "SILENT") return DoglegParams::SILENT;
35  if (s == "VERBOSE") return DoglegParams::VERBOSE;
36 
37  /* default is silent */
38  return DoglegParams::SILENT;
39 }
40 
41 /* ************************************************************************* */
42 std::string DoglegParams::verbosityDLTranslator(VerbosityDL verbosityDL) const {
43  std::string s;
44  switch (verbosityDL) {
45  case DoglegParams::SILENT: s = "SILENT"; break;
46  case DoglegParams::VERBOSE: s = "VERBOSE"; break;
47  default: s = "UNDEFINED"; break;
48  }
49  return s;
50 }
51 
52 /* ************************************************************************* */
53 namespace internal {
55  const double delta;
56 
57  DoglegState(const Values& _values, double _error, double _delta, unsigned int _iterations = 0)
58  : NonlinearOptimizerState(_values, _error, _iterations), delta(_delta) {}
59 };
60 }
61 
63 
64 /* ************************************************************************* */
66  const DoglegParams& params)
68  graph, std::unique_ptr<State>(
69  new State(initialValues, graph.error(initialValues), params.deltaInitial))),
70  params_(ensureHasOrdering(params, graph)) {}
71 
73  const Ordering& ordering)
74  : NonlinearOptimizer(graph, std::unique_ptr<State>(
75  new State(initialValues, graph.error(initialValues), 1.0))) {
77 }
78 
79 double DoglegOptimizer::getDelta() const {
80  return static_cast<const State*>(state_.get())->delta;
81 }
82 
83 /* ************************************************************************* */
85 
86  // Linearize graph
88 
89  // Pull out parameters we'll use
90  const bool dlVerbose = (params_.verbosityDL > DoglegParams::SILENT);
91 
92  // Do Dogleg iteration with either Multifrontal or Sequential elimination
94 
95  if ( params_.isMultifrontal() ) {
96  GaussianBayesTree bt = *linear->eliminateMultifrontal(*params_.ordering, params_.getEliminationFunction());
98  VectorValues dx_n = bt.optimize();
100  dx_u, dx_n, bt, graph_, state_->values, state_->error, dlVerbose);
101  }
102  else if ( params_.isSequential() ) {
103  GaussianBayesNet bn = *linear->eliminateSequential(*params_.ordering, params_.getEliminationFunction());
105  VectorValues dx_n = bn.optimize();
107  dx_u, dx_n, bn, graph_, state_->values, state_->error, dlVerbose);
108  }
109  else if ( params_.isIterative() ) {
110  throw std::runtime_error("Dogleg is not currently compatible with the linear conjugate gradient solver");
111  }
112  else {
113  throw std::runtime_error("Optimization parameter is invalid: DoglegParams::elimination");
114  }
115 
116  // Maybe show output
117  if(params_.verbosity >= NonlinearOptimizerParams::DELTA) result.dx_d.print("delta");
118 
119  // Create new state with new values and new error
120  state_.reset(new State(state_->values.retract(result.dx_d), result.f_error, result.delta,
121  state_->iterations + 1));
122  return linear;
123 }
124 
125 /* ************************************************************************* */
127  if (!params.ordering)
129  return params;
130 }
131 
132 } /* namespace gtsam */
gtsam::NonlinearOptimizerParams::isSequential
bool isSequential() const
Definition: NonlinearOptimizerParams.h:124
GaussianFactorGraph.h
Linear Factor Graph where all factors are Gaussians.
gtsam::GaussianFactorGraph::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactorGraph.h:82
gtsam::NonlinearOptimizer::graph
const NonlinearFactorGraph & graph() const
return the graph with nonlinear factors
Definition: NonlinearOptimizer.h:118
gtsam::GaussianBayesNet::optimizeGradientSearch
VectorValues optimizeGradientSearch() const
Definition: GaussianBayesNet.cpp:89
s
RealScalar s
Definition: level1_cplx_impl.h:126
gtsam::DoglegOptimizerImpl::Iterate
static IterationResult Iterate(double delta, TrustRegionAdaptationMode mode, const VectorValues &dx_u, const VectorValues &dx_n, const M &Rd, const F &f, const VALUES &x0, const double f_error, const bool verbose=false)
Definition: DoglegOptimizerImpl.h:138
NonlinearOptimizerState.h
Private class for NonlinearOptimizer state.
gtsam::internal::DoglegState
Definition: DoglegOptimizer.cpp:54
gtsam::DoglegOptimizerImpl::ONE_STEP_PER_ITERATION
@ ONE_STEP_PER_ITERATION
Definition: DoglegOptimizerImpl.h:56
gtsam::Ordering::Create
static Ordering Create(OrderingType orderingType, const FACTOR_GRAPH &graph)
Definition: inference/Ordering.h:217
gtsam::DoglegParams::SILENT
@ SILENT
Definition: DoglegOptimizer.h:36
gtsam::GaussianBayesTree::optimizeGradientSearch
VectorValues optimizeGradientSearch() const
Definition: GaussianBayesTree.cpp:73
gtsam::NonlinearOptimizerParams::verbosity
Verbosity verbosity
The printing verbosity during optimization (default SILENT)
Definition: NonlinearOptimizerParams.h:46
gtsam::NonlinearFactorGraph::linearize
std::shared_ptr< GaussianFactorGraph > linearize(const Values &linearizationPoint) const
Linearize a nonlinear factor graph.
Definition: NonlinearFactorGraph.cpp:239
gtsam::internal::DoglegState::DoglegState
DoglegState(const Values &_values, double _error, double _delta, unsigned int _iterations=0)
Definition: DoglegOptimizer.cpp:57
GaussianBayesNet.h
Chordal Bayes Net, the result of eliminating a factor graph.
gtsam::DoglegOptimizer::DoglegOptimizer
DoglegOptimizer(const NonlinearFactorGraph &graph, const Values &initialValues, const DoglegParams &params=DoglegParams())
Definition: DoglegOptimizer.cpp:65
vanilla::params
static const SmartProjectionParams params
Definition: smartFactorScenarios.h:69
result
Values result
Definition: OdometryOptimize.cpp:8
gtsam::NonlinearOptimizerParams::orderingType
Ordering::OrderingType orderingType
The method of ordering use during variable elimination (default COLAMD)
Definition: NonlinearOptimizerParams.h:47
gtsam::DoglegParams::verbosityDL
VerbosityDL verbosityDL
The verbosity level for Dogleg (default: SILENT), see also NonlinearOptimizerParams::verbosity.
Definition: DoglegOptimizer.h:41
gtsam::DoglegParams::VerbosityDL
VerbosityDL
Definition: DoglegOptimizer.h:35
gtsam::DoglegOptimizer::iterate
GaussianFactorGraph::shared_ptr iterate() override
Definition: DoglegOptimizer.cpp:84
gtsam::DoglegParams::verbosityDLTranslator
VerbosityDL verbosityDLTranslator(const std::string &verbosityDL) const
Definition: DoglegOptimizer.cpp:30
gtsam.examples.PlanarManipulatorExample.delta
def delta(g0, g1)
Definition: PlanarManipulatorExample.py:45
gtsam::VectorValues
Definition: VectorValues.h:74
gtsam::DoglegOptimizer::ensureHasOrdering
DoglegParams ensureHasOrdering(DoglegParams params, const NonlinearFactorGraph &graph) const
Definition: DoglegOptimizer.cpp:126
gtsam::NonlinearFactorGraph
Definition: NonlinearFactorGraph.h:55
gtsam::State
internal::DoglegState State
Definition: DoglegOptimizer.cpp:62
gtsam::NonlinearOptimizerParams::isIterative
bool isIterative() const
Definition: NonlinearOptimizerParams.h:133
gtsam::GaussianBayesNet::optimize
VectorValues optimize() const
Definition: GaussianBayesNet.cpp:44
VectorValues.h
Factor Graph Values.
transform
EIGEN_DONT_INLINE void transform(const Transformation &t, Data &data)
Definition: geometry.cpp:25
gtsam::GaussianBayesTree::optimize
VectorValues optimize() const
Definition: GaussianBayesTree.cpp:67
gtsam::NonlinearOptimizer::graph_
NonlinearFactorGraph graph_
The graph with nonlinear factors.
Definition: NonlinearOptimizer.h:78
ordering
static enum @1096 ordering
gtsam::internal::NonlinearOptimizerState
Definition: NonlinearOptimizerState.h:34
gtsam::DoglegParams
Definition: DoglegOptimizer.h:32
gtsam::DoglegOptimizer::params_
DoglegParams params_
Definition: DoglegOptimizer.h:71
gtsam
traits
Definition: SFMdata.h:40
gtsam::GaussianBayesTree
Definition: GaussianBayesTree.h:49
gtsam::NonlinearOptimizer
Definition: NonlinearOptimizer.h:75
error
static double error
Definition: testRot3.cpp:37
gtsam::Values
Definition: Values.h:65
gtsam::NonlinearOptimizerParams::isMultifrontal
bool isMultifrontal() const
Definition: NonlinearOptimizerParams.h:119
std
Definition: BFloat16.h:88
gtsam::DoglegOptimizerImpl::IterationResult
Definition: DoglegOptimizerImpl.h:34
GaussianBayesTree.h
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
gtsam::internal::DoglegState::delta
const double delta
Definition: DoglegOptimizer.cpp:55
gtsam::DoglegParams::VERBOSE
@ VERBOSE
Definition: DoglegOptimizer.h:37
DoglegOptimizerImpl.h
Nonlinear factor graph optimizer using Powell's Dogleg algorithm (detail implementation)
internal
Definition: BandTriangularSolver.h:13
DoglegOptimizer.h
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
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2
gtsam::NonlinearOptimizer::state_
std::unique_ptr< internal::NonlinearOptimizerState > state_
PIMPL'd state.
Definition: NonlinearOptimizer.h:80
gtsam::NonlinearOptimizerParams::getEliminationFunction
GaussianFactorGraph::Eliminate getEliminationFunction() const
Definition: NonlinearOptimizerParams.h:137
gtsam::Ordering
Definition: inference/Ordering.h:33
gtsam::DoglegOptimizer::getDelta
double getDelta() const
Definition: DoglegOptimizer.cpp:79
gtsam::GaussianBayesNet
Definition: GaussianBayesNet.h:35
gtsam::DoglegOptimizer::params
const DoglegParams & params() const
Definition: DoglegOptimizer.h:115


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:26