Official implementation of the Greedy Ancestral Seach (GAS) algorithm from the paper 'On the Number of Conditional Independence Tests in Constraint-based Causal Discovery'.
Project description
Greedy Ancestral Search
Official implementation of the Greedy Ancestral Seach (GAS) algorithm from the paper "On the Number of Conditional Independence Tests in Constraint-based Causal Discovery".
Installation
To get started, you'll need Python 3.10 or newer.
You can install greedy-ancestral-search directly from PyPI:
pip install greedy-ancestral-search
Usage
Here is a simple example of using GAS with an oracle d-separation tester to learn the essential graph from a randomly generated directed acyclic graph.
import random
import networkx as nx
from greedy_ancestral_search import greedy_ancestral_search
# 1. Define the set of nodes.
number_of_nodes = 10
nodes = set(range(number_of_nodes))
# 2. Create a random ground-truth DAG to simulate data.
edge_probability = 0.5
G = nx.DiGraph()
G.add_nodes_from(nodes)
for u in nodes:
for v in nodes:
if u < v and random.random() < edge_probability:
G.add_edge(u, v)
# 3. Define a conditional independence tester function.
# This function queries the ground-truth graph for d-separation.
# In a real-world scenario, this would be a statistical test on data.
def oracle_tester(X, Y, condition_set):
"""Returns True if X and Y are d-separated by condition_set in G."""
return nx.is_d_separator(G, X, Y, condition_set)
# 4. Run the GAS algorithm.
# The function takes the set of nodes and the CI tester as input.
undirected_edges, directed_edges = greedy_ancestral_search(nodes, oracle_tester)
# The algorithm returns the edges of the learned essential graph.
print("Undirected Edges:", undirected_edges)
print("Directed Edges:", directed_edges)
Development
First, clone the repository:
git clone --recurse-submodules https://github.com/uhlerlab/greedy-ancestral-search.git
cd greedy-ancestral-search
Dependencies
This project uses uv for dependency management.
For more information, see the official documentation.
If you don't have uv, install it with the official script:
curl -LsSf https://astral.sh/uv/install.sh | sh
Then, install all development and runtime dependencies:
uv sync --all-groups
Tests
The test suite validates the algorithm's correctness by generating random DAGs and verifying that the algorithm output, using an oracle d-separation tester, corresponds to the correct essential graph.
Tests are located in the tests/ directory.
To run the standard test suite:
uv run pytest
To run the comprehensive test suite, which uses larger graphs and more iterations (as used in our CI workflow):
export CI=1 && uv run pytest
Benchmarks
The benchmarks/ directory contains scripts for performance evaluation.
To run a specific benchmark:
uv run benchmarks/<script>.py
Available scripts include:
benchmarks/airfoil.pybenchmarks/neighborhood-comparison.pybenchmarks/nodes-comparison.pybenchmarks/sample-size.pybenchmarks/scale-free-graphs.pybenchmarks/sergio.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file greedy_ancestral_search-0.1.0.tar.gz.
File metadata
- Download URL: greedy_ancestral_search-0.1.0.tar.gz
- Upload date:
- Size: 150.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70e0b2c1996abcbfa757de87924bd4888c4cc9f11a20da40abeaa6312fcb781d
|
|
| MD5 |
3bb4ff84aa64efb18917bc34f96e3716
|
|
| BLAKE2b-256 |
45521e2f2a4a90ce6be263cfa3827ef95651983129c3c78673b4e2092f35779e
|
Provenance
The following attestation bundles were made for greedy_ancestral_search-0.1.0.tar.gz:
Publisher:
release.yaml on uhlerlab/greedy-ancestral-search
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
greedy_ancestral_search-0.1.0.tar.gz -
Subject digest:
70e0b2c1996abcbfa757de87924bd4888c4cc9f11a20da40abeaa6312fcb781d - Sigstore transparency entry: 1154444835
- Sigstore integration time:
-
Permalink:
uhlerlab/greedy-ancestral-search@d8b54a369f8aa1bbb3059f09aba3d7a0cabfdb13 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/uhlerlab
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@d8b54a369f8aa1bbb3059f09aba3d7a0cabfdb13 -
Trigger Event:
release
-
Statement type:
File details
Details for the file greedy_ancestral_search-0.1.0-py3-none-any.whl.
File metadata
- Download URL: greedy_ancestral_search-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e631542be404150c4ee3c81f4df0823ab193d2944fc609bf32a721b189a01c4f
|
|
| MD5 |
32dd0108af3598348bd22664df4c65c9
|
|
| BLAKE2b-256 |
45d6c8f2aa25a71da2dcdf5fffce1a5ad1260af9d78f80ba278afe391a6a2dda
|
Provenance
The following attestation bundles were made for greedy_ancestral_search-0.1.0-py3-none-any.whl:
Publisher:
release.yaml on uhlerlab/greedy-ancestral-search
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
greedy_ancestral_search-0.1.0-py3-none-any.whl -
Subject digest:
e631542be404150c4ee3c81f4df0823ab193d2944fc609bf32a721b189a01c4f - Sigstore transparency entry: 1154444836
- Sigstore integration time:
-
Permalink:
uhlerlab/greedy-ancestral-search@d8b54a369f8aa1bbb3059f09aba3d7a0cabfdb13 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/uhlerlab
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@d8b54a369f8aa1bbb3059f09aba3d7a0cabfdb13 -
Trigger Event:
release
-
Statement type: