chc.dynamics_id¶
Stability tier: stable.
Causal identification of the residual's control channel, not just of a scalar effect.
chc.train fits a residual by prediction error. Under a confounded logging policy that is the
wrong object: if the historical action was chosen from a covariate that also drives the state,
then d(dx/dt)/du fitted on (x, u, x_next) is the observational response, and a
controller that optimises against it moves the state the wrong way. That is the same failure the
scalar headline benchmark shows -- and until now nothing protected the residual from it.
This module closes that gap with Robinson partialling-out lifted from a scalar effect to a
state-dependent matrix. With nuisances g(x,z) = E[y | x,z] and m(x,z) = E[u | x,z], where
y = (x_next - x)/dt - f_known(t, x, u) is the part the residual must explain::
y - g(x,z) = B_θ(x) (u - m(x,z)) + eps, E[eps | x, z, u - m] = 0
so the estimator regresses the residualised state rate on the residualised action, with
K-fold cross-fitting of both nuisances. Neyman orthogonality is what buys the guarantee: the
channel error is second order in nuisance error, which is exactly the order transfer
p -> 2p of chc.research.regret.composition_transfer_certificate and the per-channel
debiasing by cross-fit Robinson DML of chc.research.regret.multichannel_control_certificate.
This module is those results' missing consumer, not a new one.
HONEST SCOPE, four limits worth stating before the code:
- Only the channel
B_θis interventional.a_θis fitted on the remainder and therefore absorbs whatever the omitted confounder contributes to the drift in-sample, so it is an observational-conditional drift. Planning is unbiased in the direction the optimiser moves; the predicted trajectory level still shifts if the confounder's distribution does. On real data this bites harder than it sounds: a confounder that trends with the state gets charged to positive feedback inx, so the fitted drift can come back unstable even where the channel is clean -- and an MPC uses the drift too. Check the drift's spectrum, and give measured exogenous drivers a place in the drift as regressors instead of leaving them only inadjust_for. The adjustment set joins the drift regression under either integrator, soa_θis conditional on it, at its mean on the log; underintegrator="rk4"a push left out would reach the channel as well, since RK4 carries the drift into it. - The residual must be control-affine (
chc.residual.ControlAffineResidual). A generalr_θ(x, u)has no partialling-out moment and gets no guarantee here. - With no adjustment set and no instrument nothing in the log identifies the channel, unless the
caller knows the actions are unconfounded given the state (
unconfounded=True), and an instrument identifies it only along the directions it moves the action. The estimator reportsidentified=Falsein both cases rather than returning a confident wrong answer -- that case belongs tochc.research.sensitivity, which prices the radius instead of pretending it away. - The premise is Markov: given
x,zandu, a transition's noise does not depend on the past. Where the noise persists within a unit and a lever persists too, the state is a common effect of the past lever and the past noise, soE[eps | x, z, u - m]is not 0 and the channel is biased by an amountchannel_errordoes not cover.persistence_checkreads the noise's persistence off the moment's residual; adjusting for the state, the levers andza period earlier removes the bias where the noise is AR(1) (ADR 0064).
Integrator = Literal['euler', 'rk4']
module-attribute
¶
Which one-step map the fit is asked to be consistent with. See fit_causal_residual.
RegionForm = Literal['ridge', 'grid']
module-attribute
¶
channel_region's radius. ridge: Abbasi-Yadkori, Pal and Szepesvari's (2011), its
log-determinant read against the fit's own ridge. grid: Simpson, Baumgartner, Koehler and
Diehl's (2026, Theorem 2), the least over a fixed grid of prior matrices, the prior's term inside
the root. Experimental.
ConfoundedControlAffineSystem
dataclass
¶
Euler-logged dx/dt = f_known(x,u) + A x + B_true u + C z under u = K z + eta.
The vector-state analogue of chc.causal.ConfoundedLinearSystem and the DGP
fit_causal_residual is scored against. z is the confounder: it drives the logged
action through K and the state rate through C, so with z withheld the response of
the rate to the action is B_true + C sigma_z^2 K^T / var(u) rather than B_true, where
var(u) = K K^T sigma_z^2 + G G^T + sigma_eta^2 collects every source of action variance.
A scalar channel with B=1, C=2, K=-1.5, sigma_z=1, sigma_eta=0.5 and no instrument
gives 1 - 2*1.5/2.5 = -0.2: the sign flip of the headline benchmark, reproduced per
channel. Turning the instrument on adds G G^T to that denominator and dilutes the bias
toward zero -- the exogenous shifter makes the log more informative, so the observational fit
looks less wrong while being no more identified. Worth knowing before reading a number off it.
The Euler discretisation is deliberately the one fit_causal_residual inverts, so a
failing recovery test means the identification is wrong, not that the integrator disagreed.
sample(n, key, known)
¶
Draw n transitions: x (n,d_x), z, u, x_next, w (instrument).
CausalDynamicsFit
dataclass
¶
A fitted causal residual next to what is and is not known about it.
identified is the load-bearing field: False means nothing the fit was given pins the
channel down from the log -- no adjustment set and no instrument, an instrument whose moment
falls short of rank (instrument_rank), or a log that moves no direction of the channel
(unmoved) -- and the residual is then the observational fit, kept only so the caller can
compare.
error_cosines
property
¶
nu, the cosines of the periods the channel's error was read with where the fit was
given periods, counted over the distinct periods, and the degrees of freedom of the
t a test read off it is sized against; None where it was given none.
OmittedConfounderBound
dataclass
¶
How far a confounder the adjustment set left out could move a linear functional of the
channel, and how strong it would have to be to move it to null. Experimental.
bias_scale is identified; strength is the analyst's, as Gamma is
(docs/concepts/gamma.md), in partial R^2s rather than odds.
ChannelRegion
dataclass
¶
A region that holds the fitted channel's coefficients at a stated level, from one log.
Experimental: it may change or be withdrawn in any release. State s's coefficients
c_s (the channel's row s, raveled lever by lever, each lever's features in turn) lie in
{c : ||c_hat_s - c||_V <= radius[s]} for every state at once with probability at least
level. V = D'D + ridge P is the matrix the fit's least squares solved, D the
channel's design on the action residuals. channel_region says where it holds, and
form which radius it reads (RegionForm).
contains(channel)
¶
Whether every state's row of channel, shaped as channel, lies in its
ellipsoid.
operator_radius(state)
¶
A bound, at the region's level, on ||B_hat(x) - B(x)||_2 at the state x: the
largest move of the rate that the channel's error makes per unit action norm. It holds at
every state at once, since each is read off the same ellipsoids.
rate_error(states, reach)
¶
A bound, at the region's level, on ||(B_hat(x) - B(x)) a|| over the (N, n)
states and every action deviation a with |a_j| <= reach[j]: the rate error
that the plan's tube reads as a standard error at its studentised quantile
(chc.decision's _model_error and _field_scale), read here at a level. The
largest of a convex form over a box is at a corner, so it reads the 2^m corners.
stability_level(rho, state)
¶
The largest level at which operator_radius at state is within rho: the
probability the region gives that the channel's error there is at most rho, 0 where
no level reaches it.
A certainty-equivalent gain whose stability holds within a radius rho of the channel
(chc.research.regret.ce_explicit_constant_certificate) then stabilises the plant with at
least this probability. That certificate's rho is the true plant's, and its channel is
the discrete step's, dt times this one under Euler: pass its radius over dt. Read at
the estimate, rho is the estimate's, which the region does not check.
Solves sum_s (R_s A + b_s)^2 = (rho / g)^2 for A, g the operator radius per
unit of the radii, and A^2 = 2 log(n / delta) + log_det_ratio for delta
(validation/tube_levels.mac).
PersistenceCheck
dataclass
¶
Whether a fit's transition noise persists within units, read off its channel moment's
residual by persistence_check. Experimental.
The fit's premise is Markov: given the state, the levers and the adjustment set, a transition's
noise does not depend on the past. Where the noise persists within a unit and a lever persists
too, the state is a common effect of the past lever and the past noise, so given the state this
period's lever and noise move together, and the channel is biased by an amount its error does
not cover (ADR 0064). And a fit given neither clusters nor periods reads the error of
its drift and of the adjustment set's push at its mean on the log, which the tube carries,
from its rows taken as independent: where the push persists as AR(0.8), that read of the
mean's variance is 1/8.8 of the mean's own at 200 rows, 1/9 on a long log (ADR 0133).
Given either, both are read from the
clusters' sums or the periods' cosines, as the channel's error is.
InterferenceCheck
dataclass
¶
Whether a fit's transitions move with their neighbours' levers, read off its channel
moment's residual by interference_check. Experimental.
The fit's premise is that a unit's transition depends on its own levers alone. Where a unit's levers move its neighbours' states as well, drivers or customers moving between zones, the residual carries the neighbours' push, and the channel is the effect of moving one unit with its neighbours held, not of a plan that moves them all (ADR 0113).
LagCheck
dataclass
¶
Whether a fit's moment residual moves with its levers some periods back, read by
lag_check. Experimental.
The fit's premise is that a period's lever moves the state over that period alone. Where the plant takes the lever some periods late, a dead time, the residual carries the late levers' push, and the channel reads the share of it the current lever is correlated with.
ClosedLoopAttribution
dataclass
¶
Which coefficients of a control-affine fit the log identifies, on a tracked plant.
ClosedLoopAttributionCertificate
dataclass
¶
Two arms: an interaction the plant has, and one the tracking loop manufactures.
solve_channel_moment(state_residual, action_residual, states, *, instrument_action=None, degree=1, ridge=1e-06, weights=None)
¶
Solve E[(y_res - B_θ(x) u_res) (x) (z (x) phi(x))] = 0 for the channel.
The Robinson moment on its own, separated from the nuisance estimation
fit_causal_residual wraps around it. Public for two reasons: cross-fitted
ridge-sieve nuisances are a default rather than a commitment, and the point of a debiased
score is that g and m may come from any learner -- gradient boosting, a neural net, a
model the caller already had -- so the caller needs a way in that does not go through ours.
It solves the moment it is handed and checks no rank. Along a direction of the channel that
instrument_action does not move, the moment holds at every channel, and the ridge picks
one. Whether an instrument identifies the channel is the caller's to settle before the solve,
which sees neither the raw shifter nor the covariates the nuisances took out, and a rank that
decides it reads both.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_residual
|
Array
|
|
required |
action_residual
|
Array
|
|
required |
states
|
Array
|
|
required |
instrument_action
|
Array | None
|
the action-shaped variable |
None
|
degree
|
int
|
monomial degree of |
1
|
ridge
|
float
|
Tikhonov term on the moment's Gram matrix, on each coefficient scaled by its regressor column's mean square, weighted as the rows are, so that it reads the same in any units of the actions and the state. Added as a constant, it outweighed actions logged in units a millionth of their own, and set their channel near zero. |
1e-06
|
weights
|
Array | None
|
one weight per transition, shape |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
The channel coefficients, shape |
Array
|
attr: |
fit_causal_residual(known, data, dt, *, adjust_for=(), instrument=None, unconfounded=False, degree=1, channel_degree=None, nuisance_degree=2, nuisance_knots='auto', nuisance_choice='prediction', folds=2, ridge=1e-06, seed=0, integrator='euler', drivers=(), weights=None, influence=False, clusters=None, periods=None, times=None)
¶
Fit a ControlAffineResidual whose channel is the interventional control response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
known
|
Dynamics
|
the physics kept fixed; its own control dependence is known, not estimated. |
required |
data
|
dict[str, Array]
|
columns |
required |
adjust_for
|
tuple[str, ...]
|
observed confounders. Empty, with no instrument and Each covariate that is not a driver also joins the drift regression, held over the
step at its value at the start, about its mean on the log, under either integrator. A
push the drift leaves out moves the drift by its lean on the state. On A push outside the polynomial's span, |
()
|
instrument
|
str | None
|
name of an exogenous action shifter, for when the confounder is latent. It
enters as the moment's instrument, not as the regressor, so this is real 2SLS. Expect a
variance premium, not a free lunch: identification here rides on however much of
the action the shifter explains, and on the reference DGP that is 18%, which costs
roughly an order of magnitude in channel error against adjusting for a logged
confounder (0.10 vs 0.002 at It identifies the channel only where its moment has rank: where the first stage's push
on the actions moves with the actions along every direction of the channel the actions
move (all but The rank does not grade an instrument: a column of noise drawn apart from the action
keeps it, and reads identified with a channel that misses. Its relevance grades it: on
the reference plant such columns read 0.002 to 0.035, the medians of eight at 500,
2000 and 8000 rows, of the order of |
None
|
unconfounded
|
bool
|
the caller's claim that the state and the drivers alone leave the actions
unconfounded -- a randomised lever, or one set by the state alone -- as a graph whose
adjustment set is empty proves. The fit is then the orthogonal one with the state and
the drivers as its only covariates, |
False
|
degree
|
int
|
the feature degree of the drift, and of the channel unless |
1
|
channel_degree
|
int | None
|
the feature degree of the channel; |
None
|
nuisance_degree
|
int
|
flexibility of |
2
|
nuisance_knots
|
int | Literal['auto'] | None
|
a natural cubic spline in each covariate, at this many of its quantiles,
beside the polynomial of |
'auto'
|
nuisance_choice
|
Literal['prediction', 'score']
|
what the three sieves are chosen on. |
'prediction'
|
folds
|
int
|
cross-fitting folds. |
2
|
ridge
|
float
|
the Tikhonov term of the nuisances, the channel's moment, the drift regression and the instrument's first stage. The nuisances read standardised covariates. The drift regression and the first stage scale each slope's term by its column's variance, beside a free bias; the moment, which has no bias, scales each coefficient's by its column's mean square, on the log's raw actions. So the ridge reads the same in any units of the state, the actions, the drivers and the instrument. Added as a constant, it outweighed a column logged in units a millionth of its own: such actions read a channel near zero, and such a state a drift slope near zero. |
1e-06
|
integrator
|
Integrator
|
the one-step map the fitted field is made consistent with.
Up to 0.6.0 the fixed point was iterated instead -- add the leftover to the target,
refit -- and each state stopped once its defect's RMS stopped falling. That is not where
the fixed point is: the RMS flattens under the noise first, and the iteration contracts
the drift only by A log that falls by more in one step than RK4 can follow has no The default stays |
'euler'
|
drivers
|
tuple[str, ...]
|
exogenous columns that push the state and that nothing the plan does can move --
weather, a demand forecast. |
()
|
weights
|
Callable[[Array], Array] | None
|
a weight on each transition's channel moment, a function of its state alone.
Experimental: it may change or be withdrawn in any release. A callable is called with
Under a channel class that contains the truth every weight estimates the same channel,
and only the variance moves. The inverse of the rate's noise variance is the efficient
weight in the limit, but it loads the states where the noise is small, which can be
where the nuisances extrapolate: on a log whose rate noise ran Under a class that misses the truth, each weight estimates a different channel: the
projection of the true one under |
None
|
influence
|
bool
|
whether to keep each transition's influence on the fitted parameters,
|
False
|
clusters
|
ndarray | Array | None
|
each transition's cluster, |
None
|
periods
|
ArrayLike | None
|
each transition's period, a whole number of steps, on a log whose transitions
fall in one group, one unit's or the units' of one declared cluster, which leaves no
second cluster to sum within: one label a transition, two periods at least. The
channel's covariance then sums the scores of each period's transitions over them and
their states, and reads the sums' dependence across the periods by |
None
|
times
|
ArrayLike | None
|
each transition's start time, |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CausalDynamicsFit
|
class: |
CausalDynamicsFit
|
no direction of the channel apart from what the states and the covariates predict, a lever |
|
CausalDynamicsFit
|
held constant or set by its own covariate, leaves |
|
CausalDynamicsFit
|
with no adjustment set; where it leaves any direction unmoved, the fit logs a WARNING |
|
CausalDynamicsFit
|
naming the levers by their columns of |
Raises:
| Type | Description |
|---|---|
ValueError
|
on an |
omitted_confounder_bound(fit, functional, *, cf_y, cf_d, rho=1.0, level=0.95, null=0.0)
¶
Bound a linear functional of the channel against a confounder adjust_for left out.
Experimental.
Chernozhukov, Cinelli, Newey, Sharma and Syrgkanis (2022) bound the bias of a linear
functional of a partially linear fit by |rho| sqrt(cf_y cf_d / (1 - cf_d)) sigma nu:
sigma^2 the rate's residual variance after the fit, nu^2 the second moment of the
functional's Riesz representer, both identified, and two shares that are not. cf_y is the
share of that residual variance the latent explains; cf_d the share of the long
representer's second moment the fit's short one misses, which for one lever is the latent's
partial R^2 with it. rho is the correlation between the two gaps, 1 at the worst. On a
linear Gaussian plant with one latent the bound is attained, for any functional of any number
of levers, and with two latents it is strict unless they move the lever and the rate in
proportion (validation/omitted_confounder_bound.mac). Over several states the bound sums
sigma_s nu_s, taking the shares as common to them; under Euler a functional of one
state's channel reads that state alone.
functional weighs the channel's coefficients, in its shape (n, m, n_features). One
lever's effect on one state is a single 1. Moving spend from lever a to lever b is
+1 at b and -1 at a, and since its value is linear in the channel, its
robustness_value is the confounding at which the move stops paying.
The sampling error follows DoubleML's: each confidence bound is one-sided at level, and
carries the estimate's influence and bias_scale's, whose nu^2 part is nu^2 -
alpha^2 for a representer alpha. Its sign convention for the estimate differs from this
one in the cross term of the two influences, which vanishes in expectation. A fit given
clusters has both influences summed within each cluster, as its channel's error is, and
one given periods reads them across its periods by cosines, each period's transitions
summed first. The bounds take a t's quantile with G - 1 degrees of freedom, G the
clusters, two-way the smaller dimension's count, or the rows where there are none; or nu,
the cosines', under periods (ADR 0075). At 5 units, a 5 % test of the channel read off its
error rejected 9.75 % and 14.75 % of panels against the normal's quantile, and 3.25 % and
5.75 % against t(4)'s (ADR 0062). DoubleML takes the normal's.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
CausalDynamicsFit
|
an identified fit of |
required |
functional
|
Array
|
the weight on each channel coefficient. |
required |
cf_y
|
float
|
the share of the residual variance the latent explains, in |
required |
cf_d
|
float
|
the share of the long representer's second moment the short one misses, in
|
required |
rho
|
float
|
the correlation of the two gaps, in |
1.0
|
level
|
float
|
each confidence bound's one-sided level, in |
0.95
|
null
|
float
|
the value the robustness values measure the distance to. |
0.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
on a fit whose channel is not identified by adjustment -- an instrument's
representer is not the moment's -- or that is weighted, or kept no representer; on a
functional of another shape; on shares, |
channel_region(fit, level=0.95, *, bound=None, form='ridge')
¶
The self-normalised confidence ellipsoid of the fitted channel, at level.
Experimental: it may change or be withdrawn in any release. Abbasi-Yadkori, Pal and
Szepesvari (NeurIPS 2011, Theorems 1 and 2): for y_t = <X_t, c> + eta_t with X_t
predictable and eta_t conditionally R-sub-Gaussian, the ridge estimate c_hat
satisfies ||c_hat - c||_V <= R sqrt(2 log(det(V)^(1/2) det(V0)^(-1/2) / delta)) +
||c||_V0 with probability at least 1 - delta, V = V0 + X'X. The regressors need only
be predictable, so a log the plant was controlled in qualifies: a closed-loop policy's actions
move with the states and the noise before them. Here V0 = ridge P, the fit's own ridge,
one ellipsoid a state at delta / n.
It gives the plan's rate error a level (ChannelRegion.rate_error) and the
certainty-equivalent certificate a probability (ChannelRegion.stability_level),
beside the standard errors the tube carries at their studentised quantile, which it does not
move.
Premises, and where they fail:
- No hidden confounder. The noise must be mean zero given the actions; a confounder the
fit does not adjust for pushes the rate with the action, and the ellipsoid misses the
channel, at any
level. - No persistent noise.
etamust be a martingale difference; AR noise is not, unless its lags are in the fit (persistence_check). - No shared shock the fit was not told of. Rows are read one at a time, so a shock every
unit shares in a period, met by levers the units move together, adds up across the
period's rows beyond each row's
R: on 30 units over 20 periods sharing each period's shock, the 0.95 region missed the channel on 6.9 % of 1000 logs read row by row. A fit givenclusterssays which rows share their noise, andRis then read within them, below. - R is read off the log: each state's root mean square of the moment's residual, over
N - qrows, a plug-in for the theorem's knownR, which also counts the cross-fitted nuisances' error. The action residuals use nuisances fitted on other rows, so the regressors are predictable to the nuisance's first order only. Under the fit'sclusters,R^2is the larger of that and the most the state's scoresD_i e_i, summed within the clusters and squared at CR1's factor, two ways the largest of the three reads the fit's error takes, reach inV's norm: the clusters' sums are then read as the theorem's terms. - The prior term
||c||_V0isboundwhere given, else the estimate's own, a plug-in; at the default ridge it is about 1e-3 of the coefficients' effect on the rate. - The prior's scale is read off the log too.
Pis the diagonal of the log's mean squares of the channel's regressors, soV0is a plug-in asRis: the theorem'sV0is fixed before the log. The grid's members are multiples of it, on the same terms.
form="grid", experimental, reads the radius of Simpson, Baumgartner, Koehler and Diehl
(arXiv 2603.19073, 2026, Theorem 2), proved under the same premises: the noise conditionally
sub-Gaussian with a known R, the regressors predictable, the true coefficients within
||c||_V0 of nought. It puts the prior's term inside the root, sqrt(||c||_V0^2 + R^2
(...)) where Abbasi-Yadkori et al. add it outside, and reads the log-determinant against a
prior matrix V_bar near D'D rather than the fit's ridge, paying sqrt(1 + rho((V0 +
D'D)^-1 V_bar)) for it: the least over a fixed grid of 65 members, V_bar = 0 and 2^j
V0, each at delta / 65 (_grid_members). At the fit's ridge of 1e-6 the
log-determinant against the ridge is the larger part of the radius, and the grid's is smaller:
on 2000 closed-loop logs of x' = 0.9 x + 0.5 u + e, u = -0.6 x + e', 2400 rows, V0 =
1e-6 I, the median radius of the region of (0.9, 0.5) read 7.06 by Abbasi-Yadkori et
al.'s form and 4.76 by the grid's; on 100 logs of 1500 rows of a feedback policy with an
adjusted confounder, the channel's region at 0.95 read 1.69 and 1.16. Each held the truth on
every log.
Under a hidden confounder an instrument's sign-perturbed sums (Szentpeteri and Csaji, 2023) stay valid; they are not built here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
CausalDynamicsFit
|
an identified Euler fit by adjustment, unweighted, whose actions move every direction of the channel. |
required |
level
|
float
|
the joint level over the states, in |
0.95
|
bound
|
float | None
|
an upper bound, for every state, on the true coefficients' norm in the ridge's
metric, |
None
|
form
|
RegionForm
|
the radius ( |
'ridge'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
on a fit that is not identified, read through an instrument, fitted under
|
persistence_check(fit, units, periods)
¶
The lag-1 autocorrelation of fit's moment residual within units. Experimental.
units and periods label the fit's transitions, N each: the unit, of any one
sortable kind, and the period the transition starts in, a whole number of steps. Two
transitions of one unit whose periods differ by one are a pair. Each state's residual is
divided by its root mean square, so each state counts alike in any units. The pairs' products,
summed over the states, are summed within each unit before the test, since the transitions of
one unit need not be independent; the statistic is their total over its CR1 spread, each
unit's sum less its pairs' share of the total, against t(G - 1) (ADR 0062). A fit given
clusters says its units' noise moves together within them, several units' or one
period's, so the units' sums are not independent: the products are summed within the fit's
clusters instead, each less its pairs' share, two ways the largest of the three reads its
error takes, against t(G - 1) for G the clusters, two ways the smaller count. On panels
of 4 units a cluster over 10 periods, whose noise and levers share a shock each period within
a cluster and do not persist, the 5 % test summed within units rejected 12.5 % of 1000 at 5
clusters and 16.2 % at 30; within the clusters, 4.9 % and 7.0 %. Two ways, the largest of
the three is conservative where the noise moves with neither label: on panels of 50 and 200
units over 12 periods, clustered by unit and period, the 5 % test rejected 3.5 % and 2.0 % of
200 logs, where Cameron, Gelbach and Miller's sum of the two less their intersection rejected
7.5 % and 6.5 %; under AR(0.2) noise at 50 units it rejected 64.5 %, theirs 72.0 %. The unit
clusters alone, at 5.5 % and 7.5 % there, rejected 43 % and 63 % of logs whose units shared a
shock each period that did not persist, and the three 5.5 % and 6.0 %: the largest of the
three stays, a test that undershoots its size where the units alone would hold it. Pairs of one
unit alone, or of a fit given periods, whose units share one group's noise, are read
across their periods instead: the products summed within each period, and the total over the
spread of their projections on nu cosines of the pairs' periods, against t(nu), as
the fit reads its error (ADR 0075). Pairs that all fall in one period leave no spread to read.
A rejection says the premise fails, not by how much the channel is off: that depends on how
far a lever persists as well (PersistenceCheck). Adjusting the fit for the state, the
levers and the adjustment set a period earlier removes the bias where the noise is AR(1): on
panels of 200 units over 100 periods whose noise and lever are AR(0.7), a channel of 0.8 read
0.0130 low, 0.0007 low with them, and 0.0250 low with the state's lag alone (ADR 0064).
A residual that moves with a lever some periods back, a dead time, is
lag_check's to read: the lag-1 autocorrelation does not name it.
Raises:
| Type | Description |
|---|---|
ValueError
|
the fit kept no moment residual, as where its channel is not identified; the labels are not one a transition; a period is not a whole number; a unit has two transitions starting in one period; or the log spans two periods or more and no unit has two transitions one period apart, as on periods counted in days a week apart, where the check read no pair and returned nan without a word. |
nuisance_shift(fit, refit, states)
¶
How far a refit of one log with richer nuisances moves the channel, in the fit's errors:
the root mean square over states, (N, n), and the channel's entries of
B_refit(x) - B_fit(x), over fit.channel_error. Experimental.
The moment is orthogonal, so the nuisances' error moves the channel at second order only, but
a policy or a drift outside their span leaves an error that does not shrink with the log, and
a bias that channel_error does not cover. Refit with nuisance_knots, more knots or a
higher nuisance_degree, and read the shift: within the span, both fits estimate one channel
and the shift is a fraction of an error; a shift of more than one or two says the fit's
nuisances miss. On a lever set by -1.5 tanh(2 x) and a drift with sin(2 x) in it, at
4000 rows, the degree-2 polynomial fit (nuisance_knots=None) read 53 to 61 errors from its
refit with nuisance_knots="auto" on five logs, and that refit 0.02 to 1.9 from its own at
twice the knots.
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
interference_check(fit, exposure, groups, periods)
¶
Regress fit's moment residual on its neighbours' levers, within periods. Experimental.
exposure is (N, m): for each of the fit's transitions, the mean of each lever over the
unit's neighbours in the period the transition starts in, nan where no neighbour is logged
then; such a transition is left out. groups and periods label the transitions, N
each: the group the errors are summed within, a unit or a declared cluster, and the period.
The residual and the exposure are taken about their means within each period, so a shock every
unit shares in a period, which the neighbours' levers may chase, moves neither. Each state's
residual is regressed on the exposure; a slope's error is the CR1 sandwich over the groups'
sums of scores, against t(G - 1), and the check's p-value Bonferroni's over the slopes.
Under the fit's premise the residual has mean zero given the unit's own states, levers and adjustment set, and a neighbour's lever is another unit's: its slope is zero. A rejection says the premise fails, by spillover or by a nuisance the fit misses that the neighbours' levers track; it does not say by how much the channel is off. Neighbours that are every other unit leave an exposure that within a period is the unit's own lever mirrored, which the check cannot tell from the unit's own effect.
Raises:
| Type | Description |
|---|---|
ValueError
|
the fit kept no moment residual, as where its channel is not identified; or the exposure or the labels are not one row a transition. |
lag_check(fit, data, units, periods, *, lags=3, adjust_for=())
¶
Regress fit's moment residual on its levers 1 to lags periods back. Experimental.
data holds the columns the fit was given, x (N, n) and u (N, m), and those named
in adjust_for, the fit's adjustment set; units and periods label the transitions as
persistence_check reads them. A transition's lever k periods back is its unit's
transition's that many periods earlier; a transition without all lags of them is left out.
The residual and the late levers are each taken less their least-squares fit on a constant,
the states, the levers and the adjustment set, the fit's own regressors, and each state's
residual is regressed on the late levers (Frisch and Waugh 1933). A slope's error is the CR1
sandwich over the units' sums of scores, or the fit's clusters' where it was given them; each
state's slopes are tested together by Wald's statistic against F(k, G - 1), and the check's
p-value is Bonferroni's over the states. This is the residual test of a model's dynamic part,
the residual's cross-correlation with past inputs (Ljung 1999, chapter 16).
Under the fit's premise the residual has mean zero given this period's state, levers and
adjustment set, and an earlier lever reaches it only through the state: its slope is zero.
A rejection says the plant reads a lever late. lag then names the lag that carries it;
chc.irf.delay_estimate reads the delay off the response with an interval, and a state
that carries the levers' last lag values holds a discrete dead time exactly
(chc.delay.DelayedDynamics holds a continuous one). It sees what
persistence_check cannot name: on the misspecification suite's two-state plant whose
lever reaches it two periods late, 200 units over 12 periods, the check rejected on 6 logs of
6 and named lag 2 on each; on the same plant without the dead time it rejected at 0.05 on 5
logs of 60, its size.
It reads across groups, the units or the fit's clusters, and not along one group's periods as
persistence_check does: on one unit, or one cluster, it has no spread to read and
returns p_value nan and lag None, as it does where no late lever moves once the
fit's regressors are held. With few groups it has little power: F(k, G - 1)'s tail is
heavy at small G, and at two groups F(1, 1) rejects at 0.05 only past
tan(0.475 pi)^2 = 161.
Raises:
| Type | Description |
|---|---|
ValueError
|
the fit kept no moment residual, as where its channel is not identified; the
columns or the labels are not one row a transition; |
closed_loop_gain_attribution(states, actions, rates)
¶
Attribute a control-affine fit's coefficients to the controller and to the plant.
The question is why the interaction coefficient b1 of
dx/dt = d + a*x + (b0 + b1*x)*u comes out large and negative on a setpoint-tracked zone.
The answer is a property of the log, not of the plant. A proportional loop
u = gain*(setpoint - x) + u0 puts every sample on an affine manifold x = c + m*u with
m = -1/gain, and restricted to that manifold the four-term class collapses to a quadratic in
the action::
d + a*x + (b0 + b1*x)*u = (d + a*c) + (a*m + b0 + b1*c)*u + (b1*m)*u^2
Only b1 reaches the u^2 term, so b1 is the identified coefficient and the pole is
not -- the inverse of the usual reading, and the reason the reported pole is a units artefact
while lambda(u) = a + b1*u holds. Matching against an observed
response A + B*u + C*u^2 gives
``b1 = C/m = -gain*C``,
so the sign is decided by the curvature of the response in the action and the magnitude by the
controller: a tighter tracker reports a bigger interaction from identical physics.
proofs/closed_loop_attribution.v proves the matching identity and exhibits the explicit
one-parameter family that leaves d, a and b0 free.
This also refutes the standing guess that b1 = -1/gain. That is the manifold slope,
not the interaction; equating them forces C = 1/gain^2, a constraint on the plant rather
than an identity (guess_is_a_constraint_not_an_identity).
exploration_budget is what buys the rest back: variation off the manifold restores the
design's rank, and with it the separation of a from b0. Reading a pole off a fit whose
budget is ~0 is reading the regulariser.
closed_loop_attribution_certificate(gains=(0.5, 1.0, 2.6, 8.0), exploration=(0.0, 0.05, 0.25, 1.0), samples=4000, seed=0)
¶
Separate the interaction a plant HAS from the one a tracking loop MANUFACTURES.
Arm A: the plant really is d + a*x + (b0 + b1*x)*u. Under exact tracking the design is
singular, yet b1 comes back exactly while the drift a does not -- the non-identification
is real and it is the pole that suffers, not the interaction.
Arm B: the plant has no interaction, but its response carries a u^2 term the fitted
class cannot represent. The fit answers with b1 = -gain*curvature: a coefficient that is
entirely an artefact of misspecification amplified by the loop, growing linearly with the
controller's gain. That is the mechanism behind a large negative b1 on a tracked log, and
why
the number cannot be read as authority-falls-with-temperature without checking the budget.
The exploration sweep is the remedy: variation off the manifold restores the design's rank and
the drift with it. All three claims are measured here, and the middle one is the one that would
embarrass the entry if b1 turned out to be as unstable as a.