antecedent.state

Incremental causal state helpers.

1"""Incremental causal state helpers."""
2
3from __future__ import annotations
4
5from ._native import CausalState, antecedent_state_append
6
7__all__ = ["CausalState", "antecedent_state_append"]
class CausalState:

Incremental causal analysis state (versioned events, no auto-rerun).

def stale_query_count(self, /):

Number of registered queries whose cached results are currently stale.

def stale_queries(self, /):

Raw ids of registered queries that are currently stale.

def batch_ids(self, /):

Batch ids currently retained in Python (catalog order).

def append_data(self, /, names, columns):

Append a tabular batch and retain its float64 columns.

Returns the new state version.

def replace_data(self, /, names=None, columns=None):

Replace all retained batches; optionally load one new batch.

Returns the new state version.

def get_batch(self, /, batch_id):

Fetch retained columns for batch_id as (names, list[ndarray]).

def batch_nrows(self, /, batch_id):

Row count for a retained batch.

def add_graph_evidence(self, /, evidence_id, fingerprint, bytes):

Add opaque graph evidence; returns new version.

def graph_evidence(self, /):

List (id, fingerprint, bytes) graph-evidence records.

def add_constraint(self, /, constraint_id, fingerprint):

Add a graph constraint; returns new version.

def remove_constraint(self, /, constraint_id):

Remove a graph constraint by id; returns new version.

def constraints(self, /):

List active constraint (id, fingerprint) pairs.

def update_assumption(self, /, kind):

Update / insert a named assumption (default provenance: stated / identification / assumed).

def register_average_effect(self, /, treatment, outcome):

Register a binary average-effect query; returns (version, query_id).

def record_intervention(self, /, intervention_id, fingerprint):

Record an opaque intervention; returns new version.

def refresh_results(self, /, entries):

Mark queries fresh at fingerprints: list of (query_id, fingerprint, bytes).

def ols_ensure(self, /, key, ncols):

Ensure an OLS sufficient-stat slot exists with ncols predictors.

def ols_append_row(self, /, key, row, y):

Append one OLS design row / response under key.

def ols_get(self, /, key):

Return OLS summary dict for key: {n, ncols, xtx, xty, yty}.

def cov_ensure(self, /, key, dim):

Ensure a streaming-covariance slot of dimension dim.

def cov_update(self, /, key, row):

Observe one row into streaming covariance key.

def cov_get(self, /, key):

Return streaming-cov summary {n, dim, mean, m2}.

def particle_filter_init( self, /, key, n_particles, *, a=0.9, process_std=0.3, obs_std=0.5, seed=1):

Initialize a particle filter under key.

def particle_filter_step(self, /, key, y):

Step particle filter key with observation y.

def particle_filter_get(self, /, key):

Particle-filter summary {n_obs, n_particles, particles, log_weights}.

version

Monotonic state version (starts at 0; bumps on each applied event).

data_version

Current data-catalog version.

def antecedent_state_append(n_appends=2, cache_bytes=Ellipsis):

Smoke / test helper: append synthetic batches and report (version, stale_count).