Skip to content

Latest commit

 

History

History
99 lines (62 loc) · 4.24 KB

File metadata and controls

99 lines (62 loc) · 4.24 KB

causaleffect

causaleffect is a Python library for computing conditional and non-conditional causal effects.

Installation

Version 0.1.0 requires Python 3.11 or newer:

python -m pip install "causaleffect==0.1.0"

For plotGraph, install the plotting extra:

python -m pip install "causaleffect[plot]==0.1.0"

For Python 3.7–3.10, install the 0.0.2 release instead:

python -m pip install "causaleffect==0.0.2"

Its source is preserved in the 0.0.2 Git tag. Python 3.11+ users can also pin that version.

For plotting with 0.0.2, install pycairo or cairocffi separately.

For local development and checks, see Contributing.

Usage

If we want to compute the causal effect P(y|do(X=x)) from the causal diagram shown below,

dag

we first create and display the graph:

import causaleffect

G = causaleffect.createGraph(["X<->Y", "Z->Y", "X->Z", "W->X", "W->Z"])
causaleffect.plotGraph(G)

which renders the following image

dag

Then we can compute the causal effect by executing:

P = causaleffect.ID({"Y"}, {"X"}, G)
print(P.printLatex())

The code above computes the causal effect, and returns a string encoding the distribution in LaTeX notation:

\sum_{w, z}P(w)P(z|w, x)\left(\sum_{x}P(x|w)P(y|w, x, z)\right)

This string, in LaTeX, is

effect

If the effect is not identifiable, ID returns a Probability with identifiable == False. Its hedge contains the two C-forest graphs; use causaleffect.printGraph(P.hedge[0]) and causaleffect.printGraph(P.hedge[1]) to inspect them.

Examples

Start with the quickstart script for identifiable, conditional, and confounded effects.

Other examples from the dissertation:

Figure number Example file
Figure 3.5 (a) example_1.py
Figure 3.6 (a) example_2.py
Figure 3.6 (b) example_3.py
Figure 3.10 example_4.py
Figure 3.12 example_5.py
Figure 3.13 example_6.py
Figure 3.15 (a) example_7.py
Figure 3.15 (b) example_8.py
Figure 3.16 example_9.py

Documentation

Read the API guide or the generated API reference. The dissertation explains the algorithms.

Run the benchmark with python benchmarks/benchmark.py. Results are local timing measurements, not performance targets.

See the changelog.

Citation

If you use causaleffect in research, please cite:

Pedemonte, M., Vitrià, J., & Parafita, Á. (2021). Algorithmic Causal Effect Identification with causaleffect. arXiv. https://doi.org/10.48550/arXiv.2107.04632