63 for (
const auto node:
_mb_.nodes()) {
64 for (const auto child: _model_.children(node)) {
65 if (_mb_.existsNode(child) && !_mb_.existsArc(Arc(node, child))) {
66 _mb_.addArc(node, child);
67 _specialArcs_.insert(Arc(node, child));
73 _mb_.setName(node, _model_.variable(node).name());
82 if (
size() != other.
size())
return false;
86 for (
const auto& nid:
nodes()) {
87 if (!other.
exists(
_model_.variable(nid).name())) {
return false; }
90 for (
const auto& arc:
arcs()) {
101 std::string nodeStream;
102 std::string arcStream;
104 output =
"digraph \"no_name\" {\n";
105 nodeStream =
"node [shape = ellipse];\n";
106 std::string tab =
" ";
108 for (
const auto node:
_mb_.nodes()) {
109 nodeStream += std::format(
"{}{}[label=\"{}\"", tab, node,
_model_.variable(node).name());
110 if (node ==
_node_) { nodeStream +=
", color=red"; }
111 nodeStream +=
"];\n";
113 for (
const auto chi:
_mb_.children(node)) {
114 arcStream += std::format(
"{}{} -> {}", tab, node, chi);
120 output += nodeStream +
'\n' + arcStream +
"\n}\n";
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
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.
bool exists(NodeId node) const final
Return true if this node exists in this graphical model.
const DAG & internalDag() const
Returns a const reference to the internal (unnamed) DAG. O(1), no copy. Use for stable references or ...
NodeId idFromName(std::string_view name) const override
Returns the NodeId of a variable given its 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()
const NodeGraphPart & nodes() const
wrapping DAG::nodes()
Size size() const
wrapping DAG::size()
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.
DAG markovBlanket(const G &g, NodeId node, int level=1)
Returns the level-level Markov blanket of node in g as a DAG.
gum is the global namespace for all aGrUM entities