22#include <boost/shared_ptr.hpp>
26#include <gtsam/base/ConcurrentMap.h>
40 double avgConditionalSize;
41 std::size_t maxConditionalSize;
42 double avgSeparatorSize;
43 std::size_t maxSeparatorSize;
44 void print(
const std::string& s =
"")
const ;
65 template<
class CLIQUE>
70 typedef boost::shared_ptr<This> shared_ptr;
77 typedef typename CLIQUE::ConditionalType ConditionalType;
78 typedef boost::shared_ptr<ConditionalType> sharedConditional;
79 typedef typename CLIQUE::BayesNetType BayesNetType;
80 typedef boost::shared_ptr<BayesNetType> sharedBayesNet;
81 typedef typename CLIQUE::FactorType FactorType;
82 typedef boost::shared_ptr<FactorType> sharedFactor;
83 typedef typename CLIQUE::FactorGraphType FactorGraphType;
84 typedef boost::shared_ptr<FactorGraphType> sharedFactorGraph;
86 typedef typename CLIQUE::EliminationTraitsType EliminationTraitsType;
123 bool equals(
const This& other,
double tol = 1e-9)
const;
127 void print(
const std::string& s =
"",
128 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
153 typename Nodes::const_iterator c =
nodes_.find(j);
155 throw std::out_of_range(
"Requested the BayesTree clique for a key that is not in the BayesTree");
189 void dot(std::ostream& os,
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
193 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
197 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
207 template<
class CONTAINER>
247 int parentnum = 0)
const;
259 template<
class BAYESTREE,
class GRAPH>
friend class EliminatableClusterTree;
263 friend class boost::serialization::access;
264 template<
class ARCHIVE>
265 void serialize(ARCHIVE & ar,
const unsigned int ) {
266 ar & BOOST_SERIALIZATION_NVP(
nodes_);
267 ar & BOOST_SERIALIZATION_NVP(
roots_);
275 template <
class CLIQUE,
typename =
void>
278 typedef CLIQUE CliqueType;
279 typedef typename CLIQUE::ConditionalType Base;
281 boost::shared_ptr<CliqueType> clique;
295 this->keys_.assign(clique->conditional()->beginParents(),
296 clique->conditional()->endParents());
300 const std::string& s =
"",
301 const KeyFormatter& formatter = DefaultKeyFormatter)
const override {
302 clique->print(s +
"stored clique", formatter);
A thin wrapper around std::vector that uses a custom allocator.
A thin wrapper around std::list that uses boost's fast_pool_allocator.
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
FastVector is a type alias to a std::vector with a custom memory allocator.
Definition FastVector.h:33
Global functions in a separate testing namespace.
Definition chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:86
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
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
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
FastMap is a thin wrapper around std::map that uses the boost fast_pool_allocator instead of the defa...
Definition ConcurrentMap.h:68
FastList is a thin wrapper around std::list that uses the boost fast_pool_allocator instead of the de...
Definition FastList.h:40
static std::pair< boost::shared_ptr< ConditionalType >, boost::shared_ptr< FactorType > > DefaultEliminate(const FactorGraphType &factors, const Ordering &keys)
The default dense elimination function.
Definition DiscreteFactorGraph.h:82
A factor graph is a bipartite graph with factor nodes connected to variable nodes.
Definition FactorGraph.h:97
A cluster-tree that eliminates to a Bayes tree.
Definition ClusterTree.h:184
clique statistics
Definition BayesTree.h:39
store all the sizes
Definition BayesTree.h:48
Nodes nodes_
Definition BayesTree.h:100
void removeClique(sharedClique clique)
remove a clique: warning, can result in a forest
Definition BayesTree-inst.h:424
sharedFactorGraph joint(Key j1, Key j2, const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
return joint on two variables Limitation: can only calculate joint if cliques are disjoint or one of ...
Definition BayesTree-inst.h:293
void fillNodesIndex(const sharedClique &subtree)
Fill the nodes index for a subtree.
Definition BayesTree-inst.h:246
void dot(std::ostream &s, sharedClique clique, const KeyFormatter &keyFormatter, int parentnum=0) const
private helper method for saving the Tree to a text file in GraphViz format
Definition BayesTree-inst.h:94
void dot(std::ostream &os, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Output to graphviz format, stream version.
Definition BayesTree-inst.h:64
void addFactorsToGraph(FactorGraph< FactorType > *graph) const
Add all cliques in this BayesTree to the specified factor graph.
Definition BayesTree-inst.h:168
bool equals(const This &other, double tol=1e-9) const
check equality
Definition BayesTree-inst.h:230
sharedClique operator[](Key j) const
Access node by variable.
Definition BayesTree.h:146
This & operator=(const This &other)
Assignment operator.
Definition BayesTree-inst.h:199
boost::shared_ptr< Clique > sharedClique
Definition BayesTree.h:74
BayesTree()
Create an empty Bayes Tree.
Definition BayesTree.h:109
Clique Node
Definition BayesTree.h:75
void clear()
Remove all nodes.
Definition BayesTree-inst.h:408
Roots roots_
Definition BayesTree.h:103
void addClique(const sharedClique &clique, const sharedClique &parent_clique=sharedClique())
add a clique (top down)
Definition BayesTree-inst.h:142
sharedBayesNet jointBayesNet(Key j1, Key j2, const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
return joint on two variables as a BayesNet Limitation: can only calculate joint if cliques are disjo...
Definition BayesTree-inst.h:302
std::string dot(const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Output to graphviz format string.
Definition BayesTree-inst.h:77
sharedClique sharedNode
Definition BayesTree.h:76
Key findParentClique(const CONTAINER &parents) const
Find parent clique of a conditional.
Definition BayesTree-inst.h:238
size_t size() const
number of cliques
Definition BayesTree-inst.h:133
void getCliqueData(sharedClique clique, BayesTreeCliqueData *stats) const
Gather data on a single clique.
Definition BayesTree-inst.h:43
void deleteCachedShortcuts()
Clear all shortcut caches - use before timing on marginal calculation to avoid residual cache data.
Definition BayesTree-inst.h:416
BayesTree(const This &other)
Copy constructor.
Definition BayesTree-inst.h:178
void removePath(sharedClique clique, BayesNetType *bn, Cliques *orphans)
Remove path from clique to root and return that path as factors plus a list of orphaned subtree roots...
Definition BayesTree-inst.h:448
const Nodes & nodes() const
Return nodes.
Definition BayesTree.h:143
FastList< sharedClique > Cliques
Definition BayesTree.h:89
DiscreteBayesTreeClique Clique
Definition BayesTree.h:73
sharedConditional marginalFactor(Key j, const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
Return marginal on any variable.
Definition BayesTree-inst.h:270
const Roots & roots() const
return root cliques
Definition BayesTree.h:149
const sharedClique & clique(Key j) const
alternate syntax for matlab: find the clique that contains the variable with Key j
Definition BayesTree.h:152
ConcurrentMap< Key, sharedClique > Nodes
Definition BayesTree.h:92
size_t numCachedSeparatorMarginals() const
Collect number of cliques with cached separator marginals.
Definition BayesTree-inst.h:55
BayesTreeCliqueData getCliqueData() const
Gather data on all cliques.
Definition BayesTree-inst.h:35
Cliques removeSubtree(const sharedClique &subtree)
Remove the requested subtree.
Definition BayesTree-inst.h:496
bool empty() const
Check if there are any cliques in the tree.
Definition BayesTree.h:138
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print
Definition BayesTree-inst.h:212
void insertRoot(const sharedClique &subtree)
Insert a new subtree with known parent clique.
Definition BayesTree-inst.h:260
void saveGraph(const std::string &filename, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
output to file with graphviz format.
Definition BayesTree-inst.h:85
void removeTop(const KeyVector &keys, BayesNetType *bn, Cliques *orphans)
Given a list of indices, turn "contaminated" part of the tree back into a factor graph.
Definition BayesTree-inst.h:475
FastVector< sharedClique > Roots
Definition BayesTree.h:95
BayesTreeOrphanWrapper(const boost::shared_ptr< CliqueType > &clique)
Construct a new Bayes Tree Orphan Wrapper object.
Definition BayesTree.h:293
std::function< EliminationResult(const FactorGraphType &, const Ordering &)> Eliminate
Definition EliminateableFactorGraph.h:89