A safety filter is a small program that sits between a controller and a robot's motors and overrides commands that would lead somewhere dangerous. The accurate filters solve an optimization problem at every control step, which is too slow for fast control loops. A known workaround trains a neural network offline to imitate the optimizer's answer, so each step costs one forward pass instead of one solve. The price is that the network is sometimes wrong. The standard fix adds a single worst-case error margin everywhere in the state space. That margin is too cautious where the network was trained densely and too thin where it has never seen data.
We propose to replace this single margin with one that varies by location and is set by how densely the training data covers each state. A normalizing flow, a density model whose likelihood can be computed exactly in one pass, scores how familiar each state and scene is. Calibration data then turns each familiarity level into an error bound with a stated coverage. Where familiarity drops below the level that calibration can support, the filter calls the slow exact solver or a backup controller instead of trusting the network. The expected result is a filter that intervenes less on familiar states, stays safe on unfamiliar ones, and makes explicit when the network's answer should not be used.
Core Claim
Approximate predictive control barrier functions are neural networks trained to reproduce the value of a look-ahead safety optimization. Didier et al. (ECC) showed they can cut solve time from about 176 ms to 3 ms, a 58x speedup. The follow-up Didier et al. (discrete-time) proved input-to-state stability of the safe set under a bounded approximation error $\epsilon_h$. Both papers motivate this proposal and supply its method. They also treat $\epsilon_h$ as one constant over a compact domain, and both acknowledge the resulting conservatism.
Our claim is that the network's actual error has a strong spatial structure, and that latent density predicts that structure well enough to schedule the margin. Concretely, let $\hat h(x,c)$ be the network's barrier estimate at physical state $x$ under scene context $c$, where $\hat h \le 0$ means safe. Let $\ell(x,c)=\log p_\omega(x,c)$ be the flow's log-density, computed on a learned embedding of $c$ when the context comes from images. The filter certifies a proposed input $u$ with successor state $x^+$ only if
$$\hat h(x^+,c) + \epsilon_\delta\big(\ell(x^+,c)\big) \le 0 .$$
Here $\epsilon_\delta(\cdot)$ is the $(1-\delta)$ quantile of the absolute residuals $|h-\hat h|$ on held-out calibration points that fall in the same log-density bin. The per-bin quantile is computed with Mondrian conformal prediction, a calibration method that gives a coverage statement separately for each group of points. When $\ell(x^+,c)$ falls below a threshold $\tau$, below which the calibration bins hold too few points to support a quantile, the filter does not answer from the network. It falls back to the exact solver or to a backup controller.
What would be new is density acting as the index of a calibrated, location-dependent margin inside the certification inequality. This is different from density used as a separate alarm, as in REDOUBT, which only validates planners and never intervenes. It is also different from a cost term inside a planner, as in EVORA, which feeds flow-based familiarity into a risk-aware controller that plans over worst-case traction but offers no guarantee of staying in the safe set.
Relation to Prior Work
Two lines of work already attach uncertainty to learned safety in latent spaces, and they bound what this proposal can claim.
UNISafe augments a learned latent world model with an uncertainty score, calibrates a threshold with conformal prediction, and solves reachability over the augmented state. Its uncertainty score is the Jensen-Renyi divergence (a measure of disagreement) across an ensemble of predictors of the next latent state. It uses a single threshold and does not size a margin. Crucially, it also documents a "hallucination trap": image encoders map out-of-distribution scenes into ordinary-looking latent codes. That finding constrains our design, because it warns that density computed on a single latent frame may be blind to exactly the failures that matter. We address it by also modeling the density of latent transitions (current latent, action, next latent), and we test whether this is enough rather than assuming it.
Safety Certification in the Latent Space learns barrier networks on frozen DINO-v2 image features. DINO-v2 is a pretrained vision transformer used there as a fixed encoder. The paper includes no mechanism for detecting out-of-distribution scenes, which is the gap we target in its setting.
On the density side, NatPN uses a flow on a network's internal features as a single-pass stand-in for model ignorance. It reports being about 5x faster than ensembles and proves that density decays far from the training data for encoders built from ReLU units, a common piecewise-linear activation. That decay property is what licenses using density as the margin index. DifferNet shows such flows are sample-efficient on frozen features, reporting 94.9% AUROC on the MVTec AD defect-detection benchmark. We reuse both techniques rather than invent new density models.
ShieldNN precomputes closed-form safe steering bounds. It needs no margin inside its analytic kinematic model, which marks the regime where our method is unnecessary.
Research Program
The work has three parts.
The first part builds the calibrated filter for a kinematic car. We reproduce the approximate predictive barrier pipeline of Didier et al., a 3×64 network trained with Huber loss, and extend its input with context parameters: obstacle position, lane geometry, and an actuation limit. The exact value $h$ can be computed for these parameters, so residuals are measurable. A flow is trained on the joint distribution of state and context over the same offline samples. Residuals on a disjoint calibration split are sorted into log-density bins to produce $\epsilon_\delta$.
The second part works out the theory. We extend the stability argument of Didier et al. from a constant $\epsilon_h$ to a state-dependent margin that holds on the region where density exceeds $\tau$, with the fallback covering the rest. We will state this honestly. Conformal coverage holds for calibration and test points drawn from the same distribution, and closed-loop trajectories are not such draws. The guarantee is therefore statistical, per bin, and it is checked empirically along rollouts. In the low-dimensional car, the calibrated bound can additionally be checked exhaustively on a dense grid.
The third part moves to perception. A visual Dubins car, following the setups of UNISafe and Anand and Kolathaya, gets its context from DINO-v2 features. Because the true 3-dimensional state is known in simulation, ground-truth safety values can be computed on a grid. This lets us measure false-safe certifications exactly, something neither paper could do. In this setting the flow is trained both on single-frame latents and on transition triples.
Baselines
Uniform margin. The reference point is the approximate filter of Didier et al. with one constant margin, set so that $|h-\hat h|\le\epsilon$ on the same calibration split at the same coverage $1-\delta$. It is the strongest competitor because it is the published method this proposal modifies.
The reported figures for this line of work are a 58x average speedup and a drop in solve time from about 176 ms to 3 ms (Didier et al.). The discrete-time version reports a speedup factor of 13 when overwriting unsafe inputs and 1900 when certifying safe inputs on a miniature race car (Didier et al.). No reported result was found on Lacuna for the intervention rate or false-safe rate of these filters, so we will measure both ourselves. Beating this baseline means a lower intervention rate at an equal or lower false-safe rate, with per-step latency under 10 ms including the flow.
Exact solver. The online predictive barrier solver is the reference for correctness and permissiveness. It defines zero approximation error and gives the latency ceiling.
Learned error regressor. A second head, or a separate network, predicts the $(1-\delta)$ quantile of the residual directly from $(x,c)$ using quantile regression, then gets the same conformal correction. It gets the same data and a matched parameter count. This is the ablation that isolates density: if it matches our method under shift, density adds nothing beyond a learned error predictor.
Distance-based margin. The margin is set by $k$-nearest-neighbor distance to the training data, and in the car setting also by a Lipschitz-style bound: the nearest calibration residual plus an estimated Lipschitz constant times the distance. It is calibrated with the same binning scheme. REDOUBT reports that latent flow matching beat Mahalanobis distance and $k$-nearest-neighbors for detecting unfamiliar scenes, but gives no granular numbers, so this comparison must be rerun here.
Ensemble uncertainty. In the visual task, UNISafe's ensemble divergence is used as the margin index, with the same calibration. Its 3D Dubins car balanced accuracy of 0.94 for identifying unsafe regions (UNISafe) is the detection figure to match. All uncertainty models get the same training budget and hyperparameter search budget.
Why not just…?
Why not just learn the error directly with quantile regression? This is the most serious threat. In familiar regions it will probably match density-based bins. Its weakness is structural: it is trained only on residuals from states inside the training data, so far from that data it extrapolates the way the barrier network does and has no built-in reason to predict large errors. By contrast, NatPN's result guarantees that density decays far from the data for ReLU encoders. The shifted-context experiments are designed to settle this question. If the regressor's false-safe rate stays within $\delta$ under shift, we will report that the simpler method suffices.
Why not just use nearest-neighbor distance with a Lipschitz bound? In the 4-to-5-dimensional car this gives a rigorous margin and may well tie with our method. The weakness is that the value function of a predictive barrier is not smooth near constraint boundaries. That is presumably why Didier et al. concentrated 2 million of their 10.9 million samples near those boundaries, and a single global Lipschitz constant there would make the bound vacuous. In DINO-v2 space, Euclidean distance has little physical meaning. We expect a tie in the car and a loss in the visual task. A win for distances in both settings would narrow our claim to "density is optional."
Why not just use an ensemble? Ensembles multiply latency and memory, and NatPN reports being about 5x faster than ensembles. UNISafe also found that naive ensemble variance collapsed under hallucination, which is why it built a divergence over predicted transitions instead. We include its divergence as a baseline rather than dismissing it.
Why not just keep a uniform margin and collect more data? Offline data collection already costs 10.9 to 18 million solver evaluations in the file's examples. A uniform margin also gives no signal at deployment when the context leaves the range it was trained on.
Proposed Experiments and Decisive Checks
Car experiment. We train on one range of contexts and test both in-range and on shifted contexts: obstacles placed closer, narrower lanes, tighter actuation limits. Metrics are false-safe rate against the exact $h$, intervention rate relative to the exact solver, closed-loop constraint violations over 400-step rollouts (matching Didier et al.'s horizon), fraction of steps sent to the solver, and per-step latency.
Visual Dubins experiment. We test under unseen textures, lighting changes, and added distractors, reporting the same metrics plus AUROC for flagging unfamiliar scenes.
Decisive checks. The proposal is judged on four outcomes.
The first is whether, in-distribution, our method attains a strictly lower intervention rate than the uniform margin at the same false-safe rate.
The second is whether, under shift, our method's false-safe rate stays at or below $\delta$ while the quantile regressor's rises. If the regressor holds too, the density contribution fails.
The third is whether, in the visual task, a flow on transition triples reduces false-safe certifications compared with a flow on single-frame latents. This tests the hallucination trap head on. If neither flow beats UNISafe's divergence, the latent-density route is not viable for perception.
The fourth is whether solver calls stay rare enough, say below 10% of steps, to preserve most of the reported 58x speedup.
References
- Approximate Predictive Control Barrier Functions using Neural Networks: A Computationally Cheap and Permissive Safety Filter
- Approximate Predictive Control Barrier Function for Discrete-Time Systems
- REDOUBT: Duo Safety Validation for Autonomous Vehicle Motion Planning
- EVORA: Deep Evidential Traversability Learning for Risk-Aware Off-Road Autonomy
- UNISafe: Uncertainty-aware Latent Safety Filters for Avoiding Out-of-Distribution Failures
- Safety Certification in the Latent space using Control Barrier Functions and World Models
- Natural Posterior Network: Deep Bayesian Predictive Uncertainty for Exponential Family Distributions
- Same Same But DifferNet: Semi-Supervised Defect Detection with Normalizing Flows
- ShieldNN: A Provably Safe NN Filter for Unsafe NN Controllers