32 template<
class CLIQUE>
class BayesTree;
48 template<
class DERIVED,
class FACTORGRAPH>
53 typedef DERIVED DerivedType;
55 typedef std::shared_ptr<This> shared_ptr;
56 typedef std::weak_ptr<This> weak_ptr;
57 typedef std::shared_ptr<DerivedType> derived_ptr;
58 typedef std::weak_ptr<DerivedType> derived_weak_ptr;
61 typedef FACTORGRAPH FactorGraphType;
62 typedef typename EliminationTraitsType::BayesNetType BayesNetType;
63 typedef typename BayesNetType::ConditionalType ConditionalType;
64 typedef std::shared_ptr<ConditionalType> sharedConditional;
65 typedef typename FactorGraphType::FactorType FactorType;
66 typedef typename FactorGraphType::Eliminate Eliminate;
79 : conditional_(conditional), problemSize_(1) {}
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_;
118 bool is_root =
false;
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 std::optional<FactorGraphType>& cachedSeparatorMarginal()
const {
178 std::lock_guard<std::mutex> marginalLock(cachedSeparatorMarginalMutex_);
196 std::lock_guard<std::mutex> marginalLock(cachedSeparatorMarginalMutex_);
197 cachedSeparatorMarginal_ = {};
202 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 204 friend class boost::serialization::access;
205 template<
class ARCHIVE>
206 void serialize(ARCHIVE & ar,
const unsigned int ) {
207 if(!parent_.lock()) {
210 ar & BOOST_SERIALIZATION_NVP(is_root);
211 ar & BOOST_SERIALIZATION_NVP(conditional_);
213 ar & BOOST_SERIALIZATION_NVP(parent_);
215 ar & BOOST_SERIALIZATION_NVP(children);
Typedefs for easier changing of types.
std::mutex cachedSeparatorMarginalMutex_
Definition: BayesTreeCliqueBase.h:110
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:113
void deleteCachedShortcutsNonRecursive()
Definition: BayesTreeCliqueBase.h:195
BayesTreeCliqueBase(const BayesTreeCliqueBase &c)
Shallow copy constructor.
Definition: BayesTreeCliqueBase.h:82
std::optional< FactorGraphType > cachedSeparatorMarginal_
This stores the Cached separator marginal P(S)
Definition: BayesTreeCliqueBase.h:105
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
Definition: FastVector.h:34
size_t treeSize() const
Definition: BayesTreeCliqueBase-inst.h:84
Variable ordering for the elimination algorithm.
bool equals(const DERIVED &other, double tol=1e-9) const
Definition: BayesTreeCliqueBase-inst.h:35
BayesTreeCliqueBase(const sharedConditional &conditional)
Definition: BayesTreeCliqueBase.h:78
Definition: BayesTreeCliqueBase.h:49
void setEliminationResult(const typename FactorGraphType::EliminationResult &eliminationResult)
Definition: BayesTreeCliqueBase-inst.h:27
Definition: BayesTree.h:66
virtual void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Definition: BayesTreeCliqueBase-inst.h:76
size_t numCachedSeparatorMarginals() const
Definition: BayesTreeCliqueBase-inst.h:93
derived_ptr parent() const
Definition: BayesTreeCliqueBase.h:153
std::pair< std::shared_ptr< ConditionalType >, std::shared_ptr< _FactorType > > EliminationResult
Definition: EliminateableFactorGraph.h:85
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 thin wrapper around std::vector that uses a custom allocator.
Definition: chartTesting.h:28
BayesNetType shortcut(const derived_ptr &root, Eliminate function=EliminationTraitsType::DefaultEliminate) const
Definition: BayesTreeCliqueBase-inst.h:113
void deleteCachedShortcuts()
Definition: BayesTreeCliqueBase-inst.h:207
FactorGraphType separatorMarginal(Eliminate function=EliminationTraitsType::DefaultEliminate) const
Definition: BayesTreeCliqueBase-inst.h:147
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
FactorGraphType marginal2(Eliminate function=EliminationTraitsType::DefaultEliminate) const
Definition: BayesTreeCliqueBase-inst.h:195
Definition: BayesTreeCliqueBase.h:33
BayesTreeCliqueBase()
Default constructor.
Definition: BayesTreeCliqueBase.h:74
bool isRoot() const
Definition: BayesTreeCliqueBase.h:144
int problemSize() const
Definition: BayesTreeCliqueBase.h:156
BayesTreeCliqueBase & operator=(const BayesTreeCliqueBase &c)
Shallow copy assignment constructor.
Definition: BayesTreeCliqueBase.h:90
KeyVector shortcut_indices(const derived_ptr &B, const FactorGraphType &p_Cp_B) const
Definition: BayesTreeCliqueBase-inst.h:57
KeyVector separator_setminus_B(const derived_ptr &B) const
Calculate set for shortcut calculations.
Definition: BayesTreeCliqueBase-inst.h:45
const sharedConditional & conditional() const
Definition: BayesTreeCliqueBase.h:141