26 #include <gtsam/base/ConcurrentMap.h>
38 double avgConditionalSize;
39 std::size_t maxConditionalSize;
40 double avgSeparatorSize;
41 std::size_t maxSeparatorSize;
42 void print(
const std::string& s =
"")
const ;
63 template<
class CLIQUE>
68 typedef boost::shared_ptr<This> shared_ptr;
76 typedef boost::shared_ptr<ConditionalType> sharedConditional;
78 typedef boost::shared_ptr<BayesNetType> sharedBayesNet;
79 typedef typename CLIQUE::FactorType
FactorType;
80 typedef boost::shared_ptr<FactorType> sharedFactor;
82 typedef boost::shared_ptr<FactorGraphType> sharedFactorGraph;
121 bool equals(
const This& other,
double tol = 1e-9)
const;
125 void print(
const std::string& s =
"",
126 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
151 typename Nodes::const_iterator c =
nodes_.find(j);
153 throw std::out_of_range(
"Requested the BayesTree clique for a key that is not in the BayesTree");
169 sharedConditional
marginalFactor(
Key j,
const Eliminate&
function = EliminationTraitsType::DefaultEliminate)
const;
175 sharedFactorGraph
joint(
Key j1,
Key j2,
const Eliminate&
function = EliminationTraitsType::DefaultEliminate)
const;
181 sharedBayesNet
jointBayesNet(
Key j1,
Key j2,
const Eliminate&
function = EliminationTraitsType::DefaultEliminate)
const;
198 template<
class CONTAINER>
238 int parentnum = 0)
const;
250 template<
class BAYESRTEE,
class GRAPH>
friend class ClusterTree;
254 friend class boost::serialization::access;
255 template<
class ARCHIVE>
256 void serialize(ARCHIVE & ar,
const unsigned int version) {
257 ar & BOOST_SERIALIZATION_NVP(
nodes_);
258 ar & BOOST_SERIALIZATION_NVP(
roots_);
266 template<
class CLIQUE>
270 typedef CLIQUE CliqueType;
271 typedef typename CLIQUE::ConditionalType Base;
273 boost::shared_ptr<CliqueType> clique;
280 this->keys_.assign(clique->conditional()->beginParents(), clique->conditional()->endParents());
283 void print(
const std::string& s=
"",
const KeyFormatter& formatter = DefaultKeyFormatter)
const {
284 clique->print(s +
"stored clique", formatter);
Nodes nodes_
Map from indices to Clique.
Definition: BayesTree.h:95
boost::shared_ptr< Clique > sharedClique
Shared pointer to a clique.
Definition: BayesTree.h:72
Definition: BayesTree.h:64
const sharedClique & clique(Key j) const
alternate syntax for matlab: find the clique that contains the variable with Key j ...
Definition: BayesTree.h:150
const Nodes & nodes() const
return nodes
Definition: BayesTree.h:141
void fillNodesIndex(const sharedClique &subtree)
Fill the nodes index for a subtree.
Definition: BayesTree-inst.h:235
Roots roots_
Root cliques.
Definition: BayesTree.h:101
sharedClique sharedNode
Synonym for sharedClique (TODO: remove)
Definition: BayesTree.h:74
A clique in a GaussianBayesTree.
Definition: GaussianBayesTree.h:35
A factor graph is a bipartite graph with factor nodes connected to variable nodes.
Definition: BayesTree.h:32
A Bayes net made from linear-Gaussian densities.
Definition: GaussianBayesNet.h:30
Definition: GaussianFactorGraph.h:43
void clear()
Remove all nodes.
Definition: BayesTree-inst.h:397
A thin wrapper around std::list that uses boost's fast_pool_allocator.
void addFactorsToGraph(FactorGraph< FactorType > &graph) const
Add all cliques in this BayesTree to the specified factor graph.
Definition: BayesTree-inst.h:156
size_t size() const
number of cliques
Definition: BayesTree-inst.h:114
BayesTree()
Create an empty Bayes Tree.
Definition: BayesTree.h:107
void insertRoot(const sharedClique &subtree)
Insert a new subtree with known parent clique.
Definition: BayesTree-inst.h:249
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:437
Definition: BayesTree.h:267
store all the sizes
Definition: BayesTree.h:46
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
Typedefs for easier changing of types.
bool empty() const
Check if there are any cliques in the tree.
Definition: BayesTree.h:136
Cliques removeSubtree(const sharedClique &subtree)
Remove the requested subtree.
Definition: BayesTree-inst.h:484
sharedConditional marginalFactor(Key j, const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
Return marginal on any variable.
Definition: BayesTree-inst.h:259
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:282
Key findParentClique(const CONTAINER &parents) const
Find parent clique of a conditional.
Definition: BayesTree-inst.h:227
boost::function< EliminationResult(const FactorGraphType &, const Ordering &)> Eliminate
The function type that does a single dense elimination step on a subgraph.
Definition: EliminateableFactorGraph.h:89
FastVector< sharedClique > Roots
Root cliques.
Definition: BayesTree.h:98
size_t Key
Integer nonlinear key type.
Definition: types.h:59
void removeClique(sharedClique clique)
remove a clique: warning, can result in a forest
Definition: BayesTree-inst.h:413
clique statistics
Definition: BayesTree.h:37
CLIQUE Clique
The clique type, normally BayesTreeClique.
Definition: BayesTree.h:71
void removeTop(const FastVector< Key > &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:462
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print
Definition: BayesTree-inst.h:201
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:291
FastList< sharedClique > Cliques
A convenience class for a list of shared cliques.
Definition: BayesTree.h:87
bool equals(const This &other, double tol=1e-9) const
check equality
Definition: BayesTree-inst.h:219
void deleteCachedShortcuts()
Clear all shortcut caches - use before timing on marginal calculation to avoid residual cache data...
Definition: BayesTree-inst.h:405
BayesTreeCliqueData getCliqueData() const
Gather data on all cliques.
Definition: BayesTree-inst.h:39
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition: GaussianFactorGraph.h:65
size_t numCachedSeparatorMarginals() const
Collect number of cliques with cached separator marginals.
Definition: BayesTree-inst.h:58
const sharedNode operator[](Key j) const
Access node by variable.
Definition: BayesTree.h:144
Definition: FastList.h:38
void addClique(const sharedClique &clique, const sharedClique &parent_clique=sharedClique())
add a clique (top down)
Definition: BayesTree-inst.h:123
void saveGraph(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Read only with side effects.
Definition: BayesTree-inst.h:67
This & operator=(const This &other)
Assignment operator.
Definition: BayesTree-inst.h:188
ConcurrentMap< Key, sharedClique > Nodes
Map from keys to Clique.
Definition: BayesTree.h:90
A conditional Gaussian functions as the node in a Bayes network It has a set of parents y...
Definition: GaussianConditional.h:36
A thin wrapper around std::vector that uses boost's pool_allocator.
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: types.h:62
const Roots & roots() const
return root cliques
Definition: BayesTree.h:147
Clique Node
Synonym for Clique (TODO: remove)
Definition: BayesTree.h:73
A cluster-tree is associated with a factor graph and is defined as in Koller-Friedman: each node k re...
Definition: BayesTree.h:33
An abstract virtual base class for JacobianFactor and HessianFactor.
Definition: GaussianFactor.h:35