graph.anteriors

pyagrum.graph.anteriors(g, nodes)

The anterior nodes of nodes (family AE, or a marked graph): the nodes with a path made of arcs (followed in their direction) and edges to one of them; in a marked graph, of edges -> (pointing towards them) and -.

As for ancestors(), a node of nodes belongs to the result only if it has such a path to another one or lies on such a cycle; going back and forth through the same edge is not a cycle. The set ant(X) of Richardson and Spirtes (2002), which contains X, is anteriors(g, X) | X.

Parameters:
  • g (MixedGraph | PDAG | ChainGraph | CPDAG | MPDAG | EssentialGraph | MarkedGraph | PAG | MAG) – the graph

  • nodes (int | str | Iterable[int | str]) – a node or several nodes, by id or by name

Returns:

the anterior nodes

Return type:

set[int]

References

T. Richardson, P. Spirtes. Ancestral graph Markov models. The Annals of Statistics 30(4):962-1030, 2002.

Example

import pyagrum as gum
import pyagrum.graph as gg

g = gum.fastMarkedGraph("A-B->C<->D")
gg.anteriors(g, "C")
# {0, 1}
gg.ancestors(g, "C")
# {1}
gg.anteriors(gum.fastPDAG("A-B->C"), "A")  # A-B-A is not a cycle
# {1}
gg.anteriors(gum.fastMixedGraph("A-B-C-A"), "A")  # a cycle
# {0, 1, 2}