pub struct StartRungBandit { /* private fields */ }Expand description
Online UCB1 bandit for start-rung selection.
Keyed by ContextBucket; per context, tracks per-rung pass/fail counts of gate verdicts.
Thread-safety comes from the caller wrapping this in Arc<std::sync::Mutex<_>> (mirroring
AdaptiveConformal — both are per-process, in-memory, low-contention).
Implementations§
Source§impl StartRungBandit
impl StartRungBandit
Sourcepub fn new(min_observations: usize, exploration: f64) -> Self
pub fn new(min_observations: usize, exploration: f64) -> Self
Create a new UCB1 bandit with the given cold-start and exploration settings.
Sourcepub fn with_algorithm(
min_observations: usize,
exploration: f64,
algorithm: Algorithm,
discount: f64,
seed: u64,
) -> Self
pub fn with_algorithm( min_observations: usize, exploration: f64, algorithm: Algorithm, discount: f64, seed: u64, ) -> Self
Create a bandit with an explicit algorithm, discount, and PRNG seed (seed matters only
for Algorithm::Thompson; pass anything non-zero).
Sourcepub fn pass_estimate(&self, ctx: &ContextBucket, rung: u32) -> Option<f64>
pub fn pass_estimate(&self, ctx: &ContextBucket, rung: u32) -> Option<f64>
Posterior-mean gate-pass estimate for (ctx, rung) — None when the context is cold
(below min_observations) or the arm is unobserved. Deterministic; used by the
speculative-deferral band, never for serving decisions.
Sourcepub fn observe(&mut self, ctx: &ContextBucket, rung: u32, verdict: Verdict)
pub fn observe(&mut self, ctx: &ContextBucket, rung: u32, verdict: Verdict)
Record a gate verdict for (context, rung).
Abstain is ignored — only clear Pass/Fail outcomes are informative for cost modelling.
Sourcepub fn choose_start(
&self,
ctx: &ContextBucket,
ladder: &[String],
prices: &PriceTable,
) -> u32
pub fn choose_start( &self, ctx: &ContextBucket, ladder: &[String], prices: &PriceTable, ) -> u32
Choose the start rung that minimises expected cost for this context and ladder.
Returns 0 in all cold-start cases:
- bandit is cold (total observations <
min_observationsfor this context) ladderis empty
Never returns a value ≥ ladder.len().
Sourcepub fn choose_start_with_propensity(
&mut self,
ctx: &ContextBucket,
ladder: &[String],
prices: &PriceTable,
) -> (u32, Option<f64>)
pub fn choose_start_with_propensity( &mut self, ctx: &ContextBucket, ladder: &[String], prices: &PriceTable, ) -> (u32, Option<f64>)
Choose the start rung and its selection propensity.
Algorithm::Ucb1: deterministic — returns(choice, None); the epsilon-greedy overlay (if configured) supplies the logged propensity, exactly as before.Algorithm::Thompson: one posterior draw per rung drives the same expected-cost argmin as UCB1 (the decision), and the propensity is Monte-Carlo estimated by re-running the drawPROPENSITY_SAMPLEStimes — the standard estimator for TS selection probabilities (exact computation is analytically intractable). Cold-start contexts return(0, None)(deterministic, no propensity to log).
Sourcepub fn feed_trace_attempts(&mut self, ctx: &ContextBucket, attempts: &[Attempt])
pub fn feed_trace_attempts(&mut self, ctx: &ContextBucket, attempts: &[Attempt])
Feed all attempts from a stored trace into this bandit — used for warm-start at startup.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StartRungBandit
impl RefUnwindSafe for StartRungBandit
impl Send for StartRungBandit
impl Sync for StartRungBandit
impl Unpin for StartRungBandit
impl UnsafeUnpin for StartRungBandit
impl UnwindSafe for StartRungBandit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more