Skip to content

chc.uncertainty

Stability tier: evolving.

Calibrated pessimism: a deep-ensemble residual whose disagreement, conformalised for coverage, scores predictive uncertainty for the offline-safety penalty (its U term).

chc.support scores density distance D((x,u),D); this module supplies the complementary calibrated predictive uncertainty U(x,u). Fit K residuals as a deep ensemble; their member disagreement is the epistemic uncertainty of the learned dynamics (large where the members, trained on the same offline data, extrapolate apart), and split conformal turns it into interval widths that cover with probability at least 1 - alpha on data exchangeable with the calibration split, given at least (1 - alpha) / alpha calibration transitions. Both plug into the same penalty channel of chc.support.pessimistic_control via penalty_trajectory(xs, us) -> scalar, so model exploitation is bounded, not merely discouraged.

A third scorer, WassersteinPenalty, targets the deployment-shift failure mode rather than in-distribution epistemic spread: a Wasserstein-1 distributionally-robust margin (radius * Sigma ||d r / d x||) that keeps control where a small shift of the state distribution cannot move the learned dynamics much.

EnsembleResidual

Bases: Module

Deep ensemble of residuals: K members whose mean is the field, whose spread is uncertainty.

Duck-types the Dynamics protocol -- __call__ returns the member mean, so it drops into HybridDynamics.residual. disagreement is the total variance across members (epistemic uncertainty of the learned part), ~0 where members agree and large where they extrapolate apart.

member_outputs(t, x, u)

Stack the K member vector fields at (t, x, u) -> shape (K, out_dim).

disagreement(t, x, u)

Total variance across members at (t, x, u) -- the epistemic uncertainty scalar.

ShardedEnsembleCertificate dataclass

Evidence that the stacked, sharded ensemble fit is the serial per-member recursion.

EnsembleUncertainty

Bases: Module

Predictive-uncertainty penalty U from an ensemble residual -- its member disagreement.

Mirrors SupportModel.penalty_trajectory so it plugs into the same lam_unc channel of chc.support.pessimistic_control. Penalises visiting states/actions where the learned dynamics are uncertain (members disagree) -- exactly where model exploitation happens.

penalty_trajectory(xs, us)

Total member disagreement over the visited (x, u) pairs (xs: (H,n), us: (H,m)).

NestedCVaRPenalty

Bases: Module

Time-consistent (nested) CVaR of the ensemble's disagreement, as a PenaltyModel.

EnsembleUncertainty sums the member variance along the trajectory, which is a risk neutral aggregation: one very bad step averages away against many quiet ones. This replaces the aggregation with a nested conditional risk measure, rho_t = c_t + CVaR_alpha[rho_{t+1}] (Ruszczynski 2010; Shapiro-Dentcheva-Ruszczynski 2021), evaluated on the per-member deviations ||r_k - mean_k r_k||. Same penalty_trajectory(xs, us) -> scalar shape, so it drops into the lam_unc channel of chc.support.pessimistic_control unchanged.

The distinction that matters is which adversary the number prices, and both are available:

  • penalty_trajectory (nested) -- the adversary re-picks the worst alpha fraction of members at every step, so a model may be wrong here and a different one wrong there.
  • static_penalty_trajectory -- the adversary must commit to one member for the whole horizon, then the tail is taken once over those horizon-summed scenarios.

Nested is therefore never smaller (subadditivity of CVaR, Sum_t CVaR[c_t] >= CVaR[Sum_t c_t] -- a standard coherence property, not a result of this repo), and the gap is the price of time consistency. Time consistency is the reason to pay it: a plan optimal for the static measure at t = 0 need not be the plan you would re-choose at t = 1 after seeing the first step, so a receding-horizon controller that re-solves -- which is what chc.mpc.mpc_control does -- can chase its own tail. The nested measure has no such gap by construction.

HONEST SCOPE: with the members re-evaluated independently at each visited pair, the recursion collapses to Sum_t CVaR_alpha[c_t]; this is the aggregation rule made risk-averse, not a dynamic-programming solve of a nested-risk MDP, and it does not certify a bound on the cost.

member_costs(xs, us)

(H, K) per-member deviation from the ensemble mean field at each visited pair.

penalty_trajectory(xs, us)

Nested: the tail is taken per step, so the worst members may differ across steps.

static_penalty_trajectory(xs, us)

Static: one tail over horizon-summed per-member scenarios (time-INCONSISTENT).

NestedRiskCertificate dataclass

Numeric evidence that the nested measure dominates the static one, and by how much.

SplitConformal

Bases: Module

Split-conformal calibration of the ensemble's next-state uncertainty (coverage guarantee).

Calibrated on a held-out split: the normalised nonconformity score is s = ||x_next - mean|| / (sigma + eps) with sigma the ensemble predictive std; q_hat is the k-th smallest of the n scores, k = ceil((n + 1)(1 - alpha)). interval_width = q_hat*(sigma + eps) has marginal coverage >= 1 - alpha on data exchangeable with the calibration split (measured by coverage). That needs k <= n, so n >= (1 - alpha) / alpha: with fewer scores no finite width carries the guarantee, and calibrate refuses rather than read the largest score, which covers n / (n + 1).

calibrate(model, data, dt, alpha=0.1, eps=1e-06) classmethod

Calibrate on data's transitions, held out from the ensemble's fit.

Raises:

Type Description
TypeError

when model's residual is not an EnsembleResidual.

ValueError

when alpha is not in (0, 1), eps is not positive, or data holds fewer than (1 - alpha) / alpha transitions.

interval_width(x, u)

Calibrated prediction-interval half-width q_hat * (sigma(x,u) + eps) (scalar).

coverage(data)

Empirical coverage on data: fraction of true next-states within the interval.

penalty_trajectory(xs, us)

Total calibrated interval width over the visited (x, u) pairs (a penalty).

HorizonConformal dataclass

One conformal scale for every step of a horizon: a simultaneous band scale * r_k.

Experimental: it may change or be withdrawn in any release. Each calibration window is scored by max_k ||x_{t+k} - x_hat_{t+k}|| / r_k over the horizon, r_k a fixed profile such as the plan's tube (CausalPlan.uncertainty_tube[1:]), and scale is the ceil((n + 1)(1 - delta))-th smallest of the n scores. Cleaveland, Lee, Pappas and Lindemann (AAAI 2024, Theorem 3 and Corollary 1): on windows drawn i.i.d., a fresh window's every step lies within scale * r_k with probability at least 1 - delta, and, its scores tied with probability 0, at most 1 - delta + 1 / (n + 1). The profile and the model must not be fitted on the calibration windows. Per step at 1 - delta each, the steps together hold less; split delta / H per step (Bonferroni), they hold more than needed.

On one series rather than i.i.d. windows, calibrate with mixing states 1 - delta - eta, eta from mixing_penalty, and refuses where eta >= delta.

Under a distribution shift, calibrate with shift=("tv", eps) or shift=("kl", rho) holds 1 - delta for every law P of the fresh window within that ball of the calibration windows' law P0: a total variation sup_A |P(A) - P0(A)| <= eps, or KL(P || P0) <= rho. A ball on the windows' law holds the scores' law in it too, and the scores' is all the band reads. Cauchois, Gupta, Ali and Duchi (JASA 2024, Proposition 1 and Theorem 1): over such a ball an event of probability beta under P0 keeps at least g(beta), the least z whose two-point divergence from beta is within the radius, and g is convex, so the k-th smallest score holds a fresh window drawn from P with probability at least g(k / (n + 1)). The scale is therefore the ceil((n + 1) beta)-th smallest score, g(beta) = 1 - delta: beta = 1 - delta + eps under total variation, exactly, and under KL the root beta > 1 - delta of KL(Bernoulli(1 - delta) || Bernoulli(beta)) = rho (validation/conformal_shift_budget.mac). How to read the radius: it is the largest shift between the calibration windows and the deployed ones the band is to survive, stated by the caller; nothing here estimates it, and the band says nothing of a larger shift. A total variation of delta or more leaves no finite band, and calibrate refuses it, as it refuses too few windows for the shifted rank. A KL ball holds no law with mass where P0 has none, and a total variation ball does. On one series the ball bounds the fresh window's law given the calibration windows, and the level is g(beta - eta): 1 - delta - eta under total variation, less under KL.

What it covers: windows of the policy that logged the calibration windows, under that policy's actions. Not the plan's own actions, which move the plant elsewhere; and it moves no number of the tube, which it reads as a profile only.

band property

scale * r_k at each step: every step's radius at the joint level.

level property

The joint level the band holds: 1 - delta, less eta on one series, for every law in the shift's ball where there is one; on one series under a KL ball, g(beta - eta), the least that ball leaves of the series' beta - eta.

calibrate(errors, profile, delta=0.05, *, mixing=None, train_lag=None, shift=None) classmethod

Calibrate on errors, (n, H, states), one row per window as horizon_errors returns them, against profile, one positive radius per step.

Parameters:

Name Type Description Default
mixing Callable[[int], float] | None

on windows cut from one series, beta(j) at a lag of j windows (mixing_penalty); None where the windows are i.i.d.

None
train_lag int | None

with mixing, the lag in windows from the data the model and the profile were fitted on to the test window (mixing_penalty).

None
shift tuple[Literal['tv', 'kl'], float] | None

("tv", eps) or ("kl", rho), the ball around the calibration windows' law whose every law the band holds at its level: a total variation eps, or the divergence KL(P || P0) of the deployed law P from the calibration law P0 (the class's docstring). The caller's bound on the shift, not an estimate. None, the default, reads no shift, and a radius of 0 reads the same band.

None

Raises:

Type Description
ValueError

when delta is not in (0, 1), the errors and the profile do not pair, too few windows certify 1 - delta, train_lag is given without mixing, or the series' eta is at least delta; when shift names another ball or a negative or infinite radius, its radius leaves the band's scale infinite, at these windows or at any number of them (a total variation of delta or more), or on one series a KL ball leaves no level.

covers(errors)

Whether each window of errors, (W, H, states), lies within the band at every step.

WassersteinPenalty

Bases: Module

Wasserstein-1 distributionally-robust penalty on the learned residual.

Where SupportModel scores in-distribution density distance D and the ensemble scores epistemic spread U, this scores sensitivity to a distribution shift of the states. It is a heuristic local-gradient margin, not the Wasserstein-1 worst case. Kantorovich-Rubinstein duality bounds the worst-case mean cost over a W1 ball of radius radius by the empirical mean plus radius times the cost's global Lipschitz constant, with equality only for special costs (Gao and Kleywegt 2023; Blanchet, Kang and Murthy 2019; Shafieezadeh-Abadeh, Esfahani and Kuhn 2015). The penalty is instead radius * Sigma_t ||d r / d x||_F, the learned residual r's local gradient at each visited state (the known physics f_known is trusted, hence excluded), summed over the trajectory rather than averaged. So it is zero where the residual is stationary at every visited state, however far a shift of radius would move it; it grows with the horizon; and it is neither the global constant nor a bound on the worst case. For r = -cos(x), four states at x = 0 and radius = 0.5 it reads 0 where moving each state by the radius raises the mean by 0.122; at x = pi/2 it reads 2.0 where radius times the global constant is 0.5. What it does: steer control away from states where the learned dynamics are locally steep. Satisfies the PenaltyModel protocol, so it drops into the lam_unc channel of chc.support.pessimistic_control unchanged; radius scales it.

from_model(model, radius) classmethod

Penalise the learned residual of a hybrid model (f_known is trusted, so excluded).

local_lipschitz(x, u)

The residual's local slope in x at one point: the Frobenius norm of d r / d x, zero at a stationary point, below or above the global Lipschitz constant elsewhere.

penalty_trajectory(xs, us)

The local-gradient margin radius * Sigma_t ||d r/d x||_F over the visited (x, u) pairs: a sum over the steps, not the W1 worst case.

ConfoundingRobustPenalty

Bases: Module

Pessimism against a HIDDEN-CONFOUNDING effect error, for the general OC stack.

chc.research.regret.confounding_robust_control robustifies a scalar tracker; this lifts the same sensitivity radius into the multivariate hybrid solver. Under hidden confounding the control-effect matrix B is only partially identified: the offline estimate B_hat sits within a sensitivity half-width radius (the MSM Delta(Gamma)) of the truth. An effect error times an action is a state error, so a per-step control u_t carries a per-step transition error ||Delta_B @ u_t|| <= radius * ||u_t||, and radius * Sigma_t ||u_t|| accumulates that over a trajectory. Penalising it steers control away from exploiting a partially-identified effect with large actions -- the confounding analogue of WassersteinPenalty's deployment-shift margin. Satisfies the PenaltyModel protocol (penalty_trajectory(xs, us) -> scalar), so it drops into the lam_unc channel of chc.support.pessimistic_control unchanged.

HONEST SCOPE, and it now depends on which constructor was used. Plain ConfoundingRobustPenalty(radius=...) is an identification-radius regulariser: that inequality bounds the state-transition error, and converting that into a bound on the objective needs the sensitivity multiplier Delta J <= Sigma_t L_{V,t+1} * radius * ||u_t||, which this path does not supply -- so lam_unc absorbs it as an unidentified scale. certified supplies it -- the adjoint norm ||lambda_{t+1}||, the RK4 injection gain and a second-order deviation tube -- and on that path lam_unc = 1 is the bound rather than a knob. confounding_cost_bound_certificate is the gate that can fail it.

Either way the COEFFICIENT is derived from the MSM sensitivity rather than being an arbitrary actuation budget; Gamma and the CVaR-gap calibration remain the analyst's inputs, and it does NOT test for confounding.

from_sensitivity(cvar_gap, gamma) classmethod

Radius = the bounded-density-ratio inflation (Gamma-1)/(Gamma+1) * cvar_gap.

certified(radius, dyn, x0, us_reference, dt, cost) classmethod

Supply the missing multiplier, so lam_unc = 1 is the bound rather than a free knob.

The radius bounds the per-step transition error; turning it into a bound on the objective needs Delta J <= Sigma_t L_{V,t+1} * radius * ||u_t||, and L_{V,t+1} is locally the adjoint norm ||lambda_{t+1}||. That is a quantity the planner already computes, so leaving it to be absorbed by lam_unc was throwing away information, not avoiding an assumption. chc.adjoint.costate_norms returns it along us_reference.

The first-order term alone is not an upper bound, and measuring rather than assuming is what showed it: at the optimum the Cauchy-Schwarz step is nearly tight, so the dropped curvature term -- positive, O(radius^2) -- pushes the realised worst case above it at every radius: an adversary reaches 1.014 of it at radius 0.005 and 1.69 at 0.2 on a two-lever oscillator, while the weights below hold at 0.995 and 0.953. chc.adjoint.perturbation_cost_weights therefore carries the deviation tube and the cost curvature as well, which is why radius is an argument here: a second-order term cannot be folded into a radius-free weight.

Three things this is and is not:

  • Second order, exact for LQ. For a linear plant with a quadratic cost the objective is exactly quadratic along a perturbation direction, so the expansion closes and the only slack left is Cauchy-Schwarz. A nonlinear plant adds the step's curvature, contracted with the costate, at the same order, and keeps an O(radius^3) remainder that nothing here bounds; confounding_cost_bound_certificate measures whether it matters.
  • At a reference. The weights are frozen at us_reference, which breaks the circularity of weights that depend on the plan that depends on the weights. Iterating (re-solve, re-weight) is available to the caller and is not done here, because a fixed point is a different claim from a bound at a named trajectory.
  • Not a confounding test. radius still comes from an assumed Gamma.

penalty_trajectory(xs, us)

Confounding pessimism radius * Sigma_t L_t ||u_t|| (xs unused).

L_t is 1 when no weights were supplied -- the identification-radius regulariser -- and chc.adjoint.perturbation_cost_weights when they were, on which path the sum is an upper bound on the cost gap rather than a scale-free direction, exact to its Cauchy-Schwarz slack, on a plant affine in the state. Elsewhere it is a bound to second order in the radius only: the O(radius^3) remainder is not bounded, and it takes over once the radius is not small against the field's curvature. On the field (x_2, -x_1 - 0.2 x_2 + k x_1^2) + u, two levers, dt = 0.05, 20 steps from (1, -0.5), the worst gap an adversary reached stayed below the sum while k * radius < 0.8, met it at 0.8 (k = 4, radius 0.2), and passed it from k * radius = 1.2: 1.30 times the sum at k = 4, radius 0.3, 2.34 times at radius 0.5, and 83 times at k = 8, radius 0.5. Read it as a bound at a radius that large only after an adversary, as confounding_cost_bound_certificate runs on an oscillator, has failed to pass it.

LipschitzRolloutCertificate dataclass

Numeric evidence: the measured rollout deviation stays under the certified Gronwall bound.

ContractiveRolloutCertificate dataclass

Evidence a contractive residual has log-norm mu<0 and a flat (bounded) rollout radius.

TimeVaryingRolloutCertificate dataclass

Evidence the time-varying tube is a valid, tighter-than-constant envelope with a cutoff.

ConfoundingRobustCertificate dataclass

Evidence the closed-form MSM worst-case equals the brute-force sharp bound and behaves.

ConfoundingRobustClosedLoopCertificate dataclass

Evidence confounding widens the closed-loop tube and shortens the certified-safe horizon.

ConfoundingBoundCurve dataclass

Predicted vs adversarially realised cost gap, radius by radius. ok iff none exceeded.

GammaBenchmark dataclass

Gamma expressed in units of the confounding the OBSERVED covariates actually carry.

GammaBenchmarkCertificate dataclass

Falsifiable gates for benchmark_gamma and negative_control_gamma.

fit_ensemble(model, data, dt, n_members=5, width=16, depth=2, bootstrap=True, seed=0, steps=2000, lr=0.01)

Fit K residuals into an EnsembleResidual (split keys + optional bootstrap), in parallel.

Each member is a fresh MLPResidual (dims inferred from data = {x, u, x_next}) trained by the same Adam recursion chc.train.fit_residual runs. With bootstrap each member sees a row-resample of the data, so disagreement reflects both init randomness and data variation. Returns HybridDynamics(model.known, EnsembleResidual) and the per-member loss histories.

The members are trained together: one stacked parameter pytree, jax.vmap over the member axis, jax.lax.scan over the Adam steps, and the stack sharded over the member axis of _member_mesh. This is one XLA program rather than K x steps dispatches, and it is the same recursion -- sharded_ensemble_certificate pins the agreement in ULP.

sharded_ensemble_certificate(seed=0, n_members=8, n_samples=96, parity_steps=60, dt=0.05)

Check fit_ensemble against a serial oracle built from the untouched public trainer.

Two claims, each pinned by the measurement that can falsify it. Numerics: every member of the stacked fit matches the member chc.train.fit_residual produces from the same key and the same bootstrap rows, reported in ULP of the working dtype rather than as an absolute -- the threshold is a precision claim, so it is stated in the unit precision actually has. Layout: the member axis is genuinely distributed, so a stacked array committed to _member_mesh and consumed by a jitted vmap comes back spanning the whole mesh; on a one-device host that is trivially 1, and the subprocess test forces eight.

parity_steps is deliberately short. Adam on this loss is chaotic: past a few hundred steps a one-ULP difference in reduction order is amplified without bound (measured 6.6 ULP at 200 float32 steps, 7557 at 400), so a long-horizon parity threshold would be either vacuous or flaky. The equivalence certified is of the recursion, which a short horizon tests exactly.

cvar_upper(values, alpha)

Upper CVaR (superquantile) of equally-weighted values at level alpha.

Mean of the worst alpha fraction, with the exact fractional-tail weight rather than a rounded count, so it agrees with _top_tail_mean's convention and is continuous in alpha. Differentiable: jnp.sort is a permutation, so this is a fixed linear functional of the order statistics almost everywhere. alpha = 1 gives the mean, alpha -> 0 the max.

nested_risk_certificate(xs, us, ensemble, alpha=0.2)

Check nested >= static >= risk-neutral, and that alpha = 1 collapses the three.

horizon_errors(model, states, actions, dt, horizon, *, stride=None)

The (W, horizon, n) errors of the model's open loop over one unit's logged windows.

Window i starts at t = i * stride (stride defaults to horizon, so the windows tile the log and each transition is in one) and runs the model's RK4 steps from the logged x_t under the logged u_t, ..., u_{t + horizon - 1}. Its row k - 1 is x_{t + k} - x_hat_{t + k}, the plant's state less the open loop's at step k. HorizonConformal.calibrate scores them.

Parameters:

Name Type Description Default
model Dynamics

the field the plan rolls out, read as chc.integrate.rollout reads it.

required
states ArrayLike

(T + 1, n), one unit's consecutive logged states.

required
actions ArrayLike

(T, m), the actions logged between them.

required
dt float

the step.

required
horizon int

the window's number of steps, at least 1.

required
stride int | None

the steps between window starts, at least 1.

None

Raises:

Type Description
ValueError

on states and actions of lengths that do not pair, a horizon or stride below 1, entries that are not finite, or a log too short for one window.

mixing_penalty(mixing, calibration, train_lag=None)

eta, the coverage that split conformal pays on one beta-mixing series.

Oliveira, Orenstein, Ramos and Romano (JMLR 2024, Theorem 4): on a stationary beta-mixing sequence, the score at a test index i falls within the empirical 1 - alpha quantile of calibration consecutive scores with probability at least 1 - alpha - eta, eta = eps_cal + eps_train + delta_cal, where eps_train = beta(i - n_train) and

eps_cal = inf over (a, m, r) of sigma(a) sqrt(4 L / (n - r + 1)) + L / (3 m) + (r - 1) / n

with L = log(4 / (delta_cal - 4 (m - 1) beta(a) - beta(r))), 2 m a = n - r + 1, delta_cal > 4 (m - 1) beta(a) + beta(r) and sigma(a) = sqrt(1/4 + (2 / a) sum_{j < a} (a - j) beta(j)). The theorem holds at every delta_cal > 0, so this takes the least eta over every block (a, m, r) and a grid of delta_cal: any point of it is a valid penalty, the least one the tightest found.

Parameters:

Name Type Description Default
mixing Callable[[int], float]

beta(j), the beta-mixing coefficient of the score sequence at a lag of j scores, in [0, 1] (the supremum over events of the gap between the joint law of the past and the future and their product, Bradley's convention). A value outside [0, 1] is clipped into it. gaussian_mixing gives a bound for windows of a stable Gaussian VAR(1).

required
calibration int

n, the number of consecutive calibration scores.

required
train_lag int | None

the lag, in scores, from the last score the model or the profile was fitted on to the test window, which adds beta(train_lag); None where they were fitted on data independent of the series, which adds nothing.

None

Raises:

Type Description
ValueError

on fewer than 2 calibration scores or a train_lag below 1.

gaussian_mixing(state_matrix, noise_covariance, *, stride=1, span=0)

A bound on the beta-mixing coefficient of a stable Gaussian VAR(1) s' = F s + w, w ~ N(0, Q), at a lag of j windows that start stride steps apart and each span span steps: beta(j * stride - span), or 1 where the windows meet.

For a stationary Markov chain beta(k) is the mean over the stationary law of the total variation from P^k(s, .) to it. By Pinsker's inequality and Jensen's, it is at most sqrt(E KL / 2), and for this chain E KL = -log det(I - S^-1 F^k S F^k') / 2, S the stationary covariance: beta(k) <= sqrt(-log det(I - S^-1 F^k S F^k')) / 2 (validation/tube_levels.mac). On one state of correlation rho it is sqrt(-log(1 - rho^(2k))) / 2.

s must be the whole state the scores are read off: on a log under a policy with its own persistence, the policy's state belongs in it.

Raises:

Type Description
ValueError

on a matrix that is not square, a covariance not of its size, not symmetric or not positive definite, a spectral radius of 1 or more, or stride below 1 or span below 0.

lipschitz_rollout_bound(lipschitz, model_error, dt, horizon)

Certified H-step trajectory-error bound from a Lipschitz field via discrete Gronwall.

Two Euler rollouts of an L-Lipschitz field, one perturbed per step by <= model_error, deviate by e_k obeying e_{k+1} <= (1 + L*dt)*e_k + dt*model_error, e_0 = 0, so

``e_H <= model_error * ((1 + L*dt)^H - 1) / L``   (``L>0``; the ``L->0`` limit is linear,
``model_error * dt * H``, no blow-up).

Turns the CERTIFIED constant L of LipschitzResidual (plus the trusted known-field norm) into a certified pessimism radius that propagates a per-step error BUDGET through time. This COMPLEMENTS (does not replace) chc.support.SupportModel: the support density-distance scores WHERE the one-step error model_error is large (off-support), and the bound propagates it (see support_calibrated_error). model_error should be a one-step bound (a conformal upper quantile or a bounded-disturbance envelope), not a validation average. Machine-checked in proofs/lipschitz_rollout.v (rollout_error_bound); derived in validation/lipschitz_rollout.mac. HONEST SCOPE: the bound is exp(L*T) (T = H*dt) -- tight for small L*T (bounded-gain residual, short horizon, safety-critical), loose else; a contraction metric (ContractiveResidual, log-norm mu<0) removes the exponential; the open loop assumes a FIXED action sequence -- for re-planning use closed_loop_rollout_bound; for per-step L_k use time_varying_rollout_bound. The recursion is explicit Euler's, so the bound holds for Euler rollouts only. Every plan of chc.plan.causal_plan rolls out by RK4, and there it is not a bound: x' = x against x' = x + 0.1 at dt = 1 reads 0.1, 0.3, 0.7 where the RK4 gaps are 0.1708, 0.6335, 1.8866. time_varying_rollout_bound's "rk4" recursion is the RK4 bound.

Raises:

Type Description
ValueError

if lipschitz or model_error is negative, infinite or nan, if dt is not a finite positive step, or if horizon is not a whole number of steps. A negative budget, step or horizon reads a negative radius, which certifies every step. A bound past the float range is inf.

lipschitz_rollout_certificate(seed=0, state_dim=2, horizon=8, dt=0.05, model_error=0.1)

Roll two fields differing by a bounded per-step error; confirm the deviation obeys the bound.

The field is f_known + r with f_known a linear map of known spectral norm and r a LipschitzResidual with certified constant L_r; L = ||A||_2 + L_r upper-bounds its x-Lipschitz constant. A fixed error of norm model_error is added each step (the learned part is the fragile one); the Euler deviation from a shared start stays under lipschitz_rollout_bound(L, model_error, dt, horizon).

contractive_rollout_bound(contraction_rate, lipschitz, model_error, dt, horizon)

UNIFORMLY BOUNDED explicit-Euler rollout radius for a CONTRACTING field (log-norm mu=-c<0).

The discrete Euler contraction factor is q = sqrt(1+2*mu*dt+L^2*dt^2) (NOT 1+mu*dt; L = the full Lipschitz constant), since two Euler steps deviate by |d+dt*(f(x)-f(y))|^2 <= (1+2*mu*dt+L^2*dt^2)|d|^2 (expanded in Maxima contractive_euler.mac; Rocq contractive_euler.v proves only that the factor's square is nonnegative and, under the step condition, below 1). Contraction (q<1) needs the step dt<2c/L^2 (sufficient, from the worst-case (mu,L) bounds); under it the discrete Gronwall bound e_H <= model_error*dt*(1 - q^H)/(1 - q) is capped at model_error*dt/(1-q) for ALL horizons -- no e^{L*T} blow-up -- tends to the continuous radius model_error/c as dt -> 0. The payoff of a certified negative log-norm (ContractiveResidual) over the non-negative ||.||-Lipschitz of LipschitzResidual; the q < 1 cap uses gronwall_bounded. Returns +inf if not contracting or the step is too large (dt >= 2c/L^2), where Euler overshoots.

Raises:

Type Description
ValueError

if contraction_rate is not finite, if lipschitz or model_error is negative, infinite or nan, if dt is not a finite positive step, or if horizon is not a whole number of steps.

contractive_rollout_certificate(seed=0, state_dim=3, horizon=60, dt=0.05, model_error=0.1)

Confirm a ContractiveResidual contracts and its radius stays flat.

Checks (i) the empirical one-sided Lipschitz <r(x)-r(y),x-y>/||x-y||^2 <= -rate (certified contraction), and (ii) the perturbed-rollout deviation stays under the BOUNDED explicit-Euler radius eps*dt/(1-q) (step dt<2c/L^2) even as the horizon grows -- contrasted with the e^{L*T} that the same field's norm-Lipschitz L would incur (lipschitz_blowup).

time_varying_rollout_bound(lipschitz, model_error, dt, *, integrator='rk4')

Per-step certified error tube e_0..e_H for time-varying L_k and BUDGET eps_k.

Two rollouts by integrator from one start, of an L_k-Lipschitz field and of the field off by at most eps_k wherever step k reads it, stay within e_k of each other, e_0 = 0:

  • "rk4", the integrator of chc.integrate.rollout and so of every plan: e_{k+1} = e_k + dt (L_k e_k + eps_k) phi(L_k dt), phi(z) = 1 + z/2 + z^2/6 + z^3/24, from bounding RK4's four stages one after another (Rocq rk4_rollout_error_bound, validation/rk4_rollout.mac). Its growth 1 + z phi(z) is RK4's stability polynomial, and on a linear scalar field with a constant error the tube is the two rollouts' gap exactly;
  • "euler": e_{k+1} = (1 + L_k dt) e_k + dt eps_k (Rocq gronwall_var_comparison), a bound on explicit-Euler rollouts only. On RK4 rollouts it is not one: x' = x against x' = x + 0.1 at dt = 1 reads 0.1, 0.3, 0.7 where the RK4 gaps are 0.1708, 0.6335, 1.8866.

Unlike the constant-L lipschitz_rollout_bound, this exposes WHICH step / channel drives the growth -- feed certified_horizon for the honest certified_until_step. eps_k is a budget: it should be a CERTIFIED per-step bound (a conformal quantile, a bounded-disturbance envelope, or support_calibrated_error combining a base error with chc.support.SupportModel), not a validation-set average.

Raises:

Type Description
ValueError

if an L_k is negative, infinite or nan. L_k bounds ||f(x) - f(y)|| / ||x - y||, which no field takes below zero; a contracting field's negative log-norm shrinks a tube only through linear_rollout_bound's matrices or contractive_rollout_bound. In either recursion it can turn the radii negative, which would certify every step, and an infinite one reads inf * 0, a nan. Also if an eps_k is negative, infinite or nan, which no budget is, or if dt is not a finite positive step.

certified_horizon(lipschitz, model_error, dt, tolerance, *, integrator='rk4')

The largest step H whose certified error e_H stays within tolerance.

Past it the plan is flagged uncertain; e is monotone, so this is the first crossing. A radius that overflows to inf is within no tolerance, inf included. The tube is time_varying_rollout_bound's for integrator, which raises as it does; a tolerance that is negative or nan raises too.

linear_rollout_bound(state_matrix, model_error, dt)

The RK4 error tube e_0..e_H of a field affine in the state, x' = A x + g(t, u).

Two RK4 rollouts from one start, of the field and of the field off by at most eps_k wherever step k reads it, under the same actions, stay within

``e_k = sum_{j<k} eps_j g_{k-1-j}``,  ``g_m = dt sum_i ||R(dt A)^m c_i(dt A)||_2``,

R(z) = 1 + z + z^2/2 + z^3/6 + z^4/24 being RK4's stability polynomial and c_1..c_4 the weights its stages put on the field's errors, (1 + z + z^2/2 + z^3/4)/6, (2 + z + z^2/2)/6, (2 + z)/6 and 1/6, which sum to phi: one step's gap is exactly R(dt A) e + dt sum_i c_i(dt A) delta_i (validation/rk4_rollout.mac). The matrices, not a norm of A, carry the growth, so a contracting A shrinks the tube where a norm-Lipschitz one could only widen it; on a scalar A = L >= 0 it is time_varying_rollout_bound's RK4 tube.

Raises:

Type Description
ValueError

if state_matrix is not a finite square matrix, an eps_k is negative, infinite or nan, or dt is not a finite positive step.

closed_loop_rollout_bound(state_lipschitz, control_lipschitz, policy_lipschitz, model_error, dt, horizon)

Closed-loop rollout radius when the plan is RE-PLANNED each step by an L_pi-Lipschitz pi.

A state error perturbs the action, which perturbs the next state, so the growth rate is L_x + L_u*L_pi (not L_x alone): e_{k+1} <= (1 + dt(L_x + L_u*L_pi)) e_k + dt*eps. Reduces to lipschitz_rollout_bound with the combined constant, and so bounds Euler rollouts only, not the RK4 rollouts every plan of chc.plan.causal_plan and chc.mpc.RecedingHorizon makes, whose gap it can read below. CAVEAT: for a clipping / active-set / threshold MPC L_pi may be unbounded (not globally Lipschitz); use this only where the controller is Lipschitz (a fixed feedback gain, or a smooth relaxation).

Raises:

Type Description
ValueError

if a Lipschitz constant is negative, infinite or nan: a negative one lowered the combined rate below the state's own. Otherwise as lipschitz_rollout_bound.

support_calibrated_error(base_error, scale, support_distances)

Per-step error BUDGET eps_k = base_error + scale * D(x_k, u_k) from a support distance.

This COMBINES (does not replace) chc.support.SupportModel: the certified rollout bound propagates a per-step budget through time, and the SupportModel says WHERE that budget is large (off-support, where the one-step model error grows). SupportModel scores the local risk, the Gronwall tube propagates it.

constraint_margin(nominal_g, lipschitz_g, error_radii)

Tightened constraint margin g(x_hat_k) + L_g * e_k for an L_g-Lipschitz constraint.

By Rocq constraint_tightening, if this margin is <= 0 at step k then the TRUE trajectory (within the certified radius e_k of the nominal x_hat_k) satisfies g(x_k) <= 0 -- the tube becomes a robust feasibility check. Admissible while all <= 0.

time_varying_rollout_certificate(seed=0, horizon=20, dt=0.05, tolerance=0.3)

Rising per-step L_k + a bumpy budget: the tube stays under the constant-max-L bound.

Identifies certified_until_step and the safety margin gives a safe_until_step cutoff.

confounding_robust_inflation(cvar_upper, cvar_lower, gamma)

MSM confounding inflation (Gamma-1)/(Gamma+1) * (CVaR_up - CVaR_lo) over a point effect.

Under a BOUNDED DENSITY-RATIO sensitivity model (the weight lies in [1/Gamma, Gamma] with mean 1 -- a marginal, covariate-unconditional special case of Tan's MSM, whose full form constrains the treatment-assignment odds with propensity/covariate-dependent bounds) the sharp worst-case E[wY] puts w=Gamma on the top-tau tail (tau=1/(Gamma+1), mean-preserving) and w=1/Gamma elsewhere. The gap over the nominal mean is this closed form (Maxima confounding_robust_cvar.mac; Rocq msm_inflation_*): 0 at Gamma=1 (point ID), nonnegative, monotone in Gamma. Dorn-Guo (2023); Oprescu et al., B-Learner (2023); Tan (2006).

For a continuous lever the same closed form is the sharp bound per covariate value x on the mean outcome at one dose level under the continuous MSM (Jesson et al. 2022; Frauen, Melnychuk and Feuerriegel 2023, Thm 1), read on the tails of Y | x. Read on a pooled sample it relaxes E[w | x] = 1 to E[w] = 1: still valid, and wider by sd(Y) / sd(Y | X), 1 / sqrt(1 - R^2) in a Gaussian location model, 1.41 at R^2 = 0.5 and 4.47 at 0.95 (validation/msm_level_bound.mac); msm_worst_case_mean's covariates reads the residual's tails instead, and its covariate_form="quantile" the tails of Y | x about a linear conditional quantile.

It bounds a level, not a slope: a contrast of two levels is bounded by the upper bound at one less the lower bound at the other (Frauen et al., Lemma 3). A channel radius spent as radius * ||u|| (ConfoundingRobustPenalty) is a structural sensitivity model of its own, not the MSM's bound.

msm_worst_case_mean(outcomes, gamma, *, covariates=None, propensity=None, covariate_form='residualised')

Sharp MSM worst-case (upper) mean of outcomes over the [1/Gamma, Gamma] weight box.

The confounding-robust pessimistic value a controller should plan against when the treated outcome sample may be confounded up to sensitivity Gamma. Equals mean + inflation with the CVaR tails of confounding_robust_inflation; reduces to the sample mean at Gamma=1.

The pooled sample's tails are sharp for a weight with E[w] = 1; the MSM's weight has E[w | x] = 1 for each covariate value, and its sharp bound reads the tails of Y | x (Dorn and Guo, JASA 2023). covariates, one row per outcome, take a prediction m(x) out of the tails: mean(Y) + inflation(Y - m(X)), which stays valid for any fixed m since E[w m(X)] = E[m(X)], and is sharp where the residual's law does not move with x. The prediction is least squares on (1, covariates), cross-fitted over 5 interleaved folds: one fitted on its own rows reads the residual's tails narrower than they are. With R^2 the covariates' share of the outcome's variance, a Gaussian location model's bound narrows by sqrt(1 - R^2).

propensity reads Gamma on Tan's (2006) scale for a binary lever, a bound on the odds of the arm, as benchmark_gamma measures it: the weight e(x) / e(x, U) lies in [e + (1 - e) / Gamma, e + (1 - e) Gamma], e the probability of the arm the outcomes were observed under, one number or one per outcome. The bound is then the largest mean of w (Y - m(X)) over those boxes unit by unit with mean(w) = 1, a fractional knapsack; at one e its tail is still 1 / (Gamma + 1) and its inflation (1 - e) times the box's (validation/msm_level_bound.mac). Without it the box [1/Gamma, Gamma] is that of a continuous dose, and on a binary lever's odds it overstates the inflation by 1 / (1 - e).

covariate_form="quantile" takes the conditional quantile of Y | x out of the tails in place of a mean, Dorn and Guo's quantile balancing. For any q(x) and a weight in the box [lo, hi] with E[w | x] = 1, E[w Y] <= E[psi], psi = q + lo (Y - q) + (hi - lo) (Y - q)_+, with equality at the quantile at level Gamma / (Gamma + 1), for the box and for Tan's alike. mean(psi) - mean(Y) is the pinball loss at that level weighted by hi - lo, so q, linear in (1, covariates), is a weighted quantile regression (Koenker and Bassett 1978), a linear program solved by HiGHS on the 5 folds each outcome is not in. The bound is psi's mean on the held outcomes and never the program's optimum: psi bounds the mean for any q, so the solver's tolerance costs sharpness and not validity. It is sharp per x where that quantile is linear in the covariates and valid otherwise, and it reads a spread of Y | x that moves with x, which the residualised form pools: at Gamma = 2 the residualised inflation is 1.064 times the per-x one on two equal cells of sd 0.3 and 3 and 1.25 on two-point cells, and on Y = 2X + (1 + 2X) eps, X ~ U(0, 1), its bound is 2.0998 where the per-x one is 2.0908 (validation/msm_quantile_balancing.mac). It costs 5 linear programs of n units each, one a fold, at each Gamma, none at Gamma = 1, where it is the mean. Its limits: a quantile that is not linear in the columns passed leaves it valid but wider than the per-x bound, and the columns must carry the basis expansion, as for the residualised form; each fold fits p + 1 coefficients out of sample, which widens it as p grows; where the spread does not move with x it buys nothing over the residualised form, whose threshold is read in sample where its own is cross-fitted; and its growth with Gamma is checked, not proved. psi grows with Gamma at a fixed quantile, but the quantile is refitted at each Gamma and its sampling error moves the bound both ways: on 20 samples of 60 rows with two covariates and a heavy-tailed spread that moves with one, the bound fell between neighbouring values of Gamma 0.025 apart in 3 of them, by up to 0.038, and on 10 samples of 400 rows in none. confounding_robust_radius reads its running maximum over Gamma.

outcomes are one per unit, of shape (n,) or the column (n, 1).

Parameters:

Name Type Description Default
covariate_form Literal['residualised', 'quantile']

what covariates take out of the tails. "residualised", the default, a least-squares prediction of the mean; "quantile", experimental, a linear conditional quantile at level Gamma / (Gamma + 1), which needs covariates and reads propensity as the default does.

'residualised'

Raises:

Type Description
ValueError

when outcomes have another shape, none, or one not finite, Gamma is below 1 or not finite, covariates do not have one row a outcome or are not finite, there are too few outcomes to cross-fit their coefficients, propensity is not one number or one per outcome in (0, 1), or covariate_form names neither form or is "quantile" without covariates.

RuntimeError

when HiGHS leaves a quantile regression unsolved.

confounding_robust_radius(nominal_radius, outcomes, gamma, *, covariates=None, propensity=None, covariate_form='residualised')

Inflate a pessimism radius by the MSM confounding gap: rho0 + (worst_case - mean).

The returned radius is never below nominal_radius (pessimism only grows under assumed confounding) and is monotone in Gamma: the worst case is a maximum over the weight box [1/Gamma, Gamma], which holds the unit weight and grows with Gamma. Rocq robust_radius_ge_nominal / robust_radius_monotone prove both for the closed form at a fixed tail gap; here the tail, and so the gap, moves with Gamma, which those lemmas do not cover. Feeds chc.support.pessimistic_control as a widened uncertainty budget. outcomes, covariates and propensity are msm_worst_case_mean's, refused as it refuses them.

Under covariate_form="quantile" the worst case refits its quantile at each Gamma, and the refit can make it fall as Gamma grows (msm_worst_case_mean), so the radius reads its running maximum over Gamma' <= Gamma. The quantile is cross-fitted at each Gamma_k = 2^(k/4), k >= 1, up to the first at or above Gamma, and each fit's psi is read at min(Gamma_k, Gamma). psi bounds the worst case at its own Gamma' <= Gamma for any quantile, and the worst case grows with Gamma, so each term is a valid bound below the one at Gamma; at a fixed quantile psi grows with Gamma, so the maximum grows with Gamma without exception. At each Gamma_k it is the largest of msm_worst_case_mean's bounds at Gamma_1, ..., Gamma_k, never below the one at Gamma_k. Between them, the top term reads the quantile fitted at the Gamma_k above Gamma, which costs sharpness at second order in the level and not validity: on 10 samples of 2000 rows of Y = 2X + (1 + 2X) eps, X ~ U(0, 1), the radius's inflation read 0.13 %, 0.26 % and 0.01 % above the pointwise bound's at Gamma 2.2, 2.5 and 2.8, on average. On few rows two cross-fitted reads of one bound differ by more than that, and either can be the larger: on msm_worst_case_mean's 20 samples of 60 rows it read below the pointwise bound at 759 of 1620 values of Gamma, by up to 0.12. It costs 5 linear programs a Gamma_k, 35 at Gamma = 3.

Parameters:

Name Type Description Default
covariate_form Literal['residualised', 'quantile']

msm_worst_case_mean's, "residualised" by default. "quantile", experimental, takes a linear conditional quantile of the outcome out of the tails, at 5 linear programs, one a fold; it needs covariates.

'residualised'

confounding_robust_certificate(seed=0, n=8, gamma=3.0)

Confirm the CVaR closed form matches the sharp LP worst-case on a mean-preserving grid.

Chooses (n, Gamma) so tau*n = n/(Gamma+1) is an integer, making the sharp box-LP optimum a pure top-tau*n assignment (weight Gamma on the largest points, 1/Gamma on the rest) that a brute-force sort computes exactly -- a real check, no LP solver needed.

confounding_robust_closed_loop_bound(state_lip, control_lip, policy_lip, base_error, control_magnitude, cvar_gap, gamma, dt, horizon)

Closed-loop rollout radius with the per-step budget inflated by MSM confounding.

Composes the MSM confounding radius with the closed-loop replan tube: the growth rate is L_x + L_u*L_pi (re-planning feeds state error through an L_pi-Lipschitz policy). The MSM half-width Delta_B = confounding_robust_inflation(cvar_gap, 0, gamma) is an effect (B) error; the per-step state-transition error it induces is ||Delta_B * u_k|| <= control_magnitude*Delta_B, so the budget is eps_k = base_error + control_magnitude*Delta_B (the action multiplier makes the units match -- effect error times control is a state error). gamma=1 recovers the plain closed-loop tube. Rocq closed_loop_confounding_monotone: the tube is monotone in the confounding at every horizon. Like closed_loop_rollout_bound, it bounds Euler rollouts only, not a plan's RK4 one.

confounding_robust_closed_loop_certificate(gamma=3.0, horizon=25, dt=0.05)

Show the MSM-inflated closed-loop tube widens and its safe horizon shrinks with Gamma.

A re-planning controller (L_pi-Lipschitz policy) on an L_x/L_u plant, a nominal margin to a constraint g <= 0: as the assumed MSM sensitivity Gamma grows the confounding-inflated tube eats the margin sooner, so the safe planning horizon contracts.

confounding_cost_bound_certificate(radii=(0.005, 0.01, 0.02, 0.05, 0.1, 0.2), horizon=20, dt=0.05, restarts=6, ascent_steps=250, seed=0)

Try to break ConfoundingRobustPenalty.certified, and report where it bends.

A two-lever damped oscillator, planned to optimality, then attacked: the adversary picks the control-channel error M with ||M||_2 <= radius that moves the objective most, by projected gradient ascent from several starts on both signs of Delta J. Random sampling was the first version and it is not good enough -- in four parameters it underestimates the worst case by enough to hide a violated bound.

Two ratios are reported because they answer different questions. ratio is the certificate: realised over the full second-order weight, and ok demands every entry stay at or below one. first_order_ratio is the diagnostic that motivated the second-order term: it exceeds one at every radius, which is why ||lambda|| alone was a calibrated estimate, not a bound.

benchmark_gamma(treated, covariates, assumed_gamma, names=None, quantile=0.95, ridge=1e-06)

Price an assumed MSM Gamma against the observed covariates, in MSM units.

Gamma is the analyst's input. It is unfalsifiable; it is not uncalibrated. The MSM bounds the assignment odds ratio between the true propensity and the modelled one uniformly over units, and dropping an observed covariate produces exactly such a pair -- so

``Gamma_j = exp( quantile_i | logit e(x_i) - logit e_{-j}(x_i) | )``

is the sensitivity a confounder as strong as covariate j would generate, measured rather than assumed.

quantile = 1.0 is the MSM's own quantity and it is not the default, because it grows with the sample. The model bounds the odds ratio uniformly over units, so the sup is the faithful statistic -- but under an unbounded covariate the sup is an extreme order statistic. Measured on a standard-normal design, the sup runs 309 -> 382 -> 397 -> 734 as n goes 500 -> 4000 -> 32000 -> 128000, while the 95th percentile sits at 22, 24, 19, 19 and the median at 2.7, 3.0, 2.7, 2.8. A benchmark that quadruples because more data arrived is not a benchmark, so the default reports a quantile and says which one; pass quantile=1.0 when the uniform bound is the point and the covariates are bounded.

multiples_of_strongest then reads Gamma as "an unobserved confounder k times as strong as the strongest thing we did observe", on the log scale odds ratios compose in. A k far below 1 is an assumption nobody should be impressed by; a k far above 1 is one the analyst has to defend.

SCOPE. Per-covariate and one-at-a-time: this is the marginal strength of each covariate, not a policy-level aggregation over a set of them, and the two differ whenever covariates are correlated. Dropping a covariate from the propensity is a benchmark, not a claim that the unobserved confounder resembles it. The propensity is logistic-linear in the columns as passed; a benchmark is only as good as that model, which is why the covariates should already carry the basis expansion the analyst believes.

ridge penalises each slope of the propensity in units of its column's variance, so an implied Gamma reads the same in any units and from any origin of the covariates.

negative_control_gamma(outcomes, tol=1e-09, gamma_max=1000000.0, *, level=None, covariates=None, propensity=None, covariate_form='residualised')

Smallest Gamma whose MSM interval covers zero on a KNOWN-NULL outcome.

The other half of calibration, and the half that can refute. On an outcome whose true effect is zero, any nonzero mean is confounding, so the smallest Gamma whose interval over the population covers zero is a lower bound on the confounding actually present. That transfers to the outcome of interest only when the control is U-comparable, confounded by the same unobserved causes (Lipsitch, Tchetgen Tchetgen and Cohen 2010). A control confounded by more than the outcome overstates the outcome's Gamma, and one confounded by less understates it (Baitairian et al., arXiv 2510.16560).

Without level this returns that Gamma read off the sample: a point estimate of it, not a refutation. The sample's mean is never exactly zero, so it reads above 1 on every sample of an unconfounded null, 1000 of 1000 at each size from 30 to 1600, and it holds the population's Gamma on about half of the samples of a confounded one. Monotonicity of the MSM inflation in Gamma makes the search a bisection, exact to tol.

With level it returns a one-sided lower confidence bound on it, and the bound is what refutes: assuming less confounding than it is refuted by the data at level. It is the smallest Gamma at which the binding endpoint, widened by z of its standard errors, reaches zero, z Student's t quantile of n - 1 degrees of freedom at (1 + level) / 2: half the miss goes to each endpoint, since which one binds is read off the sample's sign, and at Gamma = 1 the bound leaves 1 exactly where the two-sided t test of a zero mean rejects. The endpoint is the mean of y / Gamma + (1 - 1/Gamma) (q + (Gamma + 1) (y - q)_+) at the sample's upper 1/(Gamma + 1) quantile q (Rockafellar and Uryasev 2000), so its standard error is that term's over sqrt(n), the quantile's own error dropping out at first order. The same bisection searches the widened endpoint. On 1000 samples a cell at level = 0.95, of normal noise and of exponential noise skewed either way, the bound read above 1 on 4.8 % to 6.2 % of an unconfounded null at sizes 100 to 1600, and held the population's Gamma on at least 94.6 % under planted biases of 0.2 and 0.5 standard deviations. The level is asymptotic: at n = 30 under the exponential's skew the null read above 1 on 8.1 % and 8.5 %, and a bias's Gamma held on 91.1 % at worst. Under Student-t noise of 2 degrees of freedom, which has no variance, the null read above 1 on 3.0 % to 4.9 %, and a bias's Gamma held on 93.5 % to 96.0 %.

Returns inf when no Gamma up to gamma_max reconciles the null -- the endpoint saturates at the extreme order statistic as Gamma -> inf, so a sample whose values all share the mean's sign cannot be pulled across zero by a bounded density ratio at all, and the negative control has refuted the model class instead of calibrating it (at level, where given).

The interval is NOT symmetric about the mean, and which endpoint has to travel depends on the sign of the estimate: a positive estimate is reconciled by the lower endpoint reaching zero, a negative one by the upper. Reflecting the sample by -sign(mean) maps both onto the single upper-endpoint routine msm_worst_case_mean computes, which is why the sharp CVaR tails are used in the direction that actually binds rather than the convenient one.

covariates and propensity are msm_worst_case_mean's. Without covariates the reading falls as they explain more of the control outcome, at the same confounding: a null of mean 0.2 and residual spread 1 reads 1.285, 1.194, 1.119 and 1.058 at R^2 0, 0.5, 0.8 and 0.95 (validation/msm_level_bound.mac), a property of the covariates and not of the confounding; with them it reads 1.285 at each. At level the endpoint's standard error is that of each unit's prediction plus its residual's term, and leaves out the prediction's own error, which enters at first order only where the residual's law moves with the covariates. outcomes are msm_worst_case_mean's, refused as it refuses them.

covariate_form="quantile" reads the endpoint with msm_worst_case_mean's quantile form, refitting the quantile at each Gamma the bisection visits: 5 linear programs a Gamma, about 5 log2(gamma_max / tol) in all, 250 at the defaults. At level the endpoint's standard error is its psi's over sqrt(n): the quantile's own error moves the endpoint at second order (Dorn, Guo and Kallus, JASA 2025). psi grows with Gamma at a fixed quantile, but the quantile is refitted at each, so the endpoint need not be monotone; the bisection then returns one Gamma at which it crosses zero.

Parameters:

Name Type Description Default
covariate_form Literal['residualised', 'quantile']

msm_worst_case_mean's, "residualised" by default. "quantile", experimental, needs covariates and costs 5 linear programs at each Gamma the search visits.

'residualised'

gamma_benchmark_certificate(strengths=(0.25, 0.5, 1.0, 2.0), sizes=(500, 4000, 32000), biases=(0.1, 0.2, 0.4), quantile=0.95, samples=4000, seed=0)

Check that the benchmark measures confounding strength and that the calibration binds.

Five gates, each able to fail:

  1. Monotone in strength. A covariate whose logit coefficient grows induces a larger implied Gamma. A benchmark that does not order confounders by strength orders nothing.
  2. The null covariate's score is a root-n noise floor. Dropping a coefficient that is truly zero must not manufacture sensitivity beyond sampling noise -- and "beyond sampling noise" is a rate, not a constant, so the gate is that log(Gamma_null) * sqrt(n) stays bounded as n grows rather than that a single draw sits below a fixed number. Measured on six seeds per size, that product runs 2.1, 4.0, 5.0, 4.4 at n = 1000 .. 64000 while Gamma_null itself falls 1.069 -> 1.017; a single draw of 1.27 at n = 4000 is inside that distribution, which is exactly why one draw cannot be the gate.
  3. Ranking. On one design carrying strong / weak / null covariates, the implied Gamma ranks them in that order.
  4. The reported quantile is stabler in n than the sup. This is the measurement the default rests on, so it is run rather than remembered: the sup is an extreme order statistic under an unbounded covariate and grows with the sample; the quantile should not.
  5. The negative control lands on the endpoint, and grows with the planted bias. At the returned Gamma the binding interval endpoint sits at zero to solver tolerance, and a larger planted bias needs a larger Gamma -- plus inf when the sample cannot be reconciled at all.