Maximal Ancestral Graph (MAG)

a 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 by MAG.fromDAG, MAG.fromPAG or the checked conversion MAG.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

adjacencyMatrix()

adjacency matrix from a graph/graphical models

adjacents()

children()

connectedComponents()

The connected components of the graph (of its skeleton).

connectedComponentsCount()

number of connected components

connectedComponentsList()

connected components as a dict of sets

edges()

empty()

existsEdge()

existsNode()

fromDAG()

The MAG of a DAG over its observed nodes (Richardson and Spirtes 2002, Theorem 4.2).

fromMarkedGraph()

Checked conversion of a marked graph.

fromPAG()

A representative MAG of the Markov equivalence class represented by a PAG (Zhang 2008, Artificial Intelligence, Theorem 2): the edges o-> and --o become ->, and the edges o-o are oriented into a DAG without unshielded collider.

graph()

hasName()

idFromName()

Return the id of the node with the given name, or None if no such name exists.

idsFromNames()

The ids of nodes given by their names, in a container of the same type.

mSeparation()

Test the m-separation (the separation of the MAG: the d-separation of the DAGs it represents).

markAt()

nameFromId()

Return the name of a node, or its id as a string if no name was set.

namesFromIds()

The names of nodes given by their ids, in a container of the same type.

neighbours()

nodes()

parents()

saveGUM()

Save the graph as a .jgum (text) or .bgum (binary) file (its class, its nodes with their names, its arcs, edges and marks).

saveGUMstring()

Save the graph as a jgum string (see pyagrum.graphFromGUMString to read it back).

size()

sizeEdges()

skeleton()

spouses()

toDot()

toString()