chc.barrier¶
Stability tier: stable.
Safety certificates when the control effect is only PARTIALLY IDENTIFIED.
The pessimism line (chc.support, chc.uncertainty) spends an identification radius on
performance: a worse effect estimate buys a wider penalty and a costlier plan. This module spends
the same radius on safety, and the accounting is different in a way that matters operationally.
For a control-affine plant xdot = f(x) + B u and a safe set {h >= 0}, the barrier condition
is grad h . (f + B u) >= -alpha * h. Write a = grad h . f for the drift term, g for the
control channel and U for the actuation limit. If the effect matrix is known only up to a radius
Delta -- here an identification radius from the bounded-density-ratio model at level
Gamma, not a disturbance bound -- the guaranteed barrier derivative is a + g*u - d*|u| with
d = Delta * ||grad h||, and:
- the best guaranteed margin is
a + (|g| - d)_+ * U, so the margin lost to an identification radiusdisU * min(d, |g|)-- first order indwhile control authority lasts, then flat: pastd = |g|there is nothing left to lose; - at
d >= |g|the robust-optimal action is exactly zero: with the sign of the channel unidentified, acting cannot improve the guarantee (the safety analogue of the sign threshold ofchc.research.regret.partial_id_control_certificate); - certification is sharp at
d* = |g| - D/U, whereD = -alpha*h - ais the deficit the drift leaves for the controller, which inverts to a largest tolerable sensitivityGamma*. Three regimes, and only the third is the interesting one:D <= 0(the drift alone is safe, no radius can break it),D > U*|g|(nominally infeasible -- not certified even atd = 0), and0 < D <= U*|g|(d*in[0, |g|), the case the threshold formula describes).
The tightening itself is the standard robust-CBF one (Jankovic 2018; Kolathaya-Ames 2019). What is
new here is the source of the radius and the resulting order dichotomy: the same effect error
costs performance regret only at second order (L_reg * e**2): an interior optimum has a
vanishing gradient, while a binding constraint has no envelope protection and pays at first
order. Objectives are protected; constraints are not. That comparison lives in d < |g|, which is
also where any usable controller lives -- once the radius exceeds the channel the safety loss is
capped at U*|g| simply because the guarantee is already gone. Within that band, and below
e = U / L_reg, safety is the larger loss by a ratio that diverges as the error shrinks.
Uncertainty-set assumption. a + <w, u> - d*||u|| is the worst case for a symmetric,
isotropic set: ||u||_2 <= U for the action and a dual-norm ball of radius d for the channel
error. It is exact there (Cauchy-Schwarz is attained). For box actuation limits or anisotropic
channel uncertainty the worst case is the corresponding support function and the closed forms below
are only an outer bound. For an asymmetric scalar interval g_true in [g - d_lo, g + d_hi] the
two branch slopes differ (g - d_lo right, g + d_hi left) and the zero-action rule reads in
its general form: acting is pointless exactly when the identified interval contains zero.
NumPy, like the rest of chc.research.sensitivity, so it is independent of the JAX x64 flag.
Maxima validation/barrier_feasibility.mac, Rocq proofs/barrier_feasibility.v.
The plant's noise, read apart (experimental). exit_probability bounds the chance that
a discrete-time closed loop leaves a QuadraticBarrier's safe set within K steps under
its noise, where the barrier holds in expectation, E[h(x') | x] >= alpha h(x) + slack: Ville's
inequality on Kushner's supermartingale, as Cosner, Culbertson, Taylor and Ames state it (RSS 2023,
Thm 5). It reads a feedback law and refuses an open-loop plan, and it is no part of any audit of
the deterministic condition above. Maxima validation/exit_probability.mac.
BarrierConfoundingCurve
dataclass
¶
Measured evidence for the first-order safety loss over a sensitivity grid on one problem.
SafetyFilterBenchmark
dataclass
¶
Closed-loop evidence for the claim that a regret-sized budget is not a safety budget.
QuadraticBarrier
dataclass
¶
h(x) = upper - (x - centre)' shape (x - centre), safe where h >= 0.
shape is symmetric positive semidefinite, so h exceeds upper nowhere: the bound
exit_probability needs on the whole state space. Positive definite, the safe set is an
ellipsoid; of lower rank, a slab or a cylinder, unbounded along shape's null space. An
affine barrier has no such bound and is not one of these; a half-space is read through a slab
inside it, which the loop leaves whenever it leaves the half-space.
Raises:
| Type | Description |
|---|---|
ValueError
|
on an |
__call__(x)
¶
h at the state x.
ExitProbability
dataclass
¶
A bound on the chance that a closed loop leaves {h >= -level} within steps steps.
bound is at least P(min_{k <= steps} h(x_k) < -level) from the start, by Ville's
inequality on Kushner's supermartingale, under E[h(x_{k+1}) | x_k] >= alpha h(x_k) + slack
and h <= upper; it is clipped at 1, where the theorem says nothing. Read scope before
the number. "everywhere": the drift condition holds at every state, exactly, on an affine
loop. "states": it was read at the states given, and the bound holds only if no state the
loop visits before it leaves has a smaller margin -- nothing checks that between them.
control_channel(grad_h, b_hat)
¶
||B^T grad h|| -- how strongly the control can move the barrier, in the best direction.
The multivariate stand-in for the scalar |g|. Cauchy-Schwarz is tight at
u = U * w / ||w||, so every bound below is attained rather than conservative.
robust_barrier_margin(drift, channel, radius, u_max)
¶
Best barrier derivative guaranteed against every effect inside the identified set.
drift + (channel - radius)_+ * u_max. The clip at zero is the whole content: past
radius = channel extra actuation buys nothing, because the adversary can cancel it. So the
margin lost relative to a perfectly identified channel is u_max * min(radius, channel) --
first order in the radius until the authority runs out, then constant. Exact for a Euclidean
action ball and an isotropic channel radius (see the module docstring).
robust_safe_action(grad_h, b_hat, radius, u_max)
¶
The action attaining robust_barrier_margin: full authority, or nothing at all.
Returns exactly 0 when radius >= ||B^T grad h||. That is not a numerical artefact and
not conservatism -- it is the optimum: with the channel's sign unidentified, every nonzero
action has a worst case at least as bad as standing still.
identification_radius_threshold(drift, channel, u_max, alpha_h)
¶
Largest radius d* whose safety certificate still holds: channel - D / u_max.
D = -alpha_h - drift is the deficit the drift leaves for the controller to cover, and the
answer is piecewise in it -- the formula alone is a trap, because it happily returns a
negative "largest radius" for a problem no radius can save:
D <= 0-- the uncontrolled system already satisfies the barrier. No radius can break it, so the threshold is vacuous andinfsays so rather than inviting a comparison.D > u_max * channel-- nominally infeasible: even a perfectly identified channel at full authority cannot cover the deficit, so nothing is certified, not even atradius = 0.nan(the module's empty-set convention, as inadmissible_action_interval).0 < D <= u_max * channel-- the case worth having a threshold for:d*lands in[0, channel)and certification holds iffradius <= d*.
barrier_gamma_star(threshold_radius, cvar_gap, grad_norm)
¶
Largest MSM Gamma a safety certificate survives: (gap + c) / (gap - c).
Inverts Delta(Gamma) = (Gamma-1)/(Gamma+1) * cvar_gap at threshold_radius, with
c = threshold_radius / grad_norm the effect-space radius the barrier can absorb. The closed
form is only valid on 0 < c < cvar_gap; outside it the four cases are genuinely different
answers rather than edge-case noise, and the denominator would silently change sign:
c < 0(ornan) -- nothing is certified, not even atGamma = 1where the radius is zero.nan, because noGamma >= 1works and reporting1.0would claim the opposite.c == 0-- exact identification and nothing more:1.0.0 < c < cvar_gap-- the finite ceiling(gap + c) / (gap - c).c >= cvar_gap--Deltasaturates atcvar_gapasGamma -> inf, so the threshold is beyond anything the sensitivity model can produce:inf.
grad_norm == 0 is a state where the barrier is flat, such as the centre of a ball, and there
the radius Delta * grad_norm is zero at every Gamma: the step holds at every level or at
none, inf when threshold_radius >= 0 and nan otherwise.
admissible_action_interval(channel, radius, u_max, drift, alpha_h)
¶
The scalar actions whose guaranteed barrier derivative clears -alpha_h.
channel is the signed grad h . B, unlike the norm taken by
robust_barrier_margin -- which way to push is the whole question here. The guaranteed
derivative drift + channel*u - radius*|u| is concave in u, so the admissible set is an
interval; combined with |u| <= u_max it stays one. Returns an empty interval as
(nan, nan) when no admissible action exists, which the caller must handle rather than
silently clip into.
A non-positive deficit means u = 0 is admissible -- it does not mean every action is.
The control that serves the task is exactly the one that can spend the drift's slack and cross
the boundary, so both ends are computed from the branch slopes in every case.
robust_safety_filter(u_nominal, channel, radius, u_max, drift, alpha_h)
¶
Least-restrictive admissible action: the nominal, clipped into the certified interval.
Minimal intervention in the exact sense -- among all actions whose guaranteed margin clears, the
one closest to what the task controller asked for. Scalar control only: for m > 1 inputs the
same set is convex but its projection is no longer a clip, and a filter that quietly over-brakes
would misreport the price of safety. Use robust_safe_action there, which maximises the
margin rather than tracking a nominal.
When the interval is empty -- the deficit exceeds what the identified channel can deliver -- the
margin-maximising action sign(channel)*u_max is returned: it does not certify, and the
caller should already know that from identification_radius_threshold.
barrier_confounding_certificate(channel=0.6, drift=-0.9, u_max=2.0, alpha_h=0.5, cvar_gap=1.0, grad_norm=1.0, l_reg=3.0, gammas=(1.0, 1.5, 2.0, 3.0, 5.0, 9.0))
¶
Sweep the sensitivity level and check the threshold, the zero-action rule and the orders.
The defaults are chosen so the sweep crosses every regime rather than sitting inside one: the
drift is in deficit (D = 0.4 > 0) so the controller is load-bearing, Gamma* = 7/3 falls
inside the grid so certification genuinely fails partway, and the radius overtakes the channel
at Gamma = 4 so the tail of the grid exercises the zero-action rule. A configuration with
D <= 0 would certify everything and prove nothing.
safety_filter_benchmark(b_true=1.0, kappa=-0.5, confounding=1.0, gamma=3.0, decay=0.3, x0=0.0, x_ref=3.0, x_limit=2.0, alpha=1.0, dt=0.1, n_steps=60, u_max=6.0, n_data=4000, seed=0)
¶
Drive a confounded plant at a reference beyond a safety limit, four ways.
The scalar plant x' = decay*x + b_true*u must track x_ref while respecting
x <= x_limit, and the two are in conflict by construction -- the reference sits past the
limit, so nothing but the constraint stops the controller. The drift is unstable (decay >
0), which is what makes the threshold bite: near the limit the plant pushes outward on its
own, so the controller has a real deficit to cover and Gamma* is finite. The actuator gain
is calibrated from an observational log whose action responded to a latent driver (kappa < 0
attenuates it), so the controller believes a weaker actuator than it has and over-commands.
The four rows are the point:
oraclefilters with the true gain and a zero radius -- the best achievable safe tracking;safety_calibratedfilters with the biased gain and the MSM radius atgamma;regret_calibratedshrinks its action by the second-order regret accounting instead -- the radius spent on the objective, which is what the pessimism line does;greedybelieves the biased gain and does nothing about it.
Returns violation rate, worst excursion and tracking cost for each. Read the tracking column
with its floor in mind: a controller that respects the limit cannot beat
(x_limit - x_ref)**2 on this plant, so the violators' lower cost is bought with the
excursions in the other two columns and is not evidence that they control better. This is a
demonstration on one synthetic plant, not a theorem: it grounds the order argument rather
than proving it.
exit_probability(barrier, plant, policy, x0, *, steps, alpha, level=0.0, states=None)
¶
How likely a closed loop is to leave a barrier's safe set within steps steps: a bound.
The loop is plant under the state feedback policy, x' = a x + b u(x) + offset + w,
the noise w independent of the past and of the state, with mean 0 and covariance
plant.noise, plus b Sigma b' for an affine policy's own covariance Sigma. On a
quadratic barrier the next state's mean barrier needs that covariance alone,
E[h(x') | x] = h(m(x)) - tr(shape Cov(w)) with m(x) the loop's mean step, so the drift
condition E[h(x') | x] >= alpha h(x) + slack is read exactly, without sampling the noise:
- an
AffinePolicycloses an affine loop,x' = F x + f + w, on which the marginE[h(x') | x] - alpha h(x)is a quadratic inx. Its least value over the whole state space isslack(scope="everywhere"), the premise as Cosner et al. state it. Where the quadratic falls without bound --alpha shape - F' shape Fhas a negative direction, or a flat one along which the margin still slopes -- no slack holds and the call refuses. - a callable
u = policy(x), a safety filter around a nominal controller say, is read atx0and at each row ofstates(scope="states"), andslackis the least margin there. The bound then holds if no state the loop visits before it leaves{h >= -level}has a smaller margin, which nothing checks between the states given.
slack is capped at upper (1 - alpha), as the theorem asks. With
h0 = h(x0) and phi = upper (1 - alpha) - slack, the bound is Cosner, Culbertson,
Taylor and Ames's (RSS 2023, Thm 5, a form of Kushner's): where
slack >= -level (1 - alpha) (branch="inward"),
1 - (h0 + level)/(upper + level) * ((upper alpha + level + slack)/(upper + level))^steps,
and below it ("outward")
(upper - h0)/(upper + level) alpha^steps
+ phi/(upper + level) (1 - alpha^steps)/(1 - alpha),
each clipped at 1. At slack = level = 0 it is 1 - alpha^steps h0 / upper. Maxima
validation/exit_probability.mac derives both forms from the supermartingale and sets the
bound against the exact exit probability of a scalar Gaussian loop, where it is several times
the truth: 0.2025 against 0.0263 at one step, 0.896 against 0.420 at ten.
Scope. A closed loop only: the condition is a property of the feedback at the states the noise
moves the loop to, and an open-loop plan -- an AffineSchedule, a
chc.plan.CausalPlan, an affine policy whose gain is zero -- is refused. The bound is
a reading of the loop under its noise, not a certificate of the deterministic barrier:
chc.plan.certify_safety neither reads nor returns it. It is free of the dimension, and
it reads the noise through its covariance alone; a noise whose law depends on the state is
outside it, and so is one that persists from step to step, an AR(1) say, until it is carried
as a state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
barrier
|
QuadraticBarrier
|
|
required |
plant
|
LinearGaussianPlant
|
the step |
required |
policy
|
AffinePolicy | Callable[[NDArray[float64]], ArrayLike]
|
the state feedback that closes the loop. |
required |
x0
|
ArrayLike
|
the known start. |
required |
steps
|
int
|
|
required |
alpha
|
float
|
the discrete-time factor in |
required |
level
|
float
|
|
0.0
|
states
|
ArrayLike | None
|
|
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
on a |
ValueError
|
on an open-loop policy, dimensions that do not agree, a non-finite entry,
|