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 
18 // \callgraph
19 
20 #pragma once
21 
23 #include <gtsam/inference/Key.h>
27 #include <string>
28 
29 namespace gtsam {
30 
36 class GTSAM_EXPORT ISAM2Clique
37  : public BayesTreeCliqueBase<ISAM2Clique, GaussianFactorGraph> {
38  public:
39  typedef ISAM2Clique This;
41  typedef boost::shared_ptr<This> shared_ptr;
42  typedef boost::weak_ptr<This> weak_ptr;
45 
48 #ifdef USE_BROKEN_FAST_BACKSUBSTITUTE
49  mutable FastMap<Key, VectorValues::iterator> solnPointers_;
50 #endif
51 
53  ISAM2Clique() : Base() {}
54  virtual ~ISAM2Clique() = default;
55 
58  ISAM2Clique(const ISAM2Clique& other)
59  : Base(other),
60  cachedFactor_(other.cachedFactor_),
61  gradientContribution_(other.gradientContribution_) {}
62 
66  Base::operator=(other);
67  cachedFactor_ = other.cachedFactor_;
68  gradientContribution_ = other.gradientContribution_;
69  return *this;
70  }
71 
73  void setEliminationResult(
74  const FactorGraphType::EliminationResult& eliminationResult);
75 
77  Base::FactorType::shared_ptr& cachedFactor() { return cachedFactor_; }
78 
80  const Vector& gradientContribution() const { return gradientContribution_; }
81 
83  void addGradientAtZero(VectorValues* g) const;
84 
85  bool equals(const This& other, double tol = 1e-9) const;
86 
88  void print(const std::string& s = "",
89  const KeyFormatter& formatter = DefaultKeyFormatter) const override;
90 
91  void optimizeWildfire(const KeySet& replaced, double threshold,
92  KeySet* changed, VectorValues* delta,
93  size_t* count) const;
94 
95  bool optimizeWildfireNode(const KeySet& replaced, double threshold,
96  KeySet* changed, VectorValues* delta,
97  size_t* count) const;
98 
103  void nnz_internal(size_t* result) const;
104  size_t calculate_nnz() const;
105 
121  void findAll(const KeySet& markedMask, KeySet* keys) const;
122 
123  private:
128  bool isDirty(const KeySet& replaced, const KeySet& changed) const;
129 
134  void fastBackSubstitute(VectorValues* delta) const;
135 
136  /*
137  * Check whether the values changed above a threshold, or always true if the
138  * clique was replaced.
139  */
140  bool valuesChanged(const KeySet& replaced, const Vector& originalValues,
141  const VectorValues& delta, double threshold) const;
142 
144  void markFrontalsAsChanged(KeySet* changed) const;
145 
147  void restoreFromOriginals(const Vector& originalValues,
148  VectorValues* delta) const;
149 
151  friend class boost::serialization::access;
152  template <class ARCHIVE>
153  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
154  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
155  ar& BOOST_SERIALIZATION_NVP(cachedFactor_);
156  ar& BOOST_SERIALIZATION_NVP(gradientContribution_);
157  }
158 }; // \struct ISAM2Clique
159 
171 size_t optimizeWildfire(const ISAM2Clique::shared_ptr& root, double threshold,
172  const KeySet& replaced, VectorValues* delta);
173 
175  double threshold, const KeySet& replaced,
176  VectorValues* delta);
177 
178 } // namespace gtsam
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
boost::shared_ptr< This > shared_ptr
Definition: ISAM2Clique.h:41
void serialize(ARCHIVE &ar, const unsigned int)
Definition: ISAM2Clique.h:153
const mpreal root(const mpreal &x, unsigned long int k, mp_rnd_t r=mpreal::get_default_rnd())
Definition: mpreal.h:2194
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
void g(const string &key, int i)
Definition: testBTree.cpp:43
boost::shared_ptr< This > shared_ptr
const KeyFormatter & formatter
size_t optimizeWildfire(const ISAM2Clique::shared_ptr &root, double threshold, const KeySet &keys, VectorValues *delta)
Base::FactorType::shared_ptr cachedFactor_
Definition: ISAM2Clique.h:46
Eigen::VectorXd Vector
Definition: Vector.h:38
Values result
size_t optimizeWildfireNonRecursive(const ISAM2Clique::shared_ptr &root, double threshold, const KeySet &keys, VectorValues *delta)
GaussianConditional ConditionalType
Definition: ISAM2Clique.h:43
ISAM2Clique()
Default constructor.
Definition: ISAM2Clique.h:53
Vector gradientContribution_
Definition: ISAM2Clique.h:47
boost::weak_ptr< This > weak_ptr
Definition: ISAM2Clique.h:42
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
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
ISAM2Clique(const ISAM2Clique &other)
Definition: ISAM2Clique.h:58
Conditional Gaussian Base class.
Linear Factor Graph where all factors are Gaussians.
Base::FactorType::shared_ptr & cachedFactor()
Definition: ISAM2Clique.h:77
traits
Definition: chartTesting.h:28
const Vector & gradientContribution() const
Access the gradient contribution.
Definition: ISAM2Clique.h:80
BayesTreeCliqueBase< This, GaussianFactorGraph > Base
Definition: ISAM2Clique.h:40
Chordal Bayes Net, the result of eliminating a factor graph.
ISAM2Clique & operator=(const ISAM2Clique &other)
Definition: ISAM2Clique.h:65
const G double tol
Definition: Group.h:83
const KeyVector keys
ConditionalType::shared_ptr sharedConditional
Definition: ISAM2Clique.h:44
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
std::pair< boost::shared_ptr< ConditionalType >, boost::shared_ptr< _FactorType > > EliminationResult
Base class for cliques of a BayesTree.
ISAM2Clique This
Definition: ISAM2Clique.h:39


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:22