pub struct BetaPrime { /* private fields */ }Expand description
Beta prime distribution, BetaPrime(α, β) over x in (0, ∞).
§Examples
use rv::prelude::*;
// Create a beta prime distribution with parameters α=2, β=3
let betaprime = BetaPrime::new(2.0, 3.0).unwrap();
// Calculate some properties
let mean = betaprime.mean().unwrap();
let variance = betaprime.variance().unwrap();Implementations§
Source§impl BetaPrime
impl BetaPrime
Sourcepub fn new(alpha: f64, beta: f64) -> Result<Self, BetaPrimeError>
pub fn new(alpha: f64, beta: f64) -> Result<Self, BetaPrimeError>
Create a new BetaPrime distribution with parameters α and β.
§Example
let bp = BetaPrime::new(2.0, 3.0);
assert!(bp.is_ok());
// Invalid negative parameter
let bp_nope = BetaPrime::new(-5.0, 1.0);
assert!(bp_nope.is_err());Sourcepub fn new_unchecked(alpha: f64, beta: f64) -> Self
pub fn new_unchecked(alpha: f64, beta: f64) -> Self
Creates a new BetaPrime without checking whether the parameters are valid.
Sourcepub fn alpha(&self) -> f64
pub fn alpha(&self) -> f64
Get the alpha parameter
§Example
let bp = BetaPrime::new(2.0, 3.0).unwrap();
assert_eq!(bp.alpha(), 2.0);Sourcepub fn set_alpha(&mut self, alpha: f64) -> Result<(), BetaPrimeError>
pub fn set_alpha(&mut self, alpha: f64) -> Result<(), BetaPrimeError>
Set the alpha parameter
§Example
let mut bp = BetaPrime::new(2.0, 3.0).unwrap();
bp.set_alpha(2.5).unwrap();
assert_eq!(bp.alpha(), 2.5);Will error for invalid values
assert!(bp.set_alpha(0.1).is_ok());
assert!(bp.set_alpha(0.0).is_err());
assert!(bp.set_alpha(-1.0).is_err());
assert!(bp.set_alpha(f64::INFINITY).is_err());
assert!(bp.set_alpha(f64::NAN).is_err());Sourcepub fn set_alpha_unchecked(&mut self, alpha: f64)
pub fn set_alpha_unchecked(&mut self, alpha: f64)
Set alpha without input validation
Sourcepub fn beta(&self) -> f64
pub fn beta(&self) -> f64
Get the beta parameter
§Example
let bp = BetaPrime::new(2.0, 3.0).unwrap();
assert_eq!(bp.beta(), 3.0);Sourcepub fn set_beta(&mut self, beta: f64) -> Result<(), BetaPrimeError>
pub fn set_beta(&mut self, beta: f64) -> Result<(), BetaPrimeError>
Set the beta parameter
§Example
let mut bp = BetaPrime::new(2.0, 3.0).unwrap();
bp.set_beta(3.5).unwrap();
assert_eq!(bp.beta(), 3.5);Will error for invalid values
assert!(bp.set_beta(0.1).is_ok());
assert!(bp.set_beta(0.0).is_err());
assert!(bp.set_beta(-1.0).is_err());
assert!(bp.set_beta(f64::INFINITY).is_err());
assert!(bp.set_beta(f64::NAN).is_err());Sourcepub fn set_beta_unchecked(&mut self, beta: f64)
pub fn set_beta_unchecked(&mut self, beta: f64)
Set beta without input validation
Trait Implementations§
Source§impl ConjugatePrior<usize, StickBreakingDiscrete> for BetaPrime
Available on crate feature experimental only.
impl ConjugatePrior<usize, StickBreakingDiscrete> for BetaPrime
Available on crate feature
experimental only.Source§fn empty_stat(&self) -> <StickBreakingDiscrete as HasSuffStat<usize>>::Stat
fn empty_stat(&self) -> <StickBreakingDiscrete as HasSuffStat<usize>>::Stat
Generate and empty sufficient statistic
fn posterior( &self, data: &DataOrSuffStat<'_, usize, StickBreakingDiscrete>, ) -> Self
Source§fn ln_m_cache(&self) -> Self::MCache
fn ln_m_cache(&self) -> Self::MCache
Compute the cache for the log marginal likelihood.
Source§fn ln_m_with_cache(
&self,
cache: &Self::MCache,
data: &DataOrSuffStat<'_, usize, StickBreakingDiscrete>,
) -> f64
fn ln_m_with_cache( &self, cache: &Self::MCache, data: &DataOrSuffStat<'_, usize, StickBreakingDiscrete>, ) -> f64
Log marginal likelihood with supplied cache.
Source§fn ln_pp_cache(
&self,
data: &DataOrSuffStat<'_, usize, StickBreakingDiscrete>,
) -> Self::PpCache
fn ln_pp_cache( &self, data: &DataOrSuffStat<'_, usize, StickBreakingDiscrete>, ) -> Self::PpCache
Compute the cache for the Log posterior predictive of y given x. Read more
Source§fn ln_pp_with_cache(&self, cache: &Self::PpCache, _y: &usize) -> f64
fn ln_pp_with_cache(&self, cache: &Self::PpCache, _y: &usize) -> f64
Log posterior predictive of y given x with supplied ln(norm)
Source§fn posterior_from_suffstat(&self, stat: &Fx::Stat) -> Self::Posterior
fn posterior_from_suffstat(&self, stat: &Fx::Stat) -> Self::Posterior
Computes the posterior distribution from the data
Source§fn ln_m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
fn ln_m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
The log marginal likelihood
Source§fn ln_pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
fn ln_pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
Log posterior predictive of y given x
Source§fn m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
fn m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
Marginal likelihood of x
fn pp_with_cache(&self, cache: &Self::PpCache, y: &X) -> f64
Source§impl ContinuousDistr<f64> for BetaPrime
impl ContinuousDistr<f64> for BetaPrime
Source§impl<'de> Deserialize<'de> for BetaPrime
impl<'de> Deserialize<'de> for BetaPrime
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl HasDensity<f64> for BetaPrime
impl HasDensity<f64> for BetaPrime
Source§impl Parameterized for BetaPrime
impl Parameterized for BetaPrime
type Parameters = BetaPrimeParameters
fn emit_params(&self) -> Self::Parameters
fn from_params(params: Self::Parameters) -> Self
fn map_params(&self, f: impl Fn(Self::Parameters) -> Self::Parameters) -> Self
Source§impl Sampleable<StickBreakingDiscrete> for BetaPrime
Available on crate feature experimental only.
impl Sampleable<StickBreakingDiscrete> for BetaPrime
Available on crate feature
experimental only.Source§impl Sampleable<f64> for BetaPrime
impl Sampleable<f64> for BetaPrime
Auto Trait Implementations§
impl !Freeze for BetaPrime
impl RefUnwindSafe for BetaPrime
impl Send for BetaPrime
impl Sync for BetaPrime
impl Unpin for BetaPrime
impl UnwindSafe for BetaPrime
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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 moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.