65 const std::pair< bool, bool > empty_mark(
false,
false);
72 for (
const auto node: query) {
73 nodes_to_visit.
insert(std::pair< NodeId, bool >(node,
true));
78 while (!nodes_to_visit.
empty()) {
86 if (nodes_to_visit.
front().second) {
90 if (hardEvidence.
exists(node)) {
continue; }
92 if (!marks[node].first) {
93 marks[node].first =
true;
94 for (
const auto par: dag.
parents(node)) {
95 nodes_to_visit.
insert(std::pair< NodeId, bool >(par,
true));
99 if (!marks[node].second) {
100 marks[node].second =
true;
101 for (
const auto chi: dag.
children(node)) {
102 nodes_to_visit.
insert(std::pair< NodeId, bool >(chi,
false));
108 const bool is_hard_evidence = hardEvidence.
exists(node);
109 const bool is_evidence = is_hard_evidence || softEvidence.
exists(node);
111 if (is_evidence && !marks[node].first) {
112 marks[node].first =
true;
115 for (
const auto par: dag.
parents(node)) {
116 nodes_to_visit.
insert(std::pair< NodeId, bool >(par,
true));
120 if (!is_hard_evidence && !marks[node].second) {
121 marks[node].second =
true;
123 for (
const auto chi: dag.
children(node)) {
124 nodes_to_visit.
insert(std::pair< NodeId, bool >(chi,
false));
The BayesBall algorithm (as described by Schachter).
Implementation of the BayesBall class.
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
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.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Generic doubly linked lists.
Val & front() const
Returns a reference to first element of a list, if any.
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.
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
Size size() const
alias for sizeNodes
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.
void clear()
Removes all the elements, if any, from 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 ...
gum is the global namespace for all aGrUM entities