3. Causal Graph Algorithms in PyWhy#

Pywhy-graphs provides data structures and methods for storing causal graphs, which are documented in Causal Graphs in PyWhy. We also provide a submodule for common graph algorithms in the form of functions that take a mixed-edge graph as input.

3.1. Core Algorithms#

is_valid_mec_graph(G[, on_error])

Check G is a valid PAG.

possible_ancestors(G, source)

Possible ancestors of a source node.

possible_descendants(G, source)

Possible descendants of a source node.

discriminating_path(graph, u, a, c[, ...])

Find the discriminating path for <..., a, u, c>.

is_definite_noncollider(G, node1, node2, node3)

Check if <node1, node2, node3> path forms a definite non-collider.

valid_pag(G)

Check if the provided PAG is valid or not.

mag_to_pag(G)

Converts the provided mag into a pag using the FCI algorithm.

pag_to_mag(graph)

Sample a MAG from a PAG using Zhang's algorithm.

check_pag_definition(G[, L, S])

Checks if the provided graph is a valid Partial Ancestral Graph (PAG).

bidirected_to_unobserved_confounder(G[, ...])

Convert all bidirected edges to unobserved confounders.

m_separated(G, x, y, z[, ...])

Check m-separation among 'x' and 'y' given 'z' in mixed-edge causal graph G, which may contain directed, bidirected, and undirected edges.

is_minimal_m_separator(G, x, y, z[, i, r, ...])

Check if a set 'z' is a i-minimal m-separator between 'x' and 'y'.

minimal_m_separator(G, x, y[, i, r, ...])

Find a i-minimal m-separating set 'z' between 'x' and 'y' in mixed-edge causal graph G.

3.2. Algorithms for Markov Equivalence Classes#

pds(graph, node_x[, node_y, max_path_length])

Find all PDS sets between node_x and node_y.

pds_path(graph, node_x, node_y[, ...])

Compute the possibly-d-separating set path.

uncovered_pd_path(graph, u, c[, ...])

Compute uncovered potentially directed (pd) paths from u to c.

3.3. Algorithms for Time-Series Graphs#

pds_t(graph, node_x, node_y[, max_path_length])

Compute the possibly-d-separating set over time.

pds_t_path(graph, node_x, node_y[, ...])

Compute the possibly-d-separating path set over time.

3.4. Algorithms for handling acyclicity#

acyclification(G[, directed_edge_type, ...])

Acyclify a cyclic graph.

4. Semi-directed (possibly-directed) Paths#

all_semi_directed_paths(G, source, target[, ...])

Generate all semi-directed paths from source to target in G.

is_semi_directed_path(G, nodes)

Returns True if and only if nodes form a semi-directed path in G.