29 #endif // GUM_NO_INLINE 43 const std::pair< bool, bool > empty_mark(
false,
false);
50 for (
const auto node : query) {
51 nodes_to_visit.
insert(std::pair< NodeId, bool >(node,
true));
56 while (!nodes_to_visit.
empty()) {
61 if (!marks.exists(node)) marks.insert(node, empty_mark);
64 if (nodes_to_visit.
front().second) {
68 if (hardEvidence.
exists(node)) {
continue; }
70 if (!marks[node].first) {
71 marks[node].first =
true;
72 for (
const auto par : dag.
parents(node)) {
73 nodes_to_visit.
insert(std::pair< NodeId, bool >(par,
true));
77 if (!marks[node].second) {
78 marks[node].second =
true;
79 for (
const auto chi : dag.
children(node)) {
80 nodes_to_visit.
insert(std::pair< NodeId, bool >(chi,
false));
86 const bool is_hard_evidence = hardEvidence.
exists(node);
87 const bool is_evidence = is_hard_evidence || softEvidence.
exists(node);
89 if (is_evidence && !marks[node].first) {
90 marks[node].first =
true;
93 for (
const auto par : dag.
parents(node)) {
94 nodes_to_visit.
insert(std::pair< NodeId, bool >(par,
true));
98 if (!is_hard_evidence && !marks[node].second) {
99 marks[node].second =
true;
101 for (
const auto chi : dag.
children(node)) {
102 nodes_to_visit.
insert(std::pair< NodeId, bool >(chi,
false));
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
Size size() const
alias for sizeNodes
The BayesBall algorithm (as described by Schachter).
Generic doubly linked lists.
gum is the global namespace for all aGrUM entities
void popFront()
Removes the first element of a List, if any.
The class for generic Hash Tables.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
Val & front() const
Returns a reference to first element of a list, if any.
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Implementation of the BayesBall class.
void clear()
Removes all the elements, if any, from the set.
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
static void requisiteNodes(const DAG &dag, const NodeSet &query, const NodeSet &hardEvidence, const NodeSet &softEvidence, NodeSet &requisite)
Fill the 'requisite' nodeset with the requisite nodes in dag given a query and evidence.