Causal Discovery
Causal discovery recovers cause-and-effect graphs from data. How the PC algorithm and its successors work, what they assume, and a runnable example.
Causal discovery is the task of inferring which variables cause which from data, producing a directed graph in which an arrow from X to Y means X directly influences Y. Standard machine learning learns associations that are good enough for predictive modeling. Causal discovery asks which of those associations would hold up under an intervention, such as changing a machine setting or a traffic-signal schedule. Its output is a set of candidate causal structures, often with some edges left undirected, that domain experts and experiments then refine.
What Makes Causal Structure Learnable#
Causal graphs are usually directed acyclic graphs (DAGs), the same structure a Bayesian network uses, read causally: each arrow is a direct effect. Discovery algorithms rely on three standard assumptions. Under the causal Markov condition, once a variable's direct causes are known, it is independent of every variable that is not one of its effects. Faithfulness says that every independence in the data comes from the graph structure and not from effects that happen to cancel out. Causal sufficiency says that no unmeasured variable causes two measured ones.
Even with all three assumptions, observational data cannot always reveal edge direction. The chain X → Y → Z, the reversed chain X ← Y ← Z, and the fork X ← Y → Z all imply the same independence pattern, namely that X and Z become independent once Y is known, so no amount of observational data separates them. The collider X → Y ← Z is different. X and Z are independent on their own but become dependent once Y is known, a signature that pins down both arrows.
Algorithms therefore return a Markov equivalence class: a partly directed graph whose oriented edges are certain and whose undirected edges could point either way. The same signature explains a classic source of dataset bias: filtering or adjusting for a collider creates a dependence between its causes that does not exist in the full population.
Discovery Algorithms#
Three families cover most methods. Constraint-based algorithms such as PC, named after Peter Spirtes and Clark Glymour, who published it in 1991, start from a fully connected undirected graph, delete edges between variables that test as conditionally independent, and then orient colliders. FCI extends this approach to settings with hidden confounders. Score-based algorithms such as greedy equivalence search (GES) search over graphs for the best score, for example the Bayesian information criterion, and NOTEARS recasts acyclicity as a smooth constraint so the search can run as continuous optimization with gradient descent. Functional methods such as LiNGAM assume linear relationships with non-Gaussian noise, which makes every edge direction identifiable, even between just two variables.
Discovery libraries also accept time ordering, physical constraints, and expert knowledge as background rules that forbid or require specific edges, which shrinks the search and orients edges the data alone cannot. The open-source causal-learn library implements all three families. This example generates data from a known collider and recovers it with PC:
import numpy as np
from causallearn.search.ConstraintBased.PC import pc
rng = np.random.default_rng(0)
n = 5000
# Ground truth: rain and a stadium event both cause congestion
rain = rng.normal(size=n)
event = rng.normal(size=n)
congestion = rain + event + rng.normal(scale=0.5, size=n)
# PC tests conditional independence to recover the graph from data alone
data = np.column_stack([rain, event, congestion])
result = pc(data, alpha=0.05, node_names=["rain", "event", "congestion"], show_progress=False)
print(result.G)The output lists two directed edges, rain --> congestion and event --> congestion. PC orients both because rain and event are independent but become dependent once congestion is known. Had the truth been a chain from rain to congestion to delays, the edges would come back undirected.
Where Causal Discovery Is Used#
Biology supplied an early landmark. In 2005, Karen Sachs and colleagues learned a protein-signaling network among 11 proteins and phospholipids from single-cell measurements, recovering most of the known connections, and the authors confirmed a newly predicted link in follow-up lab experiments. In climate science, time-series methods such as PCMCI, developed by Jakob Runge and implemented in the Tigramite package, find causal links among climate variables while handling lags and autocorrelation, a natural fit for time series analysis. The PyWhy ecosystem pairs discovery tools with DoWhy for the next step, estimating how large an effect is once the graph is fixed.
Computer vision can supply the variables. Object counting with Ultralytics YOLO26 tallies the vehicles and pedestrians that cross a line or region in traffic footage, and counts logged per time interval can be joined with weather, event schedules, and signal timing before a discovery algorithm runs.
Causal Discovery vs. Related Terms#
- Causal representation learning: Learns the causal variables themselves from raw inputs such as pixels, along with the graph among them. Causal discovery starts from variables that are already measured.
- Explainable AI (XAI): Explains which inputs drove a model's prediction, without claiming that changing an input would change the outcome in the world.
- Feature engineering: Selects and builds inputs that improve prediction, including variables that are only correlated with the target. A causal graph identifies the variables whose change would move the target.










