MAG.fromDAG

static MAG.fromDAG(*args)

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

Two observed nodes are adjacent iff no set of observed nodes (with the selected ones) d-separates them; the edge is a--b if each one is an ancestor of the other or of a selected node, a->b if only a is, a<->b if none is.

Parameters:
  • dag (pyagrum.DAG) – the DAG

  • latents (set[int], optional) – its latent nodes (marginalized), as a set (not a list)

  • selection (set[int], optional) – its selected nodes (conditioned on), as a set (not a list)

Returns:

the MAG over the other nodes (same ids and names)

Return type:

pyagrum.MAG

Raises:

pyagrum.InvalidArgument – if a node is both latent and selected, or is not in the DAG

Example

import pyagrum as gum

dag = gum.fastDAG("A->X<-T->Y<-B")
mag = gum.MAG.fromDAG(dag, {dag.idFromName("T")})  # T latent
print(mag)
# {0<A>,1<X>,3<Y>,4<B>} , {0 --> 1, 1 <-> 3, 3 <-- 4}
dag = gum.fastDAG("A->S<-B;B->C")
print(gum.MAG.fromDAG(dag, set(), {dag.idFromName("S")}))  # S selected: A--B
# {0<A>,2<B>,3<C>} , {2 --> 3, 0 --- 2}

Class

MAG