Skip to main content

EProcessRiskControl

Struct EProcessRiskControl 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn should_serve(&self, score: f64) -> bool

Whether score clears the certified threshold. false while nothing is certified.

Source

pub fn realized_served_failure(&self) -> f64

Realized served-failure rate so far — a running diagnostic, not the guarantee.

Source

pub const fn rounds(&self) -> u64

Rounds observed.

Source

pub fn e_values(&self) -> &[f64]

Current e-value at each grid point, parallel to the grid — for telemetry and tests.

Source

pub fn grid(&self) -> &[f64]

The candidate grid, ascending.

Source

pub const fn alpha(&self) -> f64

Target served-failure rate the certificate is stated at.

Source

pub const fn delta(&self) -> f64

Family-wise error budget the certificate is stated at.

Trait Implementations§

Source§

impl Clone for EProcessRiskControl

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EProcessRiskControl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for EProcessRiskControl

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for EProcessRiskControl

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.