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--bif each one is an ancestor of the other or of a selected node,a->bif only a is,a<->bif none is.- Parameters:
dag (
pyagrum.DAG) – the DAGlatents (
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:
- 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