48 template < GUM_DiGraphable G,
bool CollectAll >
53 static constexpr std::pair< bool, bool > empty_mark{
false,
false};
57 for (
const auto node: query)
58 to_visit.
insert(std::pair{node,
true});
60 while (!to_visit.
empty()) {
62 const bool from_child = to_visit.
front().second;
69 if (Zhard.
exists(node))
continue;
73 for (
const auto par: g.parents(node))
74 to_visit.
insert(std::pair{par,
true});
78 for (
const auto chi: g.children(node))
79 to_visit.
insert(std::pair{chi,
false});
83 if constexpr (CollectAll) result.
insert(node);
85 const bool is_hard = Zhard.
exists(node);
86 const bool is_ev = is_hard || Zsoft.
exists(node);
90 if constexpr (!CollectAll) result.
insert(node);
91 for (
const auto par: g.parents(node))
92 to_visit.
insert(std::pair{par,
true});
94 if (!is_hard && !bot) {
96 for (
const auto chi: g.children(node))
97 to_visit.
insert(std::pair{chi,
false});
105 template < GUM_DiGraphable G >
111 template < GUM_DiGraphable G >
Generic Bayes Ball algorithm (Shachter 1998) for directed graphs.
mapped_type & getWithDefault(const Key &key, const Val &default_value)
Returns a reference on the element the key of which is passed in argument.
Generic doubly linked lists.
Val & front() const
Returns a reference to first element of a list, if any.
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
void popFront()
Removes the first element of a List, if any.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
void insert(const Key &k)
Inserts a new element into the set.
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet _bayesBall_(const G &g, const NodeSet &query, const NodeSet &Zhard, const NodeSet &Zsoft)
NodeSet requisiteNodes(const G &g, const NodeSet &query, const NodeSet &Zhard=NodeSet(), const NodeSet &Zsoft=NodeSet())
Returns the Shachter-requisite nodes for query given evidence.
NodeSet dConnected(const G &g, const NodeSet &query, const NodeSet &Zhard=NodeSet(), const NodeSet &Zsoft=NodeSet())
Returns all nodes d-connected to query given evidence.