25 template<
class DERIVED,
class FACTORGRAPH>
27 const typename FactorGraphType::EliminationResult& eliminationResult)
29 conditional_ = eliminationResult.first;
33 template<
class DERIVED,
class FACTORGRAPH>
35 const DERIVED& other,
double tol)
const 37 return (!conditional_ && !other.conditional())
38 || conditional_->equals(*other.conditional(),
tol);
42 template<
class DERIVED,
class FACTORGRAPH>
46 KeySet p_F_S_parents(this->conditional()->beginParents(), this->conditional()->endParents());
47 KeySet indicesB(B->conditional()->begin(), B->conditional()->end());
49 std::set_difference(p_F_S_parents.begin(), p_F_S_parents.end(),
50 indicesB.begin(), indicesB.end(), back_inserter(S_setminus_B));
55 template<
class DERIVED,
class FACTORGRAPH>
59 gttic(shortcut_indices);
60 KeySet allKeys = p_Cp_B.keys();
61 KeySet indicesB(B->conditional()->begin(), B->conditional()->end());
62 KeyVector S_setminus_B = separator_setminus_B(B);
65 std::set_intersection(S_setminus_B.begin(), S_setminus_B.end(),
66 allKeys.begin(), allKeys.end(), back_inserter(keep));
68 std::set_intersection(indicesB.begin(), indicesB.end(),
69 allKeys.begin(), allKeys.end(), back_inserter(keep));
74 template<
class DERIVED,
class FACTORGRAPH>
78 conditional_->print(s, keyFormatter);
82 template<
class DERIVED,
class FACTORGRAPH>
86 size += child->treeSize();
91 template<
class DERIVED,
class FACTORGRAPH>
94 std::lock_guard<std::mutex> marginalLock(cachedSeparatorMarginalMutex_);
95 if (!cachedSeparatorMarginal_)
98 size_t subtree_count = 1;
100 subtree_count += child->numCachedSeparatorMarginals();
102 return subtree_count;
110 template<
class DERIVED,
class FACTORGRAPH>
114 gttic(BayesTreeCliqueBase_shortcut);
117 KeyVector S_setminus_B = separator_setminus_B(B);
118 if (!parent_.expired() && !S_setminus_B.empty())
122 gttoc(BayesTreeCliqueBase_shortcut);
124 gttic(BayesTreeCliqueBase_shortcut);
125 p_Cp_B += parent->conditional_;
128 KeyVector keep = shortcut_indices(B, p_Cp_B);
131 boost::shared_ptr<FactorGraphType> p_S_B = p_Cp_B.marginal(keep,
function);
132 return *p_S_B->eliminatePartialSequential(S_setminus_B,
function).first;
144 template <
class DERIVED,
class FACTORGRAPH>
148 std::lock_guard<std::mutex> marginalLock(cachedSeparatorMarginalMutex_);
149 gttic(BayesTreeCliqueBase_separatorMarginal);
151 if (!cachedSeparatorMarginal_) {
152 gttic(BayesTreeCliqueBase_separatorMarginal_cachemiss);
155 if (parent_.expired() ) {
158 cachedSeparatorMarginal_ = empty;
161 gttoc(BayesTreeCliqueBase_separatorMarginal_cachemiss);
162 gttoc(BayesTreeCliqueBase_separatorMarginal);
169 gttic(BayesTreeCliqueBase_separatorMarginal);
170 gttic(BayesTreeCliqueBase_separatorMarginal_cachemiss);
173 p_Cp += parent->conditional_;
176 KeyVector indicesS(this->conditional()->beginParents(),
177 this->conditional()->endParents());
178 auto separatorMarginal =
179 p_Cp.marginalMultifrontalBayesNet(
Ordering(indicesS),
function);
180 cachedSeparatorMarginal_.reset(*separatorMarginal);
185 return *cachedSeparatorMarginal_;
192 template <
class DERIVED,
class FACTORGRAPH>
196 gttic(BayesTreeCliqueBase_marginal2);
200 p_C += boost::shared_ptr<FactorType>(this->conditional_);
205 template<
class DERIVED,
class FACTORGRAPH>
212 std::lock_guard<std::mutex> marginalLock(cachedSeparatorMarginalMutex_);
213 if (cachedSeparatorMarginal_) {
215 child->deleteCachedShortcuts();
219 cachedSeparatorMarginal_ = boost::none;
FACTORGRAPH FactorGraphType
KeyVector shortcut_indices(const derived_ptr &B, const FactorGraphType &p_Cp_B) const
FactorGraphType::Eliminate Eliminate
size_t numCachedSeparatorMarginals() const
EliminationTraitsType::BayesNetType BayesNetType
BayesNetType shortcut(const derived_ptr &root, Eliminate function=EliminationTraitsType::DefaultEliminate) const
void setEliminationResult(const typename FactorGraphType::EliminationResult &eliminationResult)
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
FactorGraphType marginal2(Eliminate function=EliminationTraitsType::DefaultEliminate) const
virtual void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
boost::shared_ptr< DerivedType > derived_ptr
void deleteCachedShortcuts()
bool equals(const DERIVED &other, double tol=1e-9) const
KeyVector separator_setminus_B(const derived_ptr &B) const
Calculate set for shortcut calculations.
FactorGraphType separatorMarginal(Eliminate function=EliminationTraitsType::DefaultEliminate) const
Base class for cliques of a BayesTree.