gtsam  4.0.0
gtsam
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 
28 
29 #include <vector>
30 
31 namespace gtsam {
32 
44 class GTSAM_EXPORT ISAM2 : public BayesTree<ISAM2Clique> {
45  protected:
48 
52 
61 
62  mutable VectorValues deltaNewton_; // Only used when using Dogleg - stores
63  // the Gauss-Newton update
64  mutable VectorValues RgProd_; // Only used when using Dogleg - stores R*g and
65  // is updated incrementally
66 
75  mutable KeySet
76  deltaReplacedMask_; // TODO(dellaert): Make sure accessed in the right way
77 
81 
84 
87 
89  mutable boost::optional<double> doglegDelta_;
90 
94 
96 
98  public:
99  typedef ISAM2 This;
103  typedef Base::Cliques Cliques;
104 
106  explicit ISAM2(const ISAM2Params& params);
107 
110  ISAM2();
111 
113  virtual ~ISAM2() {}
114 
116  virtual bool equals(const ISAM2& other, double tol = 1e-9) const;
117 
150  virtual ISAM2Result update(
151  const NonlinearFactorGraph& newFactors = NonlinearFactorGraph(),
152  const Values& newTheta = Values(),
153  const FactorIndices& removeFactorIndices = FactorIndices(),
154  const boost::optional<FastMap<Key, int> >& constrainedKeys = boost::none,
155  const boost::optional<FastList<Key> >& noRelinKeys = boost::none,
156  const boost::optional<FastList<Key> >& extraReelimKeys = boost::none,
157  bool force_relinearize = false);
158 
176  void marginalizeLeaves(
177  const FastList<Key>& leafKeys,
178  boost::optional<FactorIndices&> marginalFactorsIndices = boost::none,
179  boost::optional<FactorIndices&> deletedFactorsIndices = boost::none);
180 
182  const Values& getLinearizationPoint() const { return theta_; }
183 
185  bool valueExists(Key key) const { return theta_.exists(key); }
186 
192  Values calculateEstimate() const;
193 
200  template <class VALUE>
201  VALUE calculateEstimate(Key key) const {
202  const Vector& delta = getDelta()[key];
203  return traits<VALUE>::Retract(theta_.at<VALUE>(key), delta);
204  }
205 
206 
215  const Value& calculateEstimate(Key key) const;
216 
218  Matrix marginalCovariance(Key key) const;
219 
222 
224  struct Impl;
225 
229  Values calculateBestEstimate() const;
230 
232  const VectorValues& getDelta() const;
233 
235  double error(const VectorValues& x) const;
236 
239  return nonlinearFactors_;
240  }
241 
243  const VariableIndex& getVariableIndex() const { return variableIndex_; }
244 
246  const KeySet& getFixedVariables() const { return fixedVariables_; }
247 
248  size_t lastAffectedVariableCount;
249  size_t lastAffectedFactorCount;
250  size_t lastAffectedCliqueCount;
251  size_t lastAffectedMarkedCount;
252  mutable size_t lastBacksubVariableCount;
253  size_t lastNnzTop;
254 
255  const ISAM2Params& params() const { return params_; }
256 
258  void printStats() const { getCliqueData().getStats().print(); }
259 
267  VectorValues gradientAtZero() const;
268 
270 
271  protected:
281  void addVariables(const Values& newTheta);
282 
286  void removeVariables(const KeySet& unusedKeys);
287 
293  void expmapMasked(const KeySet& mask);
294 
295  FactorIndexSet getAffectedFactors(const FastList<Key>& keys) const;
296  GaussianFactorGraph::shared_ptr relinearizeAffectedFactors(
297  const FastList<Key>& affectedKeys, const KeySet& relinKeys) const;
298  GaussianFactorGraph getCachedBoundaryFactors(const Cliques& orphans);
299 
300  virtual boost::shared_ptr<KeySet> recalculate(
301  const KeySet& markedKeys, const KeySet& relinKeys,
302  const KeyVector& observedKeys, const KeySet& unusedIndices,
303  const boost::optional<FastMap<Key, int> >& constrainKeys,
304  ISAM2Result* result);
305 
306  void updateDelta(bool forceFullSolve = false) const;
307 }; // ISAM2
308 
310 template <>
311 struct traits<ISAM2> : public Testable<ISAM2> {};
312 
313 } // namespace gtsam
314 
boost::optional< double > doglegDelta_
The current Dogleg Delta (trust region radius)
Definition: ISAM2.h:89
Values theta_
The current linearization point.
Definition: ISAM2.h:47
int update_count_
Counter incremented every update(), used to determine periodic relinearization.
Definition: ISAM2.h:95
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
Class that stores detailed iSAM2 result.
ValueType at(Key j) const
Retrieve a variable by key j.
Definition: Values-inl.h:342
This is the base class for any type to be stored in Values.
Definition: Value.h:36
Specialized iSAM2 Clique.
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactorGraph.h:74
const VariableIndex & getVariableIndex() const
Access the nonlinear variable index.
Definition: ISAM2.h:243
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
boost::shared_ptr< Clique > sharedClique
Shared pointer to a clique.
Definition: BayesTree.h:72
Definition: FastMap.h:37
Template to create a binary predicate.
Definition: Testable.h:110
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition: VariableIndex.h:43
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition: GaussianFactorGraph.h:65
Incremental update functionality (ISAM2) for BayesTree, with fluid relinearization.
Base::sharedClique sharedClique
Shared pointer to a clique.
Definition: ISAM2.h:102
VariableIndex variableIndex_
VariableIndex lets us look up factors by involved variable and keeps track of dimensions.
Definition: ISAM2.h:51
Definition: ISAM2Params.h:135
VALUE calculateEstimate(Key key) const
Compute an estimate for a single variable using its incomplete linear delta computed during the last ...
Definition: ISAM2.h:201
bool exists(Key j) const
Check if a value exists with key j.
Definition: Values.cpp:97
Specialized Clique structure for ISAM2, incorporating caching and gradient contribution TODO: more do...
Definition: ISAM2Clique.h:36
Definition: FastList.h:38
GaussianFactorGraph linearFactors_
The current linear factors, which are only updated as needed.
Definition: ISAM2.h:83
ISAM2Params params_
The current parameters.
Definition: ISAM2.h:86
Factor Graph Constsiting of non-linear factors.
virtual ~ISAM2()
default virtual destructor
Definition: ISAM2.h:113
Definition: ISAM2-impl.h:25
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:73
const Values & getLinearizationPoint() const
Access the current linearization point.
Definition: ISAM2.h:182
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
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:56
void printStats() const
prints out clique statistics
Definition: ISAM2.h:258
KeySet fixedVariables_
Set of variables that are involved with linear factors from marginalized variables and thus cannot ha...
Definition: ISAM2.h:93
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
NonlinearFactorGraph nonlinearFactors_
All original nonlinear factors are stored here to use during relinearization.
Definition: ISAM2.h:80
VectorValues delta_
The linear delta from the last linear solution, an update to the estimate in theta.
Definition: ISAM2.h:60
const KeySet & getFixedVariables() const
Access the nonlinear variable index.
Definition: ISAM2.h:246
A non-linear factor graph is a graph of non-Gaussian, i.e.
Definition: NonlinearFactorGraph.h:77
Definition: ISAM2Result.h:41
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition: Factor.h:32
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Base::Cliques Cliques
List of Clique typedef from base class.
Definition: ISAM2.h:103
ISAM2 This
This class.
Definition: ISAM2.h:99
bool valueExists(Key key) const
Check whether variable with given key exists in linearization point.
Definition: ISAM2.h:185
BayesTree< ISAM2Clique > Base
The BayesTree base class.
Definition: ISAM2.h:100
const NonlinearFactorGraph & getFactorsUnsafe() const
Access the set of nonlinear factors.
Definition: ISAM2.h:238
Base::Clique Clique
A clique.
Definition: ISAM2.h:101
Parameters for iSAM 2.