Struct rv::dist::Beta [−][src]
pub struct Beta { /* fields omitted */ }
Beta distribution, Beta(α, β) over x in (0, 1).
Examples
Beta as a conjugate prior for Bernoulli
use rv::prelude::*; // A prior that encodes our strong belief that coins are fair: let beta = Beta::new(5.0, 5.0).unwrap(); // The posterior predictive probability that a coin will come up heads given // no new observations. let p_prior_heads = beta.pp(&true, &DataOrSuffStat::None); // 0.5 assert!((p_prior_heads - 0.5).abs() < 1E-12); // Five Bernoulli trials. We flipped a coin five times and it came up head // four times. let flips = vec![true, true, false, true, true]; // The posterior predictive probability that a coin will come up heads given // the five flips we just saw. let p_pred_heads = beta.pp(&true, &DataOrSuffStat::Data(&flips)); // 9/15 assert!((p_pred_heads - 3.0/5.0).abs() < 1E-12);
Implementations
impl Beta
[src]
impl Beta
[src]pub fn new(alpha: f64, beta: f64) -> Result<Self, BetaError>
[src]
Create a Beta
distribution with even density over (0, 1).
Example
// Uniform let beta_unif = Beta::new(1.0, 1.0); assert!(beta_unif.is_ok()); // Jefferey's prior let beta_jeff = Beta::new(0.5, 0.5); assert!(beta_jeff.is_ok()); // Invalid negative parameter let beta_nope = Beta::new(-5.0, 1.0); assert!(beta_nope.is_err());
pub fn new_unchecked(alpha: f64, beta: f64) -> Self
[src]
Creates a new Beta without checking whether the parameters are valid.
pub fn uniform() -> Self
[src]
Create a Beta
distribution with even density over (0, 1).
Example
let beta = Beta::uniform(); assert_eq!(beta, Beta::new(1.0, 1.0).unwrap());
pub fn jeffreys() -> Self
[src]
Create a Beta
distribution with the Jeffrey’s parameterization,
Beta(0.5, 0.5).
Example
let beta = Beta::jeffreys(); assert_eq!(beta, Beta::new(0.5, 0.5).unwrap());
pub fn alpha(&self) -> f64
[src]
Get the alpha parameter
Example
let beta = Beta::new(1.0, 5.0).unwrap(); assert_eq!(beta.alpha(), 1.0);
pub fn set_alpha(&mut self, alpha: f64) -> Result<(), BetaError>
[src]
Set the alpha parameter
Example
let mut beta = Beta::new(1.0, 5.0).unwrap(); beta.set_alpha(2.0).unwrap(); assert_eq!(beta.alpha(), 2.0);
Will error for invalid values
assert!(beta.set_alpha(0.1).is_ok()); assert!(beta.set_alpha(0.0).is_err()); assert!(beta.set_alpha(-1.0).is_err()); assert!(beta.set_alpha(std::f64::INFINITY).is_err()); assert!(beta.set_alpha(std::f64::NAN).is_err());
pub fn set_alpha_unchecked(&mut self, alpha: f64)
[src]
Set alpha without input validation
pub fn beta(&self) -> f64
[src]
Get the beta parameter
Example
let beta = Beta::new(1.0, 5.0).unwrap(); assert_eq!(beta.beta(), 5.0);
pub fn set_beta(&mut self, beta: f64) -> Result<(), BetaError>
[src]
Set the beta parameter
Example
let mut beta = Beta::new(1.0, 5.0).unwrap(); beta.set_beta(2.0).unwrap(); assert_eq!(beta.beta(), 2.0);
Will error for invalid values
assert!(beta.set_beta(0.1).is_ok()); assert!(beta.set_beta(0.0).is_err()); assert!(beta.set_beta(-1.0).is_err()); assert!(beta.set_beta(std::f64::INFINITY).is_err()); assert!(beta.set_beta(std::f64::NAN).is_err());
pub fn set_beta_unchecked(&mut self, beta: f64)
[src]
Set beta without input validation
Trait Implementations
impl Clone for Beta
[src]
impl Clone for Beta
[src]fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<X: Booleable> ConjugatePrior<X, Bernoulli> for Beta
[src]
impl<X: Booleable> ConjugatePrior<X, Bernoulli> for Beta
[src]type Posterior = Self
Type of the posterior distribution
type LnMCache = f64
Type of the ln_m
cache
type LnPpCache = (f64, f64)
Type of the ln_pp
cache
fn posterior(&self, x: &DataOrSuffStat<'_, X, Bernoulli>) -> Self
[src]
fn ln_m_cache(&self) -> Self::LnMCache
[src]
fn ln_m_with_cache(
&self,
cache: &Self::LnMCache,
x: &DataOrSuffStat<'_, X, Bernoulli>
) -> f64
[src]
&self,
cache: &Self::LnMCache,
x: &DataOrSuffStat<'_, X, Bernoulli>
) -> f64
fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, X, Bernoulli>) -> Self::LnPpCache
[src]
fn ln_pp_with_cache(&self, cache: &Self::LnPpCache, y: &X) -> f64
[src]
fn ln_m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn ln_pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
impl ContinuousDistr<Bernoulli> for Beta
[src]
impl ContinuousDistr<Bernoulli> for Beta
[src]impl ContinuousDistr<f32> for Beta
[src]
impl ContinuousDistr<f32> for Beta
[src]impl ContinuousDistr<f64> for Beta
[src]
impl ContinuousDistr<f64> for Beta
[src]Auto Trait Implementations
impl RefUnwindSafe for Beta
impl RefUnwindSafe for Beta
impl UnwindSafe for Beta
impl UnwindSafe for Beta
Blanket Implementations
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
pub fn to_subset(&self) -> Option<SS>
pub fn is_in_subset(&self) -> bool
pub fn to_subset_unchecked(&self) -> SS
pub fn from_subset(element: &SS) -> SP
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,