Skip to content

chc.discovery

Stability tier: experimental.

Lagged causal-parent discovery for the dynamics -- a minimal, control-focused grow-shrink selection (not PC, not PCMCI).

For each next-state component x^j_t this finds which lagged variables {x^i_{t-tau}, u^k_{t-tau}} are its direct parents with the MCI-calibrated partial-correlation test (chc.independence.partial_corr_test), in two phases (the grow-shrink of Margaritis and Thrun, NIPS 1999; the IAMB of Tsamardinos, Aliferis and Statnikov, FLAIRS 2003). Grow: add the candidate with the strongest association given the already-selected parents, until none is significant. Conditioning on the selected parents (dominant autoregressive lags are picked first) removes indirect-path false positives -- x^i_{t-2} -> x^i_{t-1} -> x^j_t makes x^i_{t-2} look like a parent to a naive test, but not once x^i_{t-1} is conditioned on. Shrink: drop, one at a time and weakest first, every selected parent that is not significant given the others. A candidate picked early as a proxy for a parent not yet selected -- a child's lag that tracks its parent's -- is read again once that parent is in, and leaves; without this phase it stayed for good. The strongest candidate is the one with the largest partial correlation, not the least p-value: on a long series both p-values underflow to 0, and the tie fell to the column order.

alpha is each test's level, with no correction for multiplicity: the step that stops tests every candidate left at alpha, so a target with m of them gains a false parent with probability up to about m * alpha. For a family-wise level, pass alpha over the candidates, alpha / ((d_state + d_control) * max_lag).

Each kept edge carries a p-value (LaggedGraph.state_p_values): the partial-correlation test of the parent with its target given every other kept parent of that target, the shrink phase's last pass, which kept it (one kept parent is tested given none). The test ran once, on the lag-aligned design, so the p-value belongs to the time-homogeneous edge, not to a slice. It is nominal: the parents were chosen by these same data, and a p-value read after a data-driven selection is not uniform under the null. It is not a selective p-value, valid given the selection (Berk, Brown, Buja, Zhang and Zhao, "Valid post-selection inference", Annals of Statistics 2013), and it is not corrected for the multiplicity above. On a long series it reads 0.0 where the t's tail underflows, and two such edges are no longer ranked by it.

Each test is the partial correlation's exact t with n - k - 2 degrees of freedom, n the lag-aligned rows and k the parents conditioned on, so a target keeps at most n - 2 parents: the selection stops growing where one more would leave a test no degree of freedom.

Deliberately minimal: lag-capped, next-state targets only, no contemporaneous-link search. The heavy algorithms (PCMCI+/LPCMCI) stay a lazy, opt-in tigramite adapter; the point here is to feed GraphResidual's adjacency and the effect estimators' adjustment set from data, not by hand.

LaggedGraph dataclass

Discovered lagged parents. state_parents[j, i, tau-1] = x^i_{t-tau} -> x^j_t.

state_p_values and control_p_values hold, at each edge, the p-value of the test that kept it (see the module docstring for which test, on which conditioning set, and why it is nominal), and nan where there is no edge; discover_lagged_parents fills them, and TigramiteDiscovery and a graph built by hand leave them None. They are float64 numpy arrays, read-only, and not jax ones: without jax_enable_x64 a jax array rounds to float32, which reads a p-value of 1e-300 as 0.0.

Raises:

Type Description
ValueError

on p-values of another shape than their parents, not nan exactly where there is no edge, outside [0, 1] at an edge, or given for one kind of parent and not the other.

adjacency()

State-to-state coupling collapsed over lags -- a GraphResidual adjacency (0/1).

node_adjacency(node_dim)

Collapse component parents to a node-level adjacency (nodes = blocks of node_dim).

adjacency[j, i] = 1 iff any component of node i is a discovered lagged parent of any component of node j -- the adjacency GraphResidual consumes when the flat state is n_nodes blocks of node_dim.

edges()

Every discovered edge as (target, source, lag, kind) (kind state/control).

causal_graph(state_names, control_names=None)

The edges as a CausalGraph unrolled over max_lag, each edge discovered by partial_corr_test with its p-value.

The graph is CausalGraph.unrolled of the (source, target, lag) triples over lags=max_lag, and is equal to it. Every unrolled copy of an edge carries the edge's p-value: the test ran once, on the lag-aligned design, and the edge holds at every slice. chc.decision.prescribe takes the graph as adjustment=, and its record writes each edge's source, test and p-value.

Parameters:

Name Type Description Default
state_names Sequence[str]

one distinct name per state component, in the series' column order.

required
control_names Sequence[str] | None

one per control column; None or empty for a graph without controls.

None

Raises:

Type Description
ValueError

on a count of names other than the components', a name given twice, or a graph without p-values (built by hand or by TigramiteDiscovery): a discovered edge carries its test's p-value.

TigramiteDiscovery dataclass

Adapter over tigramite's PCMCI (lazy import; requires tigramite installed).

A drop-in for discover_lagged_parents returning the same LaggedGraph, but with PCMCI + a tigramite conditional-independence test doing the work. Reach for it when the native minimal grow-shrink is not enough -- dense coupling, or nonlinear dependencies via a nonparametric test (cond_ind_test=GPDC()/CMIknn()). tigramite is GPL-3.0, so it stays bring-your-own-env and is never a chc dependency.

The graph holds no p-values (state_p_values is None), so LaggedGraph.causal_graph refuses it: PCMCI's own p-value matrix is not read into it, since tigramite is not installed where this library is tested.

discover(series, controls=None, max_lag=3)

Run PCMCI on [series, controls] and return the state components' lagged parents.

discover_lagged_parents(series, controls=None, max_lag=3, alpha=0.01, max_parents=None)

Discover each state component's lagged parents from a trajectory; see the module docstring.

series is (T, d_state); controls an optional (T, d_control). max_parents caps the forward selection per target (default: the candidate count). Returns a LaggedGraph.

Each edge's p-value is the shrink's last test of it, given the target's other kept parents (state_p_values, control_p_values); no test runs for it beyond the selection's own. It is nominal, not selective, and 0.0 where the t's tail underflows (see the module docstring). A target keeps at most T - max_lag - 2 parents, each test's degrees of freedom at least 1. Up to 1.1.0 the p-values were Fisher's z, which differ from the exact t's at every T, and by most where T - max_lag is small; where a test had no degree of freedom left, its z was floored at one and read the collinear residuals' correlation of 1 as a parent.

alpha is each test's level, not the graph's: a candidate that is not a parent enters at about that rate, so a graph of many candidates holds a false edge far more often; on three states and one control over three lags, 31 of whose 36 candidate edges are not parents, about 1 % of those 31 entered at alpha=0.01, and 26 % of 500 graphs of 300 steps and 27 % of 500 of 1000 steps held at least one false edge (scripts/bench_discovery_false_edges.py: 0.96 % and 0.94 % entered, SE 0.08 points, and 26.2 % and 26.8 % of the graphs, SE 2.0 points). Fisher's z, up to 1.1.0, read 0.97 % and 0.95 %, and 26.4 % and 27.0 %, on the same series.

Raises:

Type Description
ValueError

where series is not (T, d_state), a value is not finite, or T - max_lag is below 3, which leaves a test of one candidate no degree of freedom.