gtsam
Loading...
Searching...
No Matches
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
18
19// \callgraph
20
21#pragma once
22
29
30#include <vector>
31
32namespace gtsam {
33
45class 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
98
101
102 public:
103 using This = ISAM2;
108
110 explicit ISAM2(const ISAM2Params& params);
111
114 ISAM2();
115
117 virtual ~ISAM2() {}
118
120 virtual bool equals(const ISAM2& other, double tol = 1e-9) const;
121
154 virtual ISAM2Result update(
155 const NonlinearFactorGraph& newFactors = NonlinearFactorGraph(),
156 const Values& newTheta = Values(),
157 const FactorIndices& removeFactorIndices = FactorIndices(),
158 const std::optional<FastMap<Key, int> >& constrainedKeys = {},
159 const std::optional<FastList<Key> >& noRelinKeys = {},
160 const std::optional<FastList<Key> >& extraReelimKeys = {},
161 bool force_relinearize = false);
162
181 virtual ISAM2Result update(const NonlinearFactorGraph& newFactors,
182 const Values& newTheta,
183 const ISAM2UpdateParams& updateParams);
184
202 void marginalizeLeaves(
203 const FastList<Key>& leafKeys,
204 FactorIndices* marginalFactorsIndices = nullptr,
205 FactorIndices* deletedFactorsIndices = nullptr);
206
211 template <class... OptArgs>
212 void marginalizeLeaves(const FastList<Key>& leafKeys,
213 OptArgs&&... optArgs) {
214 // dereference the optional arguments and pass
215 // it to the pointer version
216 marginalizeLeaves(leafKeys, (&optArgs)...);
217 }
218
223 std::pair<FactorIndices, FactorIndices> marginalizeLeavesWithIndices(const FastList<Key>& leafKeys);
224
226 const Values& getLinearizationPoint() const { return theta_; }
227
229 bool valueExists(Key key) const { return theta_.exists(key); }
230
236 Values calculateEstimate() const;
237
244 template <class VALUE>
245 VALUE calculateEstimate(Key key) const {
246 const Vector& delta = getDelta()[key];
247 return traits<VALUE>::Retract(theta_.at<VALUE>(key), delta);
248 }
249
250#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
265 const Value& calculateEstimate(Key key) const;
266#endif
267
275 Values calculateEstimate(const KeyVector& keys) const;
276
278 Matrix marginalInformation(Key key) const;
279
281 Matrix marginalCovariance(Key key) const;
282
284 JointMarginal jointMarginalCovariance(const KeyVector& queryKeys) const;
285
287 JointMarginal jointMarginalInformation(const KeyVector& queryKeys) const;
288
291
295 Values calculateBestEstimate() const;
296
298 const VectorValues& getDelta() const;
299
301 double error(const VectorValues& x) const;
302
305 return nonlinearFactors_;
306 }
307
310
312 const KeySet& getFixedVariables() const { return fixedVariables_; }
313
314 const ISAM2Params& params() const { return params_; }
315
319 size_t treeNnz() const;
320
322 void printStats() const { getCliqueData().getStats().print(); }
323
334 VectorValues gradientAtZero() const;
335
345 std::pair<KeySet, bool> predictUpdateInfo(
346 const NonlinearFactorGraph& newFactors, const Values& newTheta,
347 const ISAM2UpdateParams& updateParams) const;
348
350
351 protected:
353 void recalculate(const ISAM2UpdateParams& updateParams,
354 const KeySet& relinKeys, ISAM2Result* result);
355
356 // Do a batch step - reorder and relinearize all variables
357 void recalculateBatch(const ISAM2UpdateParams& updateParams,
358 KeySet* affectedKeysSet, ISAM2Result* result);
359
360 // retrieve all factors that ONLY contain the affected variables
361 // (note that the remaining stuff is summarized in the cached factors)
362 GaussianFactorGraph relinearizeAffectedFactors(
363 const ISAM2UpdateParams& updateParams, const FastList<Key>& affectedKeys,
364 const KeySet& relinKeys);
365
377 void recalculateIncremental(const ISAM2UpdateParams& updateParams,
378 const KeySet& relinKeys,
379 const FastList<Key>& affectedKeys,
380 KeySet* affectedKeysSet, Cliques* orphans,
381 ISAM2Result* result);
382
388 void addVariables(const Values& newTheta,
389 ISAM2Result::DetailedResults* detail = 0);
390
394 void removeVariables(const KeySet& unusedKeys);
395
396 friend class IncrementalFixedLagSmoother;
397
398 void updateDelta(bool forceFullSolve = false) const;
399
400 private:
401#if GTSAM_ENABLE_BOOST_SERIALIZATION
403 friend class boost::serialization::access;
404 template<class ARCHIVE>
405 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
406 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
407 ar & BOOST_SERIALIZATION_NVP(theta_);
408 ar & BOOST_SERIALIZATION_NVP(variableIndex_);
409 ar & BOOST_SERIALIZATION_NVP(delta_);
410 ar & BOOST_SERIALIZATION_NVP(deltaNewton_);
411 ar & BOOST_SERIALIZATION_NVP(RgProd_);
412 ar & BOOST_SERIALIZATION_NVP(deltaReplacedMask_);
413 ar & BOOST_SERIALIZATION_NVP(nonlinearFactors_);
414 ar & BOOST_SERIALIZATION_NVP(linearFactors_);
415 ar & BOOST_SERIALIZATION_NVP(doglegDelta_);
416 ar & BOOST_SERIALIZATION_NVP(fixedVariables_);
417 ar & BOOST_SERIALIZATION_NVP(update_count_);
418 }
419#endif
420
421}; // ISAM2
422
424template <>
425struct traits<ISAM2> : public Testable<ISAM2> {};
426
427} // namespace gtsam
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
Specialized iSAM2 Clique.
Parameters for iSAM 2.
Factor Graph consisting of non-linear factors.
Class that stores detailed iSAM2 result.
Class that stores extra params for ISAM2::update().
Global functions in a separate testing namespace.
Definition chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition Factor.h:37
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
FastList is a thin wrapper around std::list that uses the boost fast_pool_allocator instead of the de...
Definition FastList.h:43
FastMap is a thin wrapper around std::map that uses the boost fast_pool_allocator instead of the defa...
Definition FastMap.h:40
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
Template to create a binary predicate.
Definition Testable.h:112
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
This is the base class for any type to be stored in Values.
Definition Value.h:39
std::shared_ptr< Clique > sharedClique
Definition BayesTree.h:84
BayesTree()
Definition BayesTree.h:119
FastList< sharedClique > Cliques
Definition BayesTree.h:99
ISAM2Clique Clique
Definition BayesTree.h:83
BayesTreeCliqueData getCliqueData() const
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition VariableIndex.h:41
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition GaussianFactorGraph.h:77
A class to store and access a joint marginal, returned from Gaussian and nonlinear covariance query A...
Definition JointMarginal.h:34
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:73
This is a base class for the various HMF2 implementations.
Definition IncrementalFixedLagSmoother.h:36
Implementation of the full ISAM2 algorithm for incremental nonlinear optimization.
Definition ISAM2.h:45
KeySet fixedVariables_
Set of variables that are involved with linear factors from marginalized variables and thus cannot ha...
Definition ISAM2.h:94
KeySet deltaReplacedMask_
A cumulative mask for the variables that were replaced and have not yet been updated in the linear so...
Definition ISAM2.h:76
void marginalizeLeaves(const FastList< Key > &leafKeys, FactorIndices *marginalFactorsIndices=nullptr, FactorIndices *deletedFactorsIndices=nullptr)
Marginalize out variables listed in leafKeys.
Definition ISAM2.cpp:556
int update_count_
Counter incremented every update(), used to determine periodic relinearization.
Definition ISAM2.h:96
BayesTree< ISAM2Clique > Base
The BayesTree base class.
Definition ISAM2.h:104
VALUE calculateEstimate(Key key) const
Compute an estimate for a single variable using its incomplete linear delta computed during the last ...
Definition ISAM2.h:245
virtual ~ISAM2()
default virtual destructor
Definition ISAM2.h:117
const KeySet & getFixedVariables() const
Access the nonlinear variable index.
Definition ISAM2.h:312
const VectorValues & getDelta() const
Access the current delta, computed during the last call to update.
Definition ISAM2.cpp:959
Base::Cliques Cliques
List of Cliques.
Definition ISAM2.h:107
Base::Clique Clique
A clique.
Definition ISAM2.h:105
void printStats() const
prints out clique statistics
Definition ISAM2.h:322
NonlinearFactorGraph nonlinearFactors_
All original nonlinear factors are stored here to use during relinearization.
Definition ISAM2.h:81
void marginalizeLeaves(const FastList< Key > &leafKeys, OptArgs &&... optArgs)
An overload of marginalizeLeaves that takes references to vectors instead of pointers to vectors and ...
Definition ISAM2.h:212
const VariableIndex & getVariableIndex() const
Access the nonlinear variable index.
Definition ISAM2.h:309
Base::sharedClique sharedClique
Shared pointer to a clique.
Definition ISAM2.h:106
VectorValues delta_
The linear delta from the last linear solution, an update to the estimate in theta.
Definition ISAM2.h:61
ISAM2(const ISAM2Params &params)
Create an empty ISAM2 instance.
Definition ISAM2.cpp:45
VariableIndex variableIndex_
VariableIndex lets us look up factors by involved variable and keeps track of dimensions.
Definition ISAM2.h:52
const Values & getLinearizationPoint() const
Access the current linearization point.
Definition ISAM2.h:226
Values theta_
The current linearization point.
Definition ISAM2.h:48
ISAM2Params params_
The current parameters.
Definition ISAM2.h:87
size_t nnzAfterLastReorder_
Bayes tree nnz recorded after the most recent full batch reorder.
Definition ISAM2.h:99
GaussianFactorGraph linearFactors_
The current linear factors, which are only updated as needed.
Definition ISAM2.h:84
const NonlinearFactorGraph & getFactorsUnsafe() const
Access the set of nonlinear factors.
Definition ISAM2.h:304
ISAM2 This
This class.
Definition ISAM2.h:103
std::optional< double > doglegDelta_
The current Dogleg Delta (trust region radius).
Definition ISAM2.h:90
bool valueExists(Key key) const
Check whether variable with given key exists in linearization point.
Definition ISAM2.h:229
Definition ISAM2Params.h:199
This struct is returned from ISAM2::update() and contains information about the update that is useful...
Definition ISAM2Result.h:39
A struct holding detailed results, which must be enabled with ISAM2Params::enableDetailedResults.
Definition ISAM2Result.h:126
This struct is used by ISAM2::update() to pass additional parameters to give the user a fine-grained ...
Definition ISAM2UpdateParams.h:32
Definition NonlinearFactorGraph.h:57
A non-templated config holding any types of Manifold-group elements.
Definition Values.h:65