causaldag.classes.dag.DAG.ancestors_of

DAG.ancestors_of(nodes: Hashable) → Set[Hashable][source]

Return the ancestors of nodes.

Parameters:nodes – The node.

See also

descendants_of()

Returns:Return all nodes j such that there is a directed path from j to node.
Return type:Set[node]

Example

>>> import causaldag as cd
>>> g = cd.DAG(arcs={(1, 2), (2, 3)})
>>> g.ancestors_of(3)
{1, 2, 3}