Examples#
New to Andrey? Work through the notebooks in this order; each part adds one step to the last.
Part 1. Concepts: the model behind every method, what the data can identify, and what each kind of graph claims.
Part 2. Getting started and the quick start: install Andrey, learn a graph from the Sachs protein measurements, and read the result.
Part 3. Visualize a causal graph: draw a result and read the mark at each end of an edge.
Part 4. Constraint-based discovery: learn a graph from conditional-independence tests, and allow hidden common causes with FCI.
Part 5. Score-based search and permutation-based search: search for the graph with the best score, over graphs or over orderings of the variables.
Part 6. Background knowledge: pass what you already know, such as tiers in time, to narrow the search.
Part 7. Linear non-Gaussian models: orient every edge when the noise is non-Gaussian.
Part 8. Pairs that share a hidden cause and causal order with hidden causes: find the variables a hidden cause joins.
Part 9. Nonlinear additive-noise models and pairwise direction: orient edges when each effect is a nonlinear function of its causes.
Part 10. Continuous optimization: fit a weighted DAG by gradient descent instead of a search over graphs.
Part 11. Time series: find the causes in data measured over time.
Part 12. Bootstrap: refit on resamples of the rows to see how stable each edge is.
Part 13. Markov check: test whether the data contradict the graph you learned.
Part 14. Missing values: fit data whose gaps depend on other variables, and correct for them.
Speed on your machine times PC on your own hardware at any point.
Each notebook runs one method or task, on your own machine or in Colab; each has Open in Colab
and Download this notebook links. The interactive demos run in your
browser instead. From a source checkout, start Jupyter with uv run --with jupyter jupyter lab. A
notebook that needs another package installs it in a cell with uv pip install.
To run one in Colab, choose Open in Colab, select a CPU runtime, and run the setup cell before the example. The setup cell installs Andrey in the Colab runtime only; the speed notebook labels that runtime in its output.
Quick start#
Load the Sachs protein measurements, fit PC, GES, FCI, and DirectLiNGAM, read each result, and draw each graph.
Notebook · Colab
Methods#
PC’s CPDAG and FCI’s and GFCI’s PAGs from conditional-independence tests; IAMB, Inter-IAMB, and MMPC, which join each variable’s local structure into a graph; CD-NOD and FCI-JCI on data from several domains; and ICP’s parents of one variable from several environments.
Notebook · Colab
XGES, hill climbing, tabu search, and exact search look for the graph with the best score, by default the extended BIC; AGES directs more edges than GES when some effects are weak; MMHC and RSMAX2 restrict the search with tests first; GIES also learns from interventions, and GnIES from environments whose changes it is not told.
Notebook · Colab
CALM learns a weighted DAG by gradient descent on a penalized likelihood, on torch; NOTEARS and
DAGMA by least squares with an l1 penalty, where the result depends on the units of the columns.
Notebook · Colab
BOSS and GRaSP search over orderings of the variables for the best-scoring graph, and BOSS-FCI and GRaSP-FCI start from that graph and allow hidden common causes; IGSP searches orderings too, on interventional settings, one per environment, whose changed variables it is told, and UT-IGSP on settings whose changed variables it is told in part or not at all.
Notebook · Colab
DirectLiNGAM and ICA-LiNGAM orient every edge when the noise is non-Gaussian; MultiGroupDirectLiNGAM fits several datasets, and GIN finds latent variables.
Notebook · Colab
CAM, RESIT, SCORE, and NoGAM learn a DAG, with every edge oriented, when each variable is a nonlinear function of its parents plus independent noise; CAM-UV allows hidden causes and marks the pairs they join.
Notebook · Colab
PCMCI, PCMCI+, LPCMCI, Granger, VARMA-LiNGAM, DYNOTEARS, Longitudinal LiNGAM, and J-PCMCI+ on data over time.
Notebook · Colab
RCD finds the direct causes and marks the pairs that share a hidden cause.
Notebook · Colab
BottomUpParceLiNGAM orders the variables and leaves those a hidden cause confounds unordered.
Notebook · Colab
ANM, PNL, and LOCI test which of two variables causes the other.
Notebook · Colab
Advanced#
Refit a method on resamples of the rows: edge frequencies, the averaged graph, and which edges to trust.
Notebook · Colab
Test the independences a graph implies against held-out rows: a true graph passes, a damaged one is rejected, and the sparsest passing graph is not always the most accurate.
Notebook · Colab
Pass what you already know to a search: tiers in time, and required or forbidden edges.
Notebook · Colab
Remove values so that whether one is missing depends on another variable, then fit PC with its
default handling and with missing="mvpc" and GES with missing="em", and count each one’s errors.
Notebook · Colab
Interactive demos#
The demos run in your browser, with nothing to install. Step through PC and Meek’s rules, explore d-separation, or compare methods on one dataset.
The true graph, Andrey’s, and causal-learn’s, side by side and scored.
In your browser
Every independence test, collider, and Meek rule PC recorded, beside its pseudocode.
In your browser
Each orientation rule, one step at a time, from the orientation engine.
In your browser
Choose two variables and a conditioning set; see which paths stay open.
In your browser
Misc#
Draw a recovered graph as a self-contained SVG.
Notebook · Colab
Time PC in Andrey and causal-learn on your own hardware.
Notebook · Colab