ISAM2.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 
19 // \callgraph
20 
21 #pragma once
22 
29 
30 #include <vector>
31 
32 namespace gtsam {
33 
45 class GTSAM_EXPORT ISAM2 : public BayesTree<ISAM2Clique> {
46  protected:
49 
53 
62 
63  mutable VectorValues deltaNewton_; // Only used when using Dogleg - stores
64  // the Gauss-Newton update
65  mutable VectorValues RgProd_; // Only used when using Dogleg - stores R*g and
66  // is updated incrementally
67 
76  mutable KeySet deltaReplacedMask_; // TODO(dellaert): Make sure accessed in
77  // the right way
78 
82 
85 
88 
90  mutable std::optional<double> doglegDelta_;
91 
95 
97 
99  public:
100  using This = ISAM2;
105 
107  explicit ISAM2(const ISAM2Params& params);
108 
111  ISAM2();
112 
114  virtual ~ISAM2() {}
115 
117  virtual bool equals(const ISAM2& other, double tol = 1e-9) const;
118 
151  virtual ISAM2Result update(
152  const NonlinearFactorGraph& newFactors = NonlinearFactorGraph(),
153  const Values& newTheta = Values(),
154  const FactorIndices& removeFactorIndices = FactorIndices(),
155  const std::optional<FastMap<Key, int> >& constrainedKeys = {},
156  const std::optional<FastList<Key> >& noRelinKeys = {},
157  const std::optional<FastList<Key> >& extraReelimKeys = {},
158  bool force_relinearize = false);
159 
178  virtual ISAM2Result update(const NonlinearFactorGraph& newFactors,
179  const Values& newTheta,
180  const ISAM2UpdateParams& updateParams);
181 
199  void marginalizeLeaves(
200  const FastList<Key>& leafKeys,
201  FactorIndices* marginalFactorsIndices = nullptr,
202  FactorIndices* deletedFactorsIndices = nullptr);
203 
208  template <class... OptArgs>
209  void marginalizeLeaves(const FastList<Key>& leafKeys,
210  OptArgs&&... optArgs) {
211  // dereference the optional arguments and pass
212  // it to the pointer version
213  marginalizeLeaves(leafKeys, (&optArgs)...);
214  }
215 
217  const Values& getLinearizationPoint() const { return theta_; }
218 
220  bool valueExists(Key key) const { return theta_.exists(key); }
221 
227  Values calculateEstimate() const;
228 
235  template <class VALUE>
237  const Vector& delta = getDelta()[key];
238  return traits<VALUE>::Retract(theta_.at<VALUE>(key), delta);
239  }
240 
249  const Value& calculateEstimate(Key key) const;
250 
252  Matrix marginalCovariance(Key key) const;
253 
256 
260  Values calculateBestEstimate() const;
261 
263  const VectorValues& getDelta() const;
264 
266  double error(const VectorValues& x) const;
267 
270  return nonlinearFactors_;
271  }
272 
274  const VariableIndex& getVariableIndex() const { return variableIndex_; }
275 
277  const KeySet& getFixedVariables() const { return fixedVariables_; }
278 
279  const ISAM2Params& params() const { return params_; }
280 
282  void printStats() const { getCliqueData().getStats().print(); }
283 
291  VectorValues gradientAtZero() const;
292 
294 
295  protected:
297  void recalculate(const ISAM2UpdateParams& updateParams,
298  const KeySet& relinKeys, ISAM2Result* result);
299 
300  // Do a batch step - reorder and relinearize all variables
301  void recalculateBatch(const ISAM2UpdateParams& updateParams,
302  KeySet* affectedKeysSet, ISAM2Result* result);
303 
304  // retrieve all factors that ONLY contain the affected variables
305  // (note that the remaining stuff is summarized in the cached factors)
306  GaussianFactorGraph relinearizeAffectedFactors(
307  const ISAM2UpdateParams& updateParams, const FastList<Key>& affectedKeys,
308  const KeySet& relinKeys);
309 
321  void recalculateIncremental(const ISAM2UpdateParams& updateParams,
322  const KeySet& relinKeys,
323  const FastList<Key>& affectedKeys,
324  KeySet* affectedKeysSet, Cliques* orphans,
326 
332  void addVariables(const Values& newTheta,
334 
338  void removeVariables(const KeySet& unusedKeys);
339 
340  void updateDelta(bool forceFullSolve = false) const;
341 
342  private:
343 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
344 
345  friend class boost::serialization::access;
346  template<class ARCHIVE>
347  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
348  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
349  ar & BOOST_SERIALIZATION_NVP(theta_);
350  ar & BOOST_SERIALIZATION_NVP(variableIndex_);
351  ar & BOOST_SERIALIZATION_NVP(delta_);
352  ar & BOOST_SERIALIZATION_NVP(deltaNewton_);
353  ar & BOOST_SERIALIZATION_NVP(RgProd_);
354  ar & BOOST_SERIALIZATION_NVP(deltaReplacedMask_);
355  ar & BOOST_SERIALIZATION_NVP(nonlinearFactors_);
356  ar & BOOST_SERIALIZATION_NVP(linearFactors_);
357  ar & BOOST_SERIALIZATION_NVP(doglegDelta_);
358  ar & BOOST_SERIALIZATION_NVP(fixedVariables_);
359  ar & BOOST_SERIALIZATION_NVP(update_count_);
360  }
361 #endif
362 
363 }; // ISAM2
364 
366 template <>
367 struct traits<ISAM2> : public Testable<ISAM2> {};
368 
369 } // namespace gtsam
ISAM2Clique.h
Specialized iSAM2 Clique.
gtsam::ISAM2::getVariableIndex
const VariableIndex & getVariableIndex() const
Definition: ISAM2.h:274
gtsam::ISAM2Params
Definition: ISAM2Params.h:136
relicense.update
def update(text)
Definition: relicense.py:46
gtsam::Values::exists
bool exists(Key j) const
Definition: Values.cpp:94
gtsam::ISAM2
Definition: ISAM2.h:45
gtsam::ISAM2::marginalizeLeaves
void marginalizeLeaves(const FastList< Key > &leafKeys, OptArgs &&... optArgs)
Definition: ISAM2.h:209
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
ISAM2Params.h
Parameters for iSAM 2.
gtsam::ISAM2::deltaNewton_
VectorValues deltaNewton_
Definition: ISAM2.h:63
gtsam::ISAM2::params_
ISAM2Params params_
Definition: ISAM2.h:87
gtsam::ISAM2::linearFactors_
GaussianFactorGraph linearFactors_
Definition: ISAM2.h:84
gtsam::ISAM2::getFactorsUnsafe
const NonlinearFactorGraph & getFactorsUnsafe() const
Definition: ISAM2.h:269
gtsam::ISAM2::update_count_
int update_count_
Definition: ISAM2.h:96
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
gtsam::ISAM2::theta_
Values theta_
Definition: ISAM2.h:48
Values
gtsam::FastMap
Definition: FastMap.h:39
gtsam::ISAM2::fixedVariables_
KeySet fixedVariables_
Definition: ISAM2.h:94
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
gtsam::ISAM2::delta_
VectorValues delta_
Definition: ISAM2.h:61
detail
Definition: testSerializationNonlinear.cpp:70
gtsam::FastSet< Key >
gtsam::ISAM2::sharedClique
Base::sharedClique sharedClique
Shared pointer to a clique.
Definition: ISAM2.h:103
vanilla::params
static const SmartProjectionParams params
Definition: smartFactorScenarios.h:69
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:39
result
Values result
Definition: OdometryOptimize.cpp:8
gtsam::ISAM2::printStats
void printStats() const
Definition: ISAM2.h:282
gtsam::ISAM2::getLinearizationPoint
const Values & getLinearizationPoint() const
Access the current linearization point.
Definition: ISAM2.h:217
Eigen::internal::VALUE
@ VALUE
Definition: SpecialFunctionsImpl.h:729
gtsam::GaussianFactorGraph
Definition: GaussianFactorGraph.h:73
gtsam::Values::at
const ValueType at(Key j) const
Definition: Values-inl.h:261
gtsam.examples.PlanarManipulatorExample.delta
def delta(g0, g1)
Definition: PlanarManipulatorExample.py:45
gtsam::VectorValues
Definition: VectorValues.h:74
ISAM2Result.h
Class that stores detailed iSAM2 result.
gtsam::ISAM2::nonlinearFactors_
NonlinearFactorGraph nonlinearFactors_
Definition: ISAM2.h:81
gtsam::NonlinearFactorGraph
Definition: NonlinearFactorGraph.h:55
gtsam::ISAM2Result::DetailedResults
Definition: ISAM2Result.h:115
gtsam::Value
Definition: Value.h:39
gtsam::ISAM2::deltaReplacedMask_
KeySet deltaReplacedMask_
Definition: ISAM2.h:76
gtsam::ISAM2::variableIndex_
VariableIndex variableIndex_
Definition: ISAM2.h:52
gtsam::ISAM2::~ISAM2
virtual ~ISAM2()
Definition: ISAM2.h:114
gtsam::FastList
Definition: FastList.h:43
gtsam::VariableIndex
Definition: VariableIndex.h:41
gtsam::equals
Definition: Testable.h:112
gtsam::ISAM2::valueExists
bool valueExists(Key key) const
Check whether variable with given key exists in linearization point.
Definition: ISAM2.h:220
key
const gtsam::Symbol key('X', 0)
gtsam::ISAM2::RgProd_
VectorValues RgProd_
Definition: ISAM2.h:65
Values
std::vector< float > Values
Definition: sparse_setter.cpp:45
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
gtsam::BayesTree
Definition: BayesTree.h:66
error
static double error
Definition: testRot3.cpp:37
gtsam::traits
Definition: Group.h:36
NonlinearFactorGraph.h
Factor Graph consisting of non-linear factors.
gtsam::ISAM2Clique
Definition: ISAM2Clique.h:36
gtsam::Values
Definition: Values.h:65
gtsam::BayesTree< ISAM2Clique >::sharedClique
std::shared_ptr< Clique > sharedClique
Shared pointer to a clique.
Definition: BayesTree.h:74
gtsam::ISAM2UpdateParams
Definition: ISAM2UpdateParams.h:32
GaussianBayesTree.h
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
ISAM2UpdateParams.h
Class that stores extra params for ISAM2::update()
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::ISAM2Result
Definition: ISAM2Result.h:39
gtsam::ISAM2::getFixedVariables
const KeySet & getFixedVariables() const
Definition: ISAM2.h:277
gtsam::ISAM2::doglegDelta_
std::optional< double > doglegDelta_
Definition: ISAM2.h:90
Base
Definition: test_virtual_functions.cpp:156
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::ISAM2::calculateEstimate
VALUE calculateEstimate(Key key) const
Definition: ISAM2.h:236
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
gtsam::FactorIndices
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition: Factor.h:37
gtsam::ISAM2::params
const ISAM2Params & params() const
Definition: ISAM2.h:279


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:46