[−][src]Struct rv::dist::Beta
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);
Methods
impl Beta
[src]
pub fn set_alpha(&mut self, val: f64) -> &mut Self
[src]
pub fn set_beta(&mut self, val: f64) -> &mut Self
[src]
impl Beta
[src]
pub fn new(alpha: f64, beta: f64) -> Result<Self>
[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 beta(&self) -> f64
[src]
Get the beta parameter
Example
let beta = Beta::new(1.0, 5.0).unwrap(); assert_eq!(beta.beta(), 5.0);
Trait Implementations
impl Rv<f32> for Beta
[src]
fn ln_f(&self, x: &f32) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> f32
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<f32>
[src]
fn f(&self, x: &X) -> f64
[src]
impl Rv<f64> for Beta
[src]
fn ln_f(&self, x: &f64) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<f64>
[src]
fn f(&self, x: &X) -> f64
[src]
impl Rv<Bernoulli> for Beta
[src]
fn ln_f(&self, x: &Bernoulli) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> Bernoulli
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
impl Support<f32> for Beta
[src]
impl Support<f64> for Beta
[src]
impl Support<Bernoulli> for Beta
[src]
impl ContinuousDistr<f32> for Beta
[src]
impl ContinuousDistr<f64> for Beta
[src]
impl ContinuousDistr<Bernoulli> for Beta
[src]
impl Cdf<f32> for Beta
[src]
impl Cdf<f64> for Beta
[src]
impl Mean<f32> for Beta
[src]
impl Mean<f64> for Beta
[src]
impl Mode<f32> for Beta
[src]
impl Mode<f64> for Beta
[src]
impl Variance<f64> for Beta
[src]
impl Entropy for Beta
[src]
impl Skewness for Beta
[src]
impl Kurtosis for Beta
[src]
impl ConjugatePrior<bool, Bernoulli> for Beta
[src]
type Posterior = Self
fn posterior(&self, x: &DataOrSuffStat<bool, Bernoulli>) -> Self
[src]
fn ln_m(&self, x: &DataOrSuffStat<bool, Bernoulli>) -> f64
[src]
fn ln_pp(&self, y: &bool, x: &DataOrSuffStat<bool, Bernoulli>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
impl ConjugatePrior<u8, Bernoulli> for Beta
[src]
type Posterior = Self
fn posterior(&self, x: &DataOrSuffStat<u8, Bernoulli>) -> Self
[src]
fn ln_m(&self, x: &DataOrSuffStat<u8, Bernoulli>) -> f64
[src]
fn ln_pp(&self, y: &u8, x: &DataOrSuffStat<u8, Bernoulli>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
impl ConjugatePrior<u16, Bernoulli> for Beta
[src]
type Posterior = Self
fn posterior(&self, x: &DataOrSuffStat<u16, Bernoulli>) -> Self
[src]
fn ln_m(&self, x: &DataOrSuffStat<u16, Bernoulli>) -> f64
[src]
fn ln_pp(&self, y: &u16, x: &DataOrSuffStat<u16, Bernoulli>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
impl ConjugatePrior<u32, Bernoulli> for Beta
[src]
type Posterior = Self
fn posterior(&self, x: &DataOrSuffStat<u32, Bernoulli>) -> Self
[src]
fn ln_m(&self, x: &DataOrSuffStat<u32, Bernoulli>) -> f64
[src]
fn ln_pp(&self, y: &u32, x: &DataOrSuffStat<u32, Bernoulli>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
impl ConjugatePrior<u64, Bernoulli> for Beta
[src]
type Posterior = Self
fn posterior(&self, x: &DataOrSuffStat<u64, Bernoulli>) -> Self
[src]
fn ln_m(&self, x: &DataOrSuffStat<u64, Bernoulli>) -> f64
[src]
fn ln_pp(&self, y: &u64, x: &DataOrSuffStat<u64, Bernoulli>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
impl ConjugatePrior<usize, Bernoulli> for Beta
[src]
type Posterior = Self
fn posterior(&self, x: &DataOrSuffStat<usize, Bernoulli>) -> Self
[src]
fn ln_m(&self, x: &DataOrSuffStat<usize, Bernoulli>) -> f64
[src]
fn ln_pp(&self, y: &usize, x: &DataOrSuffStat<usize, Bernoulli>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
impl ConjugatePrior<i8, Bernoulli> for Beta
[src]
type Posterior = Self
fn posterior(&self, x: &DataOrSuffStat<i8, Bernoulli>) -> Self
[src]
fn ln_m(&self, x: &DataOrSuffStat<i8, Bernoulli>) -> f64
[src]
fn ln_pp(&self, y: &i8, x: &DataOrSuffStat<i8, Bernoulli>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
impl ConjugatePrior<i16, Bernoulli> for Beta
[src]
type Posterior = Self
fn posterior(&self, x: &DataOrSuffStat<i16, Bernoulli>) -> Self
[src]
fn ln_m(&self, x: &DataOrSuffStat<i16, Bernoulli>) -> f64
[src]
fn ln_pp(&self, y: &i16, x: &DataOrSuffStat<i16, Bernoulli>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
impl ConjugatePrior<i32, Bernoulli> for Beta
[src]
type Posterior = Self
fn posterior(&self, x: &DataOrSuffStat<i32, Bernoulli>) -> Self
[src]
fn ln_m(&self, x: &DataOrSuffStat<i32, Bernoulli>) -> f64
[src]
fn ln_pp(&self, y: &i32, x: &DataOrSuffStat<i32, Bernoulli>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
impl ConjugatePrior<i64, Bernoulli> for Beta
[src]
type Posterior = Self
fn posterior(&self, x: &DataOrSuffStat<i64, Bernoulli>) -> Self
[src]
fn ln_m(&self, x: &DataOrSuffStat<i64, Bernoulli>) -> f64
[src]
fn ln_pp(&self, y: &i64, x: &DataOrSuffStat<i64, Bernoulli>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
impl ConjugatePrior<isize, Bernoulli> for Beta
[src]
type Posterior = Self
fn posterior(&self, x: &DataOrSuffStat<isize, Bernoulli>) -> Self
[src]
fn ln_m(&self, x: &DataOrSuffStat<isize, Bernoulli>) -> f64
[src]
fn ln_pp(&self, y: &isize, x: &DataOrSuffStat<isize, Bernoulli>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
impl<'_> From<&'_ Beta> for String
[src]
impl Clone for Beta
[src]
impl Default for Beta
[src]
impl PartialEq<Beta> for Beta
[src]
impl PartialOrd<Beta> for Beta
[src]
fn partial_cmp(&self, other: &Beta) -> Option<Ordering>
[src]
fn lt(&self, other: &Beta) -> bool
[src]
fn le(&self, other: &Beta) -> bool
[src]
fn gt(&self, other: &Beta) -> bool
[src]
fn ge(&self, other: &Beta) -> bool
[src]
impl Display for Beta
[src]
impl Debug for Beta
[src]
Auto Trait Implementations
impl Send for Beta
impl Sync for Beta
impl Unpin for Beta
impl UnwindSafe for Beta
impl RefUnwindSafe for Beta
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn is_in_subset(&self) -> bool
unsafe fn to_subset_unchecked(&self) -> SS
fn from_subset(element: &SS) -> SP
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,