Directed Acyclic Graph (DAG)

a DAG
class pyagrum.DAG(*args)

DAG represents a Directed Acyclic Graph.

DAG() -> DAG

default constructor

DAG(src) -> DAG
Parameters:
DAG(src) -> DAG
Parameters:
  • src (pyagrum.DiGraph) – a directed graph without directed cycle (for a mixed graph, only its arcs are copied)

Raises:
  • pyagrum.InvalidDirectedCycle – if src has a directed cycle

Scientific notes

A DAG is a directed graph without directed cycle. Its independence model is the d-separation [1]: \(X\) and \(Y\) are d-separated by \(Z\) if every path between them contains either a non-collider that belongs to \(Z\), or a collider (\(\to v \leftarrow\)) that is not in \(Z\) and has no descendant in \(Z\). dSeparation decides it in linear time with the Bayes-Ball algorithm [2]. Convention of pyAgrum: \(X\) and \(Y\) must be disjoint, and a node of \(X\) or \(Y\) that belongs to \(Z\) is observed, hence separated from any node (the result is the one for \(X \setminus Z\) and \(Y \setminus Z\)).

moralGraph links the parents of each node and drops the directions; moralizedAncestralGraph(S) does the same on the subgraph induced by \(S\) and its ancestors (the ancestors of a node do not include the node itself). minimalCondSet(target, S) is the part of \(S\) that matters for the target, \(P(\mathit{target} \mid S) = P(\mathit{target} \mid S')\): it is read from the graph alone, by a Bayes-Ball-like traversal from the target that stops at the nodes of \(S\), so it holds for every distribution of the DAG.

Methods

addArc()

Add an arc from tail to head.

addNodes()

Add a set of n nodes.

ancestors()

give the set of nodeid of ancestors of a node

arcs()

Returns the set of arcs in the graph.

children()

dSeparation()

Check if the sets of nodes X and Y are d-separated (by the set of nodes Z if given) in the DAG.

descendants()

give the set of nodeid of descendants of a node

emptyArcs()

Check if the graph doesn’t contains arcs.

eraseArc()

Erase the arc between n1 and n2.

eraseChildren()

Erase the arcs heading to the node’s children.

eraseParents()

Erase the arcs coming to the node.

existsArc()

Check if an arc exists between n1 and n2.

minimalCondSet()

Return a minimal conditioning set of a target given source nodes in the DAG.

moralGraph()

Returns the moral graph of the DAG, formed by adding edges between all pairs of nodes that have a common child, and then making all edges in the graph undirected.

moralizedAncestralGraph()

Compute the moralized ancestral graph of the nodes from the DAG.

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).

sizeArcs()

Methods inherited from DiGraph

addNode()

addNodeWithId()

Add a node by choosing a new NodeId.

adjacencyMatrix()

adjacency matrix from a graph/graphical models

clear()

Remove all the nodes and arcs from the graph.

completeGraph()

Create a complete directed graph with n nodes.

connectedComponents()

Returns the weakly connected components of the graph.

connectedComponentsCount()

number of connected components

connectedComponentsList()

connected components as a dict of sets

directedPath()

Return a shortest directed path from node1 to node2, or None if no such path exists.

directedUnorientedPath()

Return a shortest path from node1 to node2 ignoring arc orientation, or None if no path exists.

empty()

Check if the graph is empty.

eraseNode()

Erase the node and all the related arcs.

existsNode()

Check if a node with a certain id exists in the graph.

family()

Return the family of a node: the node itself plus all its parents.

hasDirectedPath()

Check if a directedpath exists between from and to.

hasName()

Check whether a node has an explicitly assigned name.

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.

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.

nodes()

setName()

Assign a name to a node.

size()

toDot()

topologicalOrder()