Quickstart
Minimal discovery loop
The public API centers on a single tick function and an optional scan
driver. The package exports the JIT-compiled JAX step as
causal_automata.step(), the multi-tick causal_automata.run(),
and the NumPy prototype as causal_automata.numpy_step().
import numpy as np
from causal_automata import (
run,
step,
warmup,
default_conditioning_k,
__version__,
)
from causal_automata.bayesian_synth import prepare_synthetic_bundle
print(__version__, warmup()) # e.g. 0.3.6 + device string
n = 100
bundle = prepare_synthetic_bundle(n=n, seed=0)
A, E, Cov = bundle.A_init, bundle.E_init, bundle.Cov
k = default_conditioning_k(n) # 3 if N≤50, 5 if N>50 (Python int)
# Preferred: jit-scanned horizon (ticks and k are static args)
A, E = run(A, E, Cov, ticks=100, k=k, threshold_birth=0.10)
# Equivalent explicit loop:
# for _ in range(100):
# A, E = step(A, E, Cov, k=k, threshold_birth=0.10)
print("Predicted edges:", int((A > 0).sum()))
ticks and k must be ordinary Python integers. Passing traced JAX
scalars raises ConcretizationTypeError — see JAX static arguments (ticks and k) for
functools.partial patterns.
Maximum Accuracy Mode (2-hop gravity)
Pass multihop=True (CLI: --multihop) so elevation drift also sees
neighbors two hops away via \(A@A\):
A, E = run(
A, E, Cov,
ticks=100,
k=k,
threshold_birth=0.10,
multihop=True,
hop_discount=1.0,
)
On the default N=100 SEM this lifts Directed F1 from 0.619 (1-hop) to 0.696 with flat wall time. See Benchmarks.
State variables
Symbol |
Meaning |
|---|---|
|
Adjacency \((N, N)\). Binary by default; with
|
|
Node elevations \((N,)\) in \([0, 1]\). Arrows may only point downhill (\(E_{\mathrm{parent}} > E_{\mathrm{child}}\)), which enforces acyclicity. |
|
Fixed empirical covariance of continuous observations. |
Each call to step applies, in order:
Gravity — raw downhill projection, then local-margin elevation drift (roots sit just above children, leaves just below parents; isolates hold
E). Optionalmultihop=Truealso pulls toward 2-hop means from \(A@A\). Final projection uses \(U=\max(A,A^\top)\) so mid-tick elevation flips reverse edges.V-well — statistical explaining-away colliders sink in
E(parent lift + non-collider anti-sink; 2-node Sepset rejects backdoor forks). Edges re-orient via later birth / downhill.Death / birth — exact closed-form
s=1screens over all skeleton neighbors, then PC-consistent endpoint-locals≥2combos (Berkson colliders excluded fromZ). Birth also requires \(|R|\ge\tau_{\mathrm{death}}\) and orients with a deterministic elevation tie-break.
NumPy vs JAX
from causal_automata.bayesian import step as numpy_step
from causal_automata.jax_core import step as jax_step, run
A1, E1 = numpy_step(A, E, Cov, threshold_birth=0.10, k=3)
A2, E2 = jax_step(A, E, Cov, threshold_birth=0.10, k=3)
A3, E3 = run(A, E, Cov, ticks=100, k=3, threshold_birth=0.10)
Both backends share the same core physics (parity-tested on the
Phase-2 N=10 SEM). Prefer JAX when N is large or a GPU / MPS device
is available; prefer NumPy for debugging and environments without JAX.
Upgrade flags (multihop, fuzzy, anneal) are JAX-only.
Synthetic end-to-end harness
python -m causal_automata.bayesian_synth --n 10
python -m causal_automata.bayesian_synth --n 50 --backend jax
python -m causal_automata.bayesian_synth --n 100 --backend jax
# Benchmark Maximum Accuracy Mode
python -m causal_automata.benchmark --n 100 --ca-only --k 5 --multihop
See Command-line tools for the full flag list and Benchmarks for comparison against gCastle PC and GOLEM.