gtsam
Loading...
Searching...
No Matches
ISAM2Clique.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
17
18// \callgraph
19
20#pragma once
21
23#include <gtsam/inference/Key.h>
27#include <string>
28
29namespace gtsam {
30
36class GTSAM_EXPORT ISAM2Clique
37 : public BayesTreeCliqueBase<ISAM2Clique, GaussianFactorGraph> {
38 public:
39 typedef ISAM2Clique This;
41 typedef std::shared_ptr<This> shared_ptr;
42 typedef std::weak_ptr<This> weak_ptr;
43 typedef GaussianConditional ConditionalType;
44 typedef ConditionalType::shared_ptr sharedConditional;
45
46 Base::FactorType::shared_ptr cachedFactor_;
47 Vector gradientContribution_;
48#ifdef USE_BROKEN_FAST_BACKSUBSTITUTE
49 mutable FastMap<Key, VectorValues::iterator> solnPointers_;
50#endif
51
53 ISAM2Clique() : Base() {}
54
58 : Base(other),
59 cachedFactor_(other.cachedFactor_),
60 gradientContribution_(other.gradientContribution_) {}
61
65 Base::operator=(other);
66 cachedFactor_ = other.cachedFactor_;
67 gradientContribution_ = other.gradientContribution_;
68 return *this;
69 }
70
72 void setEliminationResult(
73 const FactorGraphType::EliminationResult& eliminationResult);
74
76 Base::FactorType::shared_ptr& cachedFactor() { return cachedFactor_; }
77
79 const Vector& gradientContribution() const { return gradientContribution_; }
80
82 void addGradientAtZero(VectorValues* g) const;
83
84 bool equals(const This& other, double tol = 1e-9) const;
85
87 void print(const std::string& s = "",
88 const KeyFormatter& formatter = DefaultKeyFormatter) const override;
89
90 void optimizeWildfire(const KeySet& replaced, double threshold,
91 KeySet* changed, VectorValues* delta,
92 size_t* count) const;
93
94 bool optimizeWildfireNode(const KeySet& replaced, double threshold,
95 KeySet* changed, VectorValues* delta,
96 size_t* count) const;
97
102 void nnz_internal(size_t* result) const;
103 size_t calculate_nnz() const;
104
120 void findAll(const KeySet& markedMask, KeySet* keys) const;
121
122 private:
123 friend class ISAM2;
124
126 void addGradientAtZero(VectorValues* g,
127 bool* hasConstrainedConditional) const;
128
133 bool isDirty(const KeySet& replaced, const KeySet& changed) const;
134
139 void fastBackSubstitute(VectorValues* delta) const;
140
141 /*
142 * Check whether the values changed above a threshold, or always true if the
143 * clique was replaced.
144 */
145 bool valuesChanged(const KeySet& replaced, const Vector& originalValues,
146 const VectorValues& delta, double threshold) const;
147
149 void markFrontalsAsChanged(KeySet* changed) const;
150
152 void restoreFromOriginals(const Vector& originalValues,
153 VectorValues* delta) const;
154
155#if GTSAM_ENABLE_BOOST_SERIALIZATION
157 friend class boost::serialization::access;
158 template <class ARCHIVE>
159 void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
160 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
161 ar& BOOST_SERIALIZATION_NVP(cachedFactor_);
162 ar& BOOST_SERIALIZATION_NVP(gradientContribution_);
163 }
164#endif
165}; // \struct ISAM2Clique
166
178size_t optimizeWildfire(const ISAM2Clique::shared_ptr& root, double threshold,
179 const KeySet& replaced, VectorValues* delta);
180
181size_t optimizeWildfireNonRecursive(const ISAM2Clique::shared_ptr& root,
182 double threshold, const KeySet& replaced,
183 VectorValues* delta);
184
185} // namespace gtsam
Base class for cliques of a BayesTree.
Conditional Gaussian Base class.
Chordal Bayes Net, the result of eliminating a factor graph.
Linear Factor Graph where all factors are Gaussians.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
size_t optimizeWildfire(const ISAM2Clique::shared_ptr &root, double threshold, const KeySet &keys, VectorValues *delta)
Optimize the BayesTree, starting from the root.
Definition ISAM2Clique.cpp:227
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition Key.h:35
FastMap is a thin wrapper around std::map that uses the boost fast_pool_allocator instead of the defa...
Definition FastMap.h:40
Template to create a binary predicate.
Definition Testable.h:112
BayesTreeCliqueBase & operator=(const BayesTreeCliqueBase &c)
Definition BayesTreeCliqueBase.h:89
BayesTreeCliqueBase()
Definition BayesTreeCliqueBase.h:73
A GaussianConditional functions as the node in a Bayes network.
Definition GaussianConditional.h:43
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition GaussianConditional.h:46
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:73
Implementation of the full ISAM2 algorithm for incremental nonlinear optimization.
Definition ISAM2.h:45
const Vector & gradientContribution() const
Access the gradient contribution.
Definition ISAM2Clique.h:79
ISAM2Clique(const ISAM2Clique &other)
Copy constructor, does not copy solution pointers as these are invalid in different trees.
Definition ISAM2Clique.h:57
ISAM2Clique & operator=(const ISAM2Clique &other)
Assignment operator, does not copy solution pointers as these are invalid in different trees.
Definition ISAM2Clique.h:64
Base::FactorType::shared_ptr & cachedFactor()
Access the cached factor.
Definition ISAM2Clique.h:76
ISAM2Clique()
Default constructor.
Definition ISAM2Clique.h:53