Maximal Ancestral Graph (MAG)
- class pyagrum.MAG(*args)
MAG represents a maximal ancestral graph: the independence model of a DAG over its observed variables, the latent variables being marginalized and the selected ones conditioned on.
A MAG is a marked graph without circle (edges
->,<->and--) which is ancestral and maximal; its separation is the m-separation. A MAG is immutable: it is built byMAG.fromDAG,MAG.fromPAGor the checked conversionMAG.fromMarkedGraph.
Example
import pyagrum as gum
dag = gum.fastDAG("A->X<-T->Y<-B")
mag = gum.MAG.fromDAG(dag, {dag.idFromName("T")}) # T latent: A->X<->Y<-B
print(mag)
# {0<A>,1<X>,3<Y>,4<B>} , {0 --> 1, 1 <-> 3, 3 <-- 4}
Scientific notes
A MAG (maximal ancestral graph) represents the independence model of a DAG over its observed variables, the latent
variables being marginalized and the selected ones conditioned on [1]. It is a marked
graph (pyagrum.MarkedGraph) without circle, with edges \(\to\), \(\leftrightarrow\) and \(-\), which is
ancestral: no node is anterior to one of its parents or spouses (anterior: linked to it by a path of edges \(-\) and \(\to\) pointing towards it), and a node with an undirected edge has neither parent nor spouse;
maximal: two non adjacent nodes are m-separated by some set.
m-separation (mSeparation): \(X\) and \(Y\) are m-separated by \(Z\) if no path between them has
all its non-colliders out of \(Z\) and all its colliders anterior to \(Z\) (a node of \(Z\) being anterior
to \(Z\)) [1]. It is computed by a linear search, and, as for the d-separation
(pyagrum.DAG), a node of \(X\) or \(Y\) that belongs to \(Z\) is separated from any node. On a DAG it is
the d-separation.
Construction from a DAG (fromDAG, with latent nodes \(L\) and selected nodes \(S\)), following
[1]: two observed nodes \(a\), \(b\) are adjacent iff they are not d-separated in
the DAG by \(\mathrm{an}(\{a,b\} \cup S) \setminus (L \cup \{a,b\})\), \(\mathrm{an}\) including the nodes
themselves; the edge is \(a - b\) if each one is an ancestor of the other or of \(S\), \(a \to b\) if only
\(a\) is, and \(a \leftrightarrow b\) if none is.
Representative of a PAG (fromPAG): the circles of the edges \(\circ\!\!\to\) become tails, the circles
of the edges \(-\!\!\circ\) become arrowheads (both become \(\to\)), and the edges
\(\circ\!\!-\!\!\circ\) are oriented into a DAG without unshielded collider; the result is a MAG of the class of
the PAG [2][3]. The causal reasoning with MAGs and PAGs is studied in
[4].
Methods
adjacency matrix from a graph/graphical models |
|
The connected components of the graph (of its skeleton). |
|
number of connected components |
|
connected components as a dict of sets |
|
The MAG of a DAG over its observed nodes (Richardson and Spirtes 2002, Theorem 4.2). |
|
Checked conversion of a marked graph. |
|
A representative MAG of the Markov equivalence class represented by a PAG (Zhang 2008, Artificial Intelligence, Theorem 2): the edges |
|
Return the id of the node with the given name, or None if no such name exists. |
|
The ids of nodes given by their names, in a container of the same type. |
|
Test the m-separation (the separation of the MAG: the d-separation of the DAGs it represents). |
|
Return the name of a node, or its id as a string if no name was set. |
|
The names of nodes given by their ids, in a container of the same type. |
|
Save the graph as a .jgum (text) or .bgum (binary) file (its class, its nodes with their names, its arcs, edges and marks). |
|
Save the graph as a jgum string (see |
|