24#include <boost/optional.hpp>
32 template<
class CLIQUE>
class BayesTree;
33 template<
class GRAPH>
struct EliminationTraits;
48 template<
class DERIVED,
class FACTORGRAPH>
53 typedef DERIVED DerivedType;
55 typedef boost::shared_ptr<This> shared_ptr;
56 typedef boost::weak_ptr<This> weak_ptr;
57 typedef boost::shared_ptr<DerivedType> derived_ptr;
58 typedef boost::weak_ptr<DerivedType> derived_weak_ptr;
61 typedef FACTORGRAPH FactorGraphType;
62 typedef typename EliminationTraitsType::BayesNetType BayesNetType;
63 typedef typename BayesNetType::ConditionalType ConditionalType;
64 typedef boost::shared_ptr<ConditionalType> sharedConditional;
65 typedef typename FactorGraphType::FactorType FactorType;
66 typedef typename FactorGraphType::Eliminate Eliminate;
83 : conditional_(c.conditional_),
86 problemSize_(c.problemSize_),
91 conditional_ = c.conditional_;
93 children = c.children;
94 problemSize_ = c.problemSize_;
113 sharedConditional conditional_;
114 derived_weak_ptr parent_;
115 FastVector<derived_ptr> children;
118 bool is_root =
false;
123 void setEliminationResult(
const typename FactorGraphType::EliminationResult& eliminationResult);
129 bool equals(
const DERIVED& other,
double tol = 1e-9)
const;
133 const std::string& s =
"",
134 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
141 const sharedConditional&
conditional()
const {
return conditional_; }
144 inline bool isRoot()
const {
return parent_.expired(); }
153 derived_ptr
parent()
const {
return parent_.lock(); }
163 BayesNetType
shortcut(
const derived_ptr& root, Eliminate function = EliminationTraitsType::DefaultEliminate)
const;
166 FactorGraphType
separatorMarginal(Eliminate function = EliminationTraitsType::DefaultEliminate)
const;
169 FactorGraphType
marginal2(Eliminate function = EliminationTraitsType::DefaultEliminate)
const;
177 const boost::optional<FactorGraphType>& cachedSeparatorMarginal()
const {
182 friend class BayesTree<DerivedType>;
204 template<
class ARCHIVE>
205 void serialize(ARCHIVE & ar,
const unsigned int ) {
206 if(!parent_.lock()) {
209 ar & BOOST_SERIALIZATION_NVP(is_root);
210 ar & BOOST_SERIALIZATION_NVP(conditional_);
212 ar & BOOST_SERIALIZATION_NVP(parent_);
214 ar & BOOST_SERIALIZATION_NVP(children);
A thin wrapper around std::vector that uses a custom allocator.
Typedefs for easier changing of types.
Variable ordering for the elimination algorithm.
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
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
Traits class for eliminateable factor graphs, specifies the types that result from elimination,...
Definition: EliminateableFactorGraph.h:36
This is the base class for BayesTree cliques.
Definition: BayesTreeCliqueBase.h:50
BayesTreeCliqueBase & operator=(const BayesTreeCliqueBase &c)
Shallow copy assignment constructor.
Definition: BayesTreeCliqueBase.h:90
void deleteCachedShortcutsNonRecursive()
Non-recursive delete cached shortcuts and marginals - internal only.
Definition: BayesTreeCliqueBase.h:195
int problemSize() const
Problem size (used for parallel traversal)
Definition: BayesTreeCliqueBase.h:156
BayesTreeCliqueBase()
Default constructor.
Definition: BayesTreeCliqueBase.h:74
derived_ptr parent() const
return a shared_ptr to the parent clique
Definition: BayesTreeCliqueBase.h:153
size_t treeSize() const
The size of subtree rooted at this clique, i.e., nr of Cliques.
Definition: BayesTreeCliqueBase-inst.h:83
BayesTreeCliqueBase(const sharedConditional &conditional)
Construct from a conditional, leaving parent and child pointers uninitialized.
Definition: BayesTreeCliqueBase.h:78
std::mutex cachedSeparatorMarginalMutex_
This protects Cached seperator marginal P(S) from concurrent read/writes as many the functions which ...
Definition: BayesTreeCliqueBase.h:110
bool isRoot() const
is this the root of a Bayes tree ?
Definition: BayesTreeCliqueBase.h:144
BayesTreeCliqueBase(const BayesTreeCliqueBase &c)
Shallow copy constructor.
Definition: BayesTreeCliqueBase.h:82
FactorGraphType marginal2(Eliminate function=EliminationTraitsType::DefaultEliminate) const
return the marginal P(C) of the clique, using marginal caching
Definition: BayesTreeCliqueBase-inst.h:194
bool equals(const DERIVED &other, double tol=1e-9) const
check equality
Definition: BayesTreeCliqueBase-inst.h:34
FactorGraphType separatorMarginal(Eliminate function=EliminationTraitsType::DefaultEliminate) const
return the marginal P(S) on the separator
Definition: BayesTreeCliqueBase-inst.h:146
BayesNetType shortcut(const derived_ptr &root, Eliminate function=EliminationTraitsType::DefaultEliminate) const
return the conditional P(S|Root) on the separator given the root
Definition: BayesTreeCliqueBase-inst.h:112
void deleteCachedShortcuts()
This deletes the cached shortcuts of all cliques (subtree) below this clique.
Definition: BayesTreeCliqueBase-inst.h:206
KeyVector shortcut_indices(const derived_ptr &B, const FactorGraphType &p_Cp_B) const
Determine variable indices to keep in recursive separator shortcut calculation The factor graph p_Cp_...
Definition: BayesTreeCliqueBase-inst.h:56
const sharedConditional & conditional() const
Access the conditional.
Definition: BayesTreeCliqueBase.h:141
friend class boost::serialization::access
Serialization function.
Definition: BayesTreeCliqueBase.h:203
KeyVector separator_setminus_B(const derived_ptr &B) const
Calculate set for shortcut calculations.
Definition: BayesTreeCliqueBase-inst.h:44
virtual void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print this node
Definition: BayesTreeCliqueBase-inst.h:75
size_t numCachedSeparatorMarginals() const
Collect number of cliques with cached separator marginals.
Definition: BayesTreeCliqueBase-inst.h:92
boost::optional< FactorGraphType > cachedSeparatorMarginal_
This stores the Cached separator marginal P(S)
Definition: BayesTreeCliqueBase.h:105
void setEliminationResult(const typename FactorGraphType::EliminationResult &eliminationResult)
Fill the elimination result produced during elimination.
Definition: BayesTreeCliqueBase-inst.h:26