Skip to main content

BayesianShrinkagePrior

Struct BayesianShrinkagePrior 

Source
pub struct BayesianShrinkagePrior {
    pub prior_mean: f64,
    pub prior_variance: f64,
}
Expand description

Prior distribution parameters for Bayesian shrinkage estimation.

Uses a normal prior N(prior_mean, prior_variance) that pulls empirical estimates toward the prior when sample size is small or variance is high.

Fields§

§prior_mean: f64

Prior mean for the loss value.

§prior_variance: f64

Prior variance (τ₀²) - controls how strongly we trust the prior. Smaller values mean stronger pull toward prior_mean.

Implementations§

Source§

impl BayesianShrinkagePrior

Source

pub const fn for_false_negative() -> Self

Default prior for false-negative loss (allowing incompatible operation).

Source

pub const fn for_validate_cost() -> Self

Default prior for validation cost.

Source

pub const fn for_false_positive() -> Self

Default prior for false-positive loss (rejecting compatible operation).

Source

pub fn shrinkage_weight( &self, empirical_variance: f64, sample_count: usize, ) -> f64

Compute shrinkage weight given empirical variance and sample count.

w = τ₀² / (τ₀² + σ²/n)

When n is small or σ² is large, w is small (trust prior more). When n is large and σ² is small, w approaches 1 (trust data more).

Source

pub fn posterior_mean( &self, empirical_mean: f64, empirical_variance: f64, sample_count: usize, ) -> f64

Compute the posterior mean using shrinkage.

μ_posterior = w * ȳ + (1-w) * μ₀

Trait Implementations§

Source§

impl Clone for BayesianShrinkagePrior

Source§

fn clone(&self) -> BayesianShrinkagePrior

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 Copy for BayesianShrinkagePrior

Source§

impl Debug for BayesianShrinkagePrior

Source§

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

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

impl PartialEq for BayesianShrinkagePrior

Source§

fn eq(&self, other: &BayesianShrinkagePrior) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for BayesianShrinkagePrior

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> 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> 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 = 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.