47 template<
class DERIVED,
class FACTORGRAPH>
52 typedef DERIVED DerivedType;
54 typedef std::shared_ptr<This> shared_ptr;
55 typedef std::weak_ptr<This> weak_ptr;
56 typedef std::shared_ptr<DerivedType> derived_ptr;
57 typedef std::weak_ptr<DerivedType> derived_weak_ptr;
60 typedef FACTORGRAPH FactorGraphType;
61 typedef typename EliminationTraitsType::BayesNetType BayesNetType;
62 typedef typename BayesNetType::ConditionalType ConditionalType;
63 typedef std::shared_ptr<ConditionalType> sharedConditional;
64 typedef typename FactorGraphType::FactorType FactorType;
65 typedef typename FactorGraphType::Eliminate Eliminate;
82 : conditional_(c.conditional_),
85 problemSize_(c.problemSize_),
90 conditional_ = c.conditional_;
92 children = c.children;
93 problemSize_ = c.problemSize_;
112 sharedConditional conditional_;
113 derived_weak_ptr parent_;
117 bool is_root =
false;
128 bool equals(
const DERIVED& other,
double tol = 1e-9)
const;
132 const std::string& s =
"",
140 const sharedConditional&
conditional()
const {
return conditional_; }
146 inline bool isRoot()
const {
return parent_.expired(); }
152 const derived_ptr
operator[](
size_t i)
const {
return children.at(i); }
161 derived_ptr
parent()
const {
return parent_.lock(); }
185 const std::optional<FactorGraphType>& cachedSeparatorMarginal()
const {
210#if GTSAM_ENABLE_BOOST_SERIALIZATION
212 friend class boost::serialization::access;
213 template<
class ARCHIVE>
214 void serialize(ARCHIVE & ar,
const unsigned int ) {
215 if(!parent_.lock()) {
218 ar & BOOST_SERIALIZATION_NVP(is_root);
219 ar & BOOST_SERIALIZATION_NVP(conditional_);
221 ar & BOOST_SERIALIZATION_NVP(parent_);
223 ar & BOOST_SERIALIZATION_NVP(children);
A thin wrapper around std::vector that uses a custom allocator.
Typedefs for easier changing of types.
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
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
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
static std::pair< std::shared_ptr< ConditionalType >, std::shared_ptr< FactorType > > DefaultEliminate(const FactorGraphType &factors, const Ordering &keys)
The default dense elimination function.
Definition DiscreteFactorGraph.h:81
Bayes tree.
Definition BayesTree.h:77
Traits class for eliminateable factor graphs, specifies the types that result from elimination,...
Definition EliminateableFactorGraph.h:38
This is the base class for BayesTree cliques.
Definition BayesTreeCliqueBase.h:49
const derived_ptr operator[](size_t i) const
Return the child at index i.
Definition BayesTreeCliqueBase.h:152
BayesTreeCliqueBase & operator=(const BayesTreeCliqueBase &c)
Shallow copy assignment constructor.
Definition BayesTreeCliqueBase.h:89
void deleteCachedShortcutsNonRecursive()
Non-recursive delete cached shortcuts and marginals - internal only.
Definition BayesTreeCliqueBase.h:203
size_t nrChildren() const
Return the number of children.
Definition BayesTreeCliqueBase.h:149
int problemSize() const
Problem size (used for parallel traversal).
Definition BayesTreeCliqueBase.h:164
BayesTreeCliqueBase()
Default constructor.
Definition BayesTreeCliqueBase.h:73
derived_ptr parent() const
return a shared_ptr to the parent clique
Definition BayesTreeCliqueBase.h:161
size_t treeSize() const
The size of subtree rooted at this clique, i.e., nr of Cliques.
Definition BayesTreeCliqueBase-inst.h:87
BayesTreeCliqueBase(const sharedConditional &conditional)
Construct from a conditional, leaving parent and child pointers uninitialized.
Definition BayesTreeCliqueBase.h:77
std::mutex cachedSeparatorMarginalMutex_
Definition BayesTreeCliqueBase.h:109
bool isRoot() const
Return true if this clique is the root of a Bayes tree.
Definition BayesTreeCliqueBase.h:146
sharedConditional & conditional()
Write access to the conditional.
Definition BayesTreeCliqueBase.h:143
BayesTreeCliqueBase(const BayesTreeCliqueBase &c)
Shallow copy constructor.
Definition BayesTreeCliqueBase.h:81
FactorGraphType marginal2(Eliminate function=EliminationTraitsType::DefaultEliminate) const
return the marginal P(C) of the clique, using marginal caching
Definition BayesTreeCliqueBase-inst.h:212
bool equals(const DERIVED &other, double tol=1e-9) const
check equality
Definition BayesTreeCliqueBase-inst.h:38
FactorGraphType separatorMarginal(Eliminate function=EliminationTraitsType::DefaultEliminate) const
return the marginal P(S) on the separator
Definition BayesTreeCliqueBase-inst.h:152
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:118
void deleteCachedShortcuts()
This deletes the cached shortcuts of all cliques (subtree) below this clique.
Definition BayesTreeCliqueBase-inst.h:224
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:60
const sharedConditional & conditional() const
Definition BayesTreeCliqueBase.h:140
KeyVector separator_setminus_B(const derived_ptr &B) const
Calculate set for shortcut calculations.
Definition BayesTreeCliqueBase-inst.h:48
virtual void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print this node
Definition BayesTreeCliqueBase-inst.h:79
size_t numCachedSeparatorMarginals() const
Collect number of cliques with cached separator marginals.
Definition BayesTreeCliqueBase-inst.h:96
std::optional< FactorGraphType > cachedSeparatorMarginal_
Definition BayesTreeCliqueBase.h:104
void setEliminationResult(const typename FactorGraphType::EliminationResult &eliminationResult)
Fill the elimination result produced during elimination.
Definition BayesTreeCliqueBase-inst.h:30
std::pair< std::shared_ptr< ConditionalType >, std::shared_ptr< _FactorType > > EliminationResult
Definition EliminateableFactorGraph.h:88