Skip to main content

BayesianConfidenceUpdater

Struct BayesianConfidenceUpdater 

Source
pub struct BayesianConfidenceUpdater { /* private fields */ }
Expand description

Bayesian confidence updater using a Beta-Bernoulli conjugate model.

§Model

Maintains parameters (α, β) of a Beta distribution. On each observation:

  • Success: α += 1
  • Failure: β += 1

The posterior mean α / (α + β) is used as the point estimate.

Implementations§

Source§

impl BayesianConfidenceUpdater

Source

pub fn new(prior: BetaPrior) -> Self

Create an updater with an explicit prior.

Source

pub fn with_builtin_prior() -> Self

Create an updater with the builtin_priors() prior.

Source

pub fn update_success(&mut self)

Record a success observation (α += 1).

Source

pub fn update_failure(&mut self)

Record a failure observation (β += 1).

Source

pub fn update(&mut self, successes: u32, failures: u32)

Apply successes and failures in bulk.

Source

pub fn posterior_mean(&self) -> f32

Posterior mean: α / (α + β).

Source

pub fn posterior_variance(&self) -> f32

Posterior variance: αβ / ((α+β)²(α+β+1)).

Source

pub fn sample_count(&self, prior: &BetaPrior) -> u32

Total observations recorded above the prior (i.e. (α - α₀) + (β - β₀)).

Source

pub fn snapshot(&self, prior: &BetaPrior) -> ConfidenceSnapshot

Build a ConfidenceSnapshot from the current posterior state.

prior is used only to compute sample_count; pass builtin_priors() unless you constructed this updater with a custom prior.

Source

pub fn alpha(&self) -> f32

Current alpha parameter (useful for serialisation/inspection).

Source

pub fn beta(&self) -> f32

Current beta parameter (useful for serialisation/inspection).

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.