![]() |
aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
|
Applies Meek's orientation rules to propagate arc directions in a mixed graph. More...
#include <MeekRules.h>
Public Member Functions | |
| MixedGraph | propagate (const MixedGraph &mg) |
| Applies Meek rules to a MixedGraph and returns the partially oriented result. | |
| PDAG | propagateToCPDAG (const MixedGraph &mg) |
| Applies Meek rules and returns a CPDAG (completed PDAG). | |
| DAG | propagateToDAG (const MixedGraph &mg) |
| Applies Meek rules and completes the result into a DAG. | |
| const std::vector< Arc > & | choices () const |
| Returns the arcs for which the algorithm made an arbitrary orientation choice. | |
Constructors / Destructors | |
| MeekRules () | |
| default constructor | |
| virtual | ~MeekRules () |
| destructor | |
Private Member Functions | |
| MixedGraph | _propagates_ (const MixedGraph &graph) |
| Applies Meek rules R1–R4 exhaustively and returns the resulting graph. | |
| bool | _applyMeekRules_ (MixedGraph &graph, NodeId xj) |
| Tries to orient edges incident to xj using Meek rules R1–R4. | |
| void | _propagatesOrientationInChainOfRemainingEdges_ (MixedGraph &graph) |
| Arbitrarily orients remaining undirected edges when no Meek rule applies. | |
| void | _complete_ (MixedGraph &graph) |
| Orients all remaining undirected edges, applying Meek rules then a chain heuristic. | |
Static Private Member Functions | |
| static void | _orientDoubleHeadedArcs_ (MixedGraph &mg) |
| Resolves double-headed arcs (x→y and y→x simultaneously) to avoid cycles. | |
| static bool | _isOrientable_ (const MixedGraph &graph, NodeId xi, NodeId xj) |
| Returns true if the edge xi–xj can be oriented as xi→xj under Meek rules R1–R3. | |
| static bool | _existsDirectedPath_ (const MixedGraph &graph, NodeId n1, NodeId n2) |
| Returns true if there is a directed path from n1 to n2 (BFS, double arcs ignored). | |
| static Arc | _selectArcToEraseByMinParents_ (const MixedGraph &graph, NodeId x, NodeId y) |
| Returns the arc to erase when resolving a double-headed arc, using a min-parents heuristic. | |
Private Attributes | |
| std::vector< Arc > | _choices_ |
Applies Meek's orientation rules to propagate arc directions in a mixed graph.
Given a MixedGraph (containing both directed arcs and undirected edges, with no double-headed arcs in the input), this class applies rules R1–R4 exhaustively to orient as many undirected edges as possible without introducing new v-structures. Three output flavours are available: MixedGraph (partial orientation), PDAG (completed PDAG / CPDAG), and DAG (fully oriented).
When the rules alone cannot resolve all undirected edges, an arbitrary orientation is chosen using a min-parents heuristic; the affected arcs are recorded and accessible via choices().
Definition at line 67 of file MeekRules.h.
| gum::MeekRules::MeekRules | ( | ) |
default constructor
Definition at line 58 of file MeekRules.cpp.
References MeekRules().
Referenced by MeekRules(), and ~MeekRules().
|
virtual |
destructor
Definition at line 61 of file MeekRules.cpp.
References MeekRules().
|
private |
Tries to orient edges incident to xj using Meek rules R1–R4.
Propagates the orientation from a node to its neighbours.
| graph | the graph (modified in place) |
| xj | the node whose incident undirected edges are examined |
Definition at line 212 of file MeekRules.cpp.
References _applyMeekRules_(), _choices_, and _isOrientable_().
Referenced by _applyMeekRules_(), _complete_(), _propagates_(), and _propagatesOrientationInChainOfRemainingEdges_().
|
private |
Orients all remaining undirected edges, applying Meek rules then a chain heuristic.
Definition at line 196 of file MeekRules.cpp.
References _applyMeekRules_(), and _propagatesOrientationInChainOfRemainingEdges_().
Referenced by propagateToDAG().
|
staticprivate |
Returns true if there is a directed path from n1 to n2 (BFS, double arcs ignored).
Definition at line 361 of file MeekRules.cpp.
References gum::List< Val >::empty(), gum::Set< Key >::exists(), gum::List< Val >::front(), gum::Set< Key >::insert(), gum::List< Val >::popFront(), and gum::List< Val >::pushBack().
Referenced by _isOrientable_(), _orientDoubleHeadedArcs_(), and _propagatesOrientationInChainOfRemainingEdges_().
|
staticnodiscardprivate |
Returns true if the edge xi–xj can be oriented as xi→xj under Meek rules R1–R3.
| graph | the graph |
| xi | candidate tail |
| xj | candidate head |
Definition at line 258 of file MeekRules.cpp.
References _existsDirectedPath_().
Referenced by _applyMeekRules_().
|
staticprivate |
Resolves double-headed arcs (x→y and y→x simultaneously) to avoid cycles.
Orient double-headed arcs while avoiding cycles.
For each double-headed arc, erases one direction based on existing directed paths; if neither direction creates a cycle, applies the min-parents heuristic.
| mg | the graph (modified in place) |
Definition at line 116 of file MeekRules.cpp.
References _existsDirectedPath_(), _selectArcToEraseByMinParents_(), gum::Set< Key >::begin(), gum::Set< Key >::contains(), gum::Set< Key >::empty(), gum::Set< Key >::erase(), gum::ArcGraphPart::eraseArc(), gum::Set< Key >::insert(), gum::NodeGraphPart::nodes(), and gum::ArcGraphPart::parents().
Referenced by propagateToCPDAG(), and propagateToDAG().
|
private |
Applies Meek rules R1–R4 exhaustively and returns the resulting graph.
Definition at line 183 of file MeekRules.cpp.
References _applyMeekRules_().
Referenced by propagate(), propagateToCPDAG(), and propagateToDAG().
|
private |
Arbitrarily orients remaining undirected edges when no Meek rule applies.
Arbitrary propagation if we can't propagate thanks to MeekRules.
Uses a BFS-based heuristic: picks the node with the most children as a local root and orients edges away from it.
| graph | the graph (modified in place) |
Definition at line 302 of file MeekRules.cpp.
References _applyMeekRules_(), _choices_, _existsDirectedPath_(), gum::DiGraph::addArc(), gum::Set< Key >::begin(), gum::ArcGraphPart::children(), gum::Set< Key >::clear(), gum::Set< Key >::contains(), gum::EdgeGraphPart::edges(), gum::Set< Key >::empty(), gum::Set< Key >::erase(), gum::EdgeGraphPart::eraseEdge(), gum::ArcGraphPart::existsArc(), gum::Set< Key >::insert(), gum::EdgeGraphPart::neighbours(), and gum::Set< Key >::size().
Referenced by _complete_().
|
staticprivate |
Returns the arc to erase when resolving a double-headed arc, using a min-parents heuristic.
Prefers to keep the direction whose head already has more parents. Ties are broken by neighbor count.
| graph | the graph |
| x | one endpoint |
| y | the other endpoint |
Definition at line 239 of file MeekRules.cpp.
Referenced by _orientDoubleHeadedArcs_().
| INLINE const std::vector< Arc > & gum::MeekRules::choices | ( | ) | const |
Returns the arcs for which the algorithm made an arbitrary orientation choice.
An arc is recorded here when no Meek rule could determine its direction and the algorithm had to pick one arbitrarily (e.g. to break a double-headed arc or to orient a residual undirected edge).
Definition at line 57 of file MeekRules_inl.h.
References _choices_.
| MixedGraph gum::MeekRules::propagate | ( | const MixedGraph & | mg | ) |
Applies Meek rules to a MixedGraph and returns the partially oriented result.
Propagates MeekRules in a MixedGraph.
Meek rules R1–R4 are applied exhaustively; remaining undirected edges are left as-is. Double-headed arcs may appear in the output if two rules fire in opposite directions on the same edge.
| mg | the mixed graph to orient (arcs and undirected edges, no double-headed arcs) |
Definition at line 64 of file MeekRules.cpp.
References _choices_, and _propagates_().
| PDAG gum::MeekRules::propagateToCPDAG | ( | const MixedGraph & | mg | ) |
Applies Meek rules and returns a CPDAG (completed PDAG).
Propagates the orientation of a MixedGraph (no double-headed arcs) and return a PDAG.
Meek rules R1–R4 are applied exhaustively, then any double-headed arcs are resolved using a min-parents heuristic to avoid cycles. The result is a valid PDAG with no double-headed arcs.
| mg | the mixed graph to orient |
Definition at line 70 of file MeekRules.cpp.
References _choices_, _orientDoubleHeadedArcs_(), _propagates_(), gum::PDAG::addArc(), gum::PDAG::addEdge(), and gum::NodeGraphPart::addNodeWithId().
| DAG gum::MeekRules::propagateToDAG | ( | const MixedGraph & | mg | ) |
Applies Meek rules and completes the result into a DAG.
Propagates the orientation of a MixedGraph and return a DAG.
Meek rules R1–R4 are applied, remaining undirected edges are arbitrarily oriented, and double-headed arcs are resolved to ensure an acyclic result.
| mg | the mixed graph to orient |
Definition at line 93 of file MeekRules.cpp.
References _choices_, _complete_(), _orientDoubleHeadedArcs_(), _propagates_(), gum::DAG::addArc(), and gum::NodeGraphPart::addNodeWithId().
|
private |
Definition at line 121 of file MeekRules.h.
Referenced by _applyMeekRules_(), _propagatesOrientationInChainOfRemainingEdges_(), choices(), propagate(), propagateToCPDAG(), and propagateToDAG().