NonlinearConjugateGradientOptimizer.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 
22 #include <gtsam/nonlinear/Values.h>
24 
25 #include <cmath>
26 
27 namespace gtsam {
28 
29 typedef internal::NonlinearOptimizerState State;
30 
38  const Values& values) {
39  // Linearize graph
41  return linear->gradientAtZero();
42 }
43 
45  const NonlinearFactorGraph& graph, const Values& initialValues,
46  const Parameters& params, const DirectionMethod& directionMethod)
47  : Base(graph, std::unique_ptr<State>(
48  new State(initialValues, graph.error(initialValues)))),
49  params_(params) {}
50 
52  const State& state) const {
53  return graph_.error(state);
54 }
55 
58  const State& state) const {
59  return gradientInPlace(graph_, state);
60 }
61 
64  const double alpha,
65  const Gradient& g) const {
66  Gradient step = g;
67  step *= alpha;
68  return current.retract(step);
69 }
70 
72  const auto [newValues, dummy] = nonlinearConjugateGradient<System, Values>(
73  System(graph_), state_->values, params_, true /* single iteration */,
75  state_.reset(
76  new State(newValues, graph_.error(newValues), state_->iterations + 1));
77 
78  // NOTE(frank): We don't linearize this system, so we must return null here.
79  return nullptr;
80 }
81 
83  // Optimize until convergence
84  System system(graph_);
85  const auto [newValues, iterations] = nonlinearConjugateGradient(
86  system, state_->values, params_, false, directionMethod_);
87  state_.reset(
88  new State(std::move(newValues), graph_.error(newValues), iterations));
89  return state_->values;
90 }
91 
92 } /* namespace gtsam */
NonlinearConjugateGradientOptimizer.h
Simple non-linear optimizer that solves using non-preconditioned CG.
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
alpha
RealScalar alpha
Definition: level1_cplx_impl.h:147
NonlinearOptimizerState.h
Private class for NonlinearOptimizer state.
gtsam::NonlinearConjugateGradientOptimizer::directionMethod_
DirectionMethod directionMethod_
Definition: NonlinearConjugateGradientOptimizer.h:107
gtsam::internal::DoglegState
Definition: DoglegOptimizer.cpp:54
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
gtsam::NonlinearFactorGraph::linearize
std::shared_ptr< GaussianFactorGraph > linearize(const Values &linearizationPoint) const
Linearize a nonlinear factor graph.
Definition: NonlinearFactorGraph.cpp:239
gtsam::NonlinearConjugateGradientOptimizer::NonlinearConjugateGradientOptimizer
NonlinearConjugateGradientOptimizer(const NonlinearFactorGraph &graph, const Values &initialValues, const Parameters &params=Parameters(), const DirectionMethod &directionMethod=DirectionMethod::PolakRibiere)
Constructor.
Definition: NonlinearConjugateGradientOptimizer.cpp:44
gtsam::DirectionMethod
DirectionMethod
Definition: NonlinearConjugateGradientOptimizer.h:72
vanilla::params
static const SmartProjectionParams params
Definition: smartFactorScenarios.h:69
pybind_wrapper_test_script.dummy
dummy
Definition: pybind_wrapper_test_script.py:42
gtsam::NonlinearConjugateGradientOptimizer::System
Definition: NonlinearConjugateGradientOptimizer.h:83
gtsam::NonlinearFactorGraph::error
double error(const Values &values) const
Definition: NonlinearFactorGraph.cpp:170
gtsam::Values::retract
Values retract(const VectorValues &delta) const
Definition: Values.cpp:98
gtsam::NonlinearOptimizerParams
Definition: NonlinearOptimizerParams.h:35
gtsam::VectorValues
Definition: VectorValues.h:74
gtsam::NonlinearConjugateGradientOptimizer::System::graph_
const NonlinearFactorGraph & graph_
Definition: NonlinearConjugateGradientOptimizer.h:90
gtsam::NonlinearFactorGraph
Definition: NonlinearFactorGraph.h:55
gtsam::State
internal::DoglegState State
Definition: DoglegOptimizer.cpp:62
gtsam::utils.visual_isam.step
def step(data, isam, result, truth, currPoseIndex, isamArgs=())
Definition: visual_isam.py:82
gtsam::NonlinearConjugateGradientOptimizer::System::error
double error(const State &state) const
Definition: NonlinearConjugateGradientOptimizer.cpp:51
VectorValues.h
Factor Graph Values.
gtsam::NonlinearOptimizer::graph_
NonlinearFactorGraph graph_
The graph with nonlinear factors.
Definition: NonlinearOptimizer.h:78
g
void g(const string &key, int i)
Definition: testBTree.cpp:41
gtsam::NonlinearOptimizer::iterations
size_t iterations() const
return number of iterations in current optimizer state
Definition: NonlinearOptimizer.cpp:53
gtsam::gradientInPlace
static VectorValues gradientInPlace(const NonlinearFactorGraph &nfg, const Values &values)
Return the gradient vector of a nonlinear factor graph.
Definition: NonlinearConjugateGradientOptimizer.cpp:37
gtsam::NonlinearConjugateGradientOptimizer::optimize
const Values & optimize() override
Definition: NonlinearConjugateGradientOptimizer.cpp:82
gtsam
traits
Definition: SFMdata.h:40
gtsam::NonlinearOptimizer
Definition: NonlinearOptimizer.h:75
error
static double error
Definition: testRot3.cpp:37
gtsam::NonlinearConjugateGradientOptimizer::System::advance
State advance(const State &current, const double alpha, const Gradient &g) const
Definition: NonlinearConjugateGradientOptimizer.cpp:63
gtsam::Values
Definition: Values.h:65
std
Definition: BFloat16.h:88
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2
gtsam::NonlinearConjugateGradientOptimizer::iterate
GaussianFactorGraph::shared_ptr iterate() override
Definition: NonlinearConjugateGradientOptimizer.cpp:71
gtsam::nonlinearConjugateGradient
std::tuple< V, int > nonlinearConjugateGradient(const S &system, const V &initial, const NonlinearOptimizerParams &params, const bool singleIteration, const DirectionMethod &directionMethod=DirectionMethod::PolakRibiere, const bool gradientDescent=false)
Definition: NonlinearConjugateGradientOptimizer.h:196
gtsam::NonlinearOptimizer::state_
std::unique_ptr< internal::NonlinearOptimizerState > state_
PIMPL'd state.
Definition: NonlinearOptimizer.h:80
gtsam::NonlinearConjugateGradientOptimizer::params_
Parameters params_
Definition: NonlinearConjugateGradientOptimizer.h:106
gtsam::NonlinearConjugateGradientOptimizer::System::gradient
Gradient gradient(const State &state) const
Definition: NonlinearConjugateGradientOptimizer.cpp:57
Values.h
A non-templated config holding any types of Manifold-group elements.
make_changelog.state
state
Definition: make_changelog.py:29


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:03:12