GTSAM  4.0.2
C++ library for smoothing and mapping (SAM)
HybridBayesTree.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 
20 #pragma once
21 
28 
29 #include <string>
30 
31 namespace gtsam {
32 
33 // Forward declarations
34 class HybridConditional;
35 class VectorValues;
36 
37 /* ************************************************************************* */
44 class GTSAM_EXPORT HybridBayesTreeClique
45  : public BayesTreeCliqueBase<HybridBayesTreeClique,
46  HybridGaussianFactorGraph> {
47  public:
50  Base;
51  typedef std::shared_ptr<This> shared_ptr;
52  typedef std::weak_ptr<This> weak_ptr;
54  HybridBayesTreeClique(const std::shared_ptr<HybridConditional>& conditional)
55  : Base(conditional) {}
57  HybridBayesTreeClique(const HybridBayesTreeClique& clique) : Base(clique) {}
58 };
59 
60 /* ************************************************************************* */
62 class GTSAM_EXPORT HybridBayesTree : public BayesTree<HybridBayesTreeClique> {
63  private:
65 
66  public:
67  typedef HybridBayesTree This;
68  typedef std::shared_ptr<This> shared_ptr;
69 
72 
73  HybridBayesTree() = default;
74 
76  bool equals(const This& other, double tol = 1e-9) const;
77 
85  GaussianBayesTree choose(const DiscreteValues& assignment) const;
86 
94  HybridValues optimize() const;
95 
103  VectorValues optimize(const DiscreteValues& assignment) const;
104 
110  void prune(const size_t maxNumberLeaves);
111 
113 
114  private:
115 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
116 
117  friend class boost::serialization::access;
118  template <class ARCHIVE>
119  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
120  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
121  }
122 #endif
123 };
124 
126 template <>
127 struct traits<HybridBayesTree> : public Testable<HybridBayesTree> {};
128 
139 template <>
141  public:
143  typedef HybridConditional Base;
144 
145  std::shared_ptr<CliqueType> clique;
146 
152  BayesTreeOrphanWrapper(const std::shared_ptr<CliqueType>& clique)
153  : clique(clique) {
154  // Store parent keys in our base type factor so that eliminating those
155  // parent keys will pull this subtree into the elimination.
156  this->keys_.assign(clique->conditional()->beginParents(),
157  clique->conditional()->endParents());
158  this->discreteKeys_.assign(clique->conditional()->discreteKeys().begin(),
159  clique->conditional()->discreteKeys().end());
160  }
161 
163  void print(
164  const std::string& s = "",
165  const KeyFormatter& formatter = DefaultKeyFormatter) const override {
166  clique->print(s + "stored clique", formatter);
167  }
168 };
169 
170 } // namespace gtsam
Definition: HybridValues.h:38
A clique in a HybridBayesTree which is a HybridConditional internally.
Definition: HybridBayesTree.h:44
Base class for conditional densities.
Definition: GaussianBayesTree.h:49
BayesTreeOrphanWrapper(const std::shared_ptr< CliqueType > &clique)
Construct a new Bayes Tree Orphan Wrapper object.
Definition: HybridBayesTree.h:152
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:113
Definition: Testable.h:152
Definition: Group.h:43
Definition: HybridBayesTree.h:62
HybridBayesTreeClique(const std::shared_ptr< HybridConditional > &conditional)
Copy constructor.
Definition: HybridBayesTree.h:54
Definition: VectorValues.h:74
Definition: BayesTree.h:281
Definition: BayesTreeCliqueBase.h:49
A Bayes net of Gaussian Conditionals indexed by discrete keys.
Definition: BayesTree.h:66
Definition: Testable.h:112
GTSAM_EXPORT Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
void print(const std::string &s="", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print utility
Definition: HybridBayesTree.h:163
Definition: DiscreteValues.h:34
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
Linearized Hybrid factor graph that uses type erasure.
Bayes Tree is a tree of cliques of a Bayes Chain.
Definition: chartTesting.h:28
Definition: HybridConditional.h:59
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
Base class for cliques of a BayesTree.