gtsam
Loading...
Searching...
No Matches
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
19
20#pragma once
21
28
29#include <string>
30
31namespace gtsam {
32
33// Forward declarations
35class VectorValues;
36
37/* ************************************************************************* */
44class GTSAM_EXPORT HybridBayesTreeClique
45 : public BayesTreeCliqueBase<HybridBayesTreeClique,
46 HybridGaussianFactorGraph> {
47 public:
48 typedef HybridBayesTreeClique This;
50 Base;
51 typedef std::shared_ptr<This> shared_ptr;
52 typedef std::weak_ptr<This> weak_ptr;
53 HybridBayesTreeClique() {}
54 HybridBayesTreeClique(const std::shared_ptr<HybridConditional>& conditional)
55 : Base(conditional) {}
57 HybridBayesTreeClique(const HybridBayesTreeClique& clique) : Base(clique) {}
58};
59
60/* ************************************************************************* */
62class 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
88 double error(const HybridValues& values) const;
89
97 HybridValues optimize() const;
98
106 VectorValues optimize(const DiscreteValues& assignment) const;
107
114 DiscreteValues mpe() const;
115
121 void prune(const size_t maxNumberLeaves);
122
124
125 private:
128 DiscreteValues discreteMaxProduct(const DiscreteFactorGraph& dfg) const;
129
130#if GTSAM_ENABLE_BOOST_SERIALIZATION
132 friend class boost::serialization::access;
133 template <class ARCHIVE>
134 void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
135 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
136 }
137#endif
138};
139
141template <>
142struct traits<HybridBayesTreeClique> : public Testable<HybridBayesTreeClique> {
143};
144
145template <>
146struct traits<HybridBayesTree> : public Testable<HybridBayesTree> {};
147
158template <>
160 public:
161 typedef HybridBayesTreeClique CliqueType;
162 typedef HybridConditional Base;
163
164 std::shared_ptr<CliqueType> clique;
165
171 BayesTreeOrphanWrapper(const std::shared_ptr<CliqueType>& clique)
172 : clique(clique) {
173 // Store parent keys in our base type factor so that eliminating those
174 // parent keys will pull this subtree into the elimination.
175 this->keys_.assign(clique->conditional()->beginParents(),
176 clique->conditional()->endParents());
177 this->discreteKeys_.assign(clique->conditional()->discreteKeys().begin(),
178 clique->conditional()->discreteKeys().end());
179 }
180
182 void print(
183 const std::string& s = "",
184 const KeyFormatter& formatter = DefaultKeyFormatter) const override {
185 clique->print(s + " stored clique ", formatter);
186 }
187};
188
189} // namespace gtsam
Linearized Hybrid factor graph that uses type erasure.
A Bayes net of Gaussian Conditionals indexed by discrete keys.
Base class for cliques of a BayesTree.
Bayes Tree is a tree of cliques of a Bayes Chain.
Base class for conditional densities.
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
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
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
A Discrete Factor Graph is a factor graph where all factors are Discrete, i.e.
Definition DiscreteFactorGraph.h:100
A map from keys to values.
Definition DiscreteValues.h:34
A clique in a HybridBayesTree which is a HybridConditional internally.
Definition HybridBayesTree.h:46
HybridBayesTreeClique(const std::shared_ptr< HybridConditional > &conditional)
Copy constructor.
Definition HybridBayesTree.h:54
A Bayes tree representing a Hybrid density.
Definition HybridBayesTree.h:62
double error(const HybridValues &values) const
Error for all conditionals.
Definition HybridBayesTree.cpp:180
DiscreteValues mpe() const
Compute the Most Probable Explanation (MPE) of the discrete variables.
Definition HybridBayesTree.cpp:56
void prune(const size_t maxNumberLeaves)
Prune the underlying Bayes tree.
Definition HybridBayesTree.cpp:198
HybridValues optimize() const
Optimize the hybrid Bayes tree by computing the MPE for the current set of discrete variables and usi...
Definition HybridBayesTree.cpp:77
GaussianBayesTree choose(const DiscreteValues &assignment) const
Get the Gaussian Bayes Tree which corresponds to a specific discrete value assignment.
Definition HybridBayesTree.cpp:160
HybridBayesTree()=default
Default constructor, creates an empty Bayes tree.
bool equals(const This &other, double tol=1e-9) const
Check equality.
Definition HybridBayesTree.cpp:41
BayesTreeOrphanWrapper(const std::shared_ptr< CliqueType > &clique)
Construct a new Bayes Tree Orphan Wrapper object.
Definition HybridBayesTree.h:171
void print(const std::string &s="", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print utility
Definition HybridBayesTree.h:182
Hybrid Conditional Density.
Definition HybridConditional.h:62
HybridConditional()=default
Default constructor needed for serialization.
HybridValues represents a collection of DiscreteValues and VectorValues.
Definition HybridValues.h:37
BayesTree()
Definition BayesTree.h:119
const sharedConditional & conditional() const
Definition BayesTreeCliqueBase.h:140
KeyVector keys_
The keys involved in this factor.
Definition Factor.h:88
A Bayes tree representing a Gaussian density.
Definition GaussianBayesTree.h:53
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:73