65 auto todo =
_mb_.nodes().asNodeSet() - done;
66 bool anythingnew =
false;
71 if (!anythingnew)
break;
77 for (
const auto node:
_mb_.nodes()) {
78 for (
const auto child:
_model_.children(node)) {
79 if (
_mb_.existsNode(child) && !
_mb_.existsArc(
Arc(node, child))) {
80 _mb_.addArc(node, child);
94 if (!
_model_.nodes().exists(node))
97 if (!
_mb_.nodes().exists(node)) {
98 _mb_.addNodeWithId(node);
102 for (
const auto& parent:
_model_.parents(node)) {
103 if (!
_mb_.nodes().exists(parent)) {
104 _mb_.addNodeWithId(parent);
107 _mb_.addArc(parent, node);
110 for (
const auto& child:
_model_.children(node)) {
111 if (!
_mb_.nodes().exists(child)) {
112 _mb_.addNodeWithId(child);
115 _mb_.addArc(node, child);
116 for (
const auto& opar:
_model_.parents(child)) {
118 if (!
_mb_.nodes().exists(opar)) {
119 _mb_.addNodeWithId(opar);
122 _mb_.addArc(opar, child);
131 if (
size() != other.
size())
return false;
135 for (
const auto& nid:
nodes()) {
138 }
catch (
NotFound const&) {
return false; }
141 for (
const auto& arc:
arcs()) {
151 std::stringstream output;
152 std::stringstream nodeStream;
153 std::stringstream arcStream;
155 output <<
"digraph \""
156 <<
"no_name\" {" << std::endl;
157 nodeStream <<
"node [shape = ellipse];" << std::endl;
158 std::string tab =
" ";
160 for (
const auto node:
_mb_.nodes()) {
161 nodeStream << tab << node <<
"[label=\"" <<
_model_.variable(node).name() <<
"\"";
162 if (node ==
_node_) { nodeStream <<
", color=red"; }
163 nodeStream <<
"];" << std::endl;
165 for (
const auto chi:
_mb_.children(node)) {
166 arcStream << tab << node <<
" -> " << chi;
168 arcStream <<
";" << std::endl;
172 output << nodeStream.str() << std::endl << arcStream.str() << std::endl <<
"}" << std::endl;
Class building the markovBlanket from a DAGmodel and a node name.
Inline implementation of the class building the essential Graph from a DAGmodel.
The base class for all directed edges.
Virtual base class for PGMs using a DAG.
const ArcSet & arcs() const
return true if the arc tail->head exists in the DAGmodel
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
Exception: at least one argument passed to a function is not what was expected.
Generic doubly linked lists.
MarkovBlanket(const DAGmodel &m, NodeId n, int level=1)
std::string toDot() const
bool hasSameStructure(const DAGmodel &other) const
Size sizeArcs() const
wrapping DAG::sizeArcs()
const ArcSet & arcs() const
wrapping DAG::arcs()
bool _buildMarkovBlanket_(const NodeId id)
const NodeGraphPart & nodes() const
wrapping DAG::nodes()
Size size() const
wrapping DAG::size()
Exception : the element we looked for cannot be found.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
#define GUM_ERROR(type, msg)
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities