pub struct EProcessRiskControl { /* private fields */ }Expand description
Anytime-valid risk controller over a fixed grid of candidate thresholds.
Feed it the deferred-feedback stream via EProcessRiskControl::observe_served and read
EProcessRiskControl::certified_threshold on the router hot path. Unlike
crate::conformal::AdaptiveConformal, the answer is valid at the round you read it.
Implementations§
Source§impl EProcessRiskControl
impl EProcessRiskControl
Sourcepub fn new(alpha: f64, delta: f64, bet: f64, grid: &[f64]) -> Self
pub fn new(alpha: f64, delta: f64, bet: f64, grid: &[f64]) -> Self
Build a controller over grid candidate thresholds.
alpha is the target served-failure rate, delta the family-wise error budget (the bound
holds with probability 1 − delta across every threshold and every round jointly).
The grid is sorted and de-duplicated; an empty grid yields a controller that never certifies, which is the correct degenerate behaviour rather than an error — the caller then simply keeps its existing threshold.
Sourcepub fn with_cap(
alpha: f64,
delta: f64,
bet: f64,
cap: f64,
grid: &[f64],
) -> Self
pub fn with_cap( alpha: f64, delta: f64, bet: f64, cap: f64, grid: &[f64], ) -> Self
As EProcessRiskControl::new, with an explicit e-value ceiling. See DEFAULT_CAP for
why a ceiling exists and what it trades.
Sourcepub fn crossing_level(&self) -> f64
pub fn crossing_level(&self) -> f64
The per-threshold crossing level under Bonferroni: n / delta.
Splitting delta across the n grid points is what keeps the family-wise error at
delta. Testing every threshold at the full delta would inflate the false-certification
rate with grid size — the classic multiple-testing trap, and an easy one to fall into here
because each individual e-process looks perfectly valid on its own.
Sourcepub fn observe_served(&mut self, score: f64, was_correct: bool)
pub fn observe_served(&mut self, score: f64, was_correct: bool)
Record one served item: its gate score, and whether it turned out correct.
Only thresholds that would have served this item (λ <= score) are updated — a threshold
strict enough to have escalated instead has learned nothing about its own risk from it.
Sourcepub fn certified_threshold(&self) -> Option<Certification>
pub fn certified_threshold(&self) -> Option<Certification>
The least conservative certified threshold, or None if nothing is certified yet.
None means “no threshold has earned a guarantee”, and the caller must keep its existing
behaviour rather than invent one. Serving on an uncertified threshold would be exactly the
unproven-claim failure this module exists to prevent.
Certification is evaluated live, against the current e-value — it is not a latch.
This is the subtle part, and getting it wrong silently reintroduces the very failure mode the
module exists to prevent. A threshold that crossed during a clean stretch and has since been
contradicted by evidence is not certified any more, and must stop serving. Latching it —
“it was proven once, so it stays proven” — is what a fixed-sample method does, and under a
regime change it keeps serving at a threshold the current regime does not justify. The first
draft of this module latched, and coverage_holds_at_every_round_under_a_regime_change
caught it: realized failure hit 0.312 against alpha=0.20.
certified_at_round is retained as provenance — when the evidence first crossed — which is
useful in a receipt and harmless here, because the serving decision reads the e-value.
Sourcepub fn should_serve(&self, score: f64) -> bool
pub fn should_serve(&self, score: f64) -> bool
Whether score clears the certified threshold. false while nothing is certified.
Sourcepub fn realized_served_failure(&self) -> f64
pub fn realized_served_failure(&self) -> f64
Realized served-failure rate so far — a running diagnostic, not the guarantee.