pub struct Gamma { /* private fields */ }
Expand description
Gamma distribution G(α, β) over x in (0, ∞).
NOTE: The gamma distribution is parameterized in terms of shape, α, and rate, β.
β^α
f(x|α, β) = ---- x^(α-1) e^(-βx)
Γ(α)
Implementations§
source§impl Gamma
impl Gamma
sourcepub fn new(shape: f64, rate: f64) -> Result<Self, GammaError>
pub fn new(shape: f64, rate: f64) -> Result<Self, GammaError>
Create a new Gamma
distribution with shape (α) and rate (β).
sourcepub fn new_unchecked(shape: f64, rate: f64) -> Self
pub fn new_unchecked(shape: f64, rate: f64) -> Self
Creates a new Gamma without checking whether the parameters are valid.
sourcepub fn shape(&self) -> f64
pub fn shape(&self) -> f64
Get the shape parameter
Example
let gam = Gamma::new(2.0, 1.0).unwrap();
assert_eq!(gam.shape(), 2.0);
sourcepub fn set_shape(&mut self, shape: f64) -> Result<(), GammaError>
pub fn set_shape(&mut self, shape: f64) -> Result<(), GammaError>
Set the shape parameter
Example
let mut gam = Gamma::new(2.0, 1.0).unwrap();
assert_eq!(gam.shape(), 2.0);
gam.set_shape(1.1).unwrap();
assert_eq!(gam.shape(), 1.1);
Will error for invalid values
assert!(gam.set_shape(1.1).is_ok());
assert!(gam.set_shape(0.0).is_err());
assert!(gam.set_shape(-1.0).is_err());
assert!(gam.set_shape(std::f64::INFINITY).is_err());
assert!(gam.set_shape(std::f64::NEG_INFINITY).is_err());
assert!(gam.set_shape(std::f64::NAN).is_err());
sourcepub fn set_shape_unchecked(&mut self, shape: f64)
pub fn set_shape_unchecked(&mut self, shape: f64)
Set the shape parameter without input validation
sourcepub fn rate(&self) -> f64
pub fn rate(&self) -> f64
Get the rate parameter
Example
let gam = Gamma::new(2.0, 1.0).unwrap();
assert_eq!(gam.rate(), 1.0);
sourcepub fn set_rate(&mut self, rate: f64) -> Result<(), GammaError>
pub fn set_rate(&mut self, rate: f64) -> Result<(), GammaError>
Set the rate parameter
Example
let mut gam = Gamma::new(2.0, 1.0).unwrap();
assert_eq!(gam.rate(), 1.0);
gam.set_rate(1.1).unwrap();
assert_eq!(gam.rate(), 1.1);
Will error for invalid values
assert!(gam.set_rate(1.1).is_ok());
assert!(gam.set_rate(0.0).is_err());
assert!(gam.set_rate(-1.0).is_err());
assert!(gam.set_rate(std::f64::INFINITY).is_err());
assert!(gam.set_rate(std::f64::NEG_INFINITY).is_err());
assert!(gam.set_rate(std::f64::NAN).is_err());
sourcepub fn set_rate_unchecked(&mut self, rate: f64)
pub fn set_rate_unchecked(&mut self, rate: f64)
Set the rate parameter without input validation
Trait Implementations§
source§impl ConjugatePrior<u16, Poisson> for Gamma
impl ConjugatePrior<u16, Poisson> for Gamma
source§fn posterior(&self, x: &DataOrSuffStat<'_, u16, Poisson>) -> Self
fn posterior(&self, x: &DataOrSuffStat<'_, u16, Poisson>) -> Self
Computes the posterior distribution from the data
source§fn ln_m_cache(&self) -> Self::LnMCache
fn ln_m_cache(&self) -> Self::LnMCache
Compute the cache for the log marginal likelihood.
source§fn ln_m_with_cache(
&self,
cache: &Self::LnMCache,
x: &DataOrSuffStat<'_, u16, Poisson>
) -> f64
fn ln_m_with_cache( &self, cache: &Self::LnMCache, x: &DataOrSuffStat<'_, u16, Poisson> ) -> f64
Log marginal likelihood with supplied cache.
source§fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u16, Poisson>) -> Self::LnPpCache
fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u16, Poisson>) -> Self::LnPpCache
Compute the cache for the Log posterior predictive of y given x. Read more
source§fn ln_pp_with_cache(&self, cache: &Self::LnPpCache, y: &u16) -> f64
fn ln_pp_with_cache(&self, cache: &Self::LnPpCache, y: &u16) -> f64
Log posterior predictive of y given x with supplied ln(norm)
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
source§impl ConjugatePrior<u32, Poisson> for Gamma
impl ConjugatePrior<u32, Poisson> for Gamma
source§fn posterior(&self, x: &DataOrSuffStat<'_, u32, Poisson>) -> Self
fn posterior(&self, x: &DataOrSuffStat<'_, u32, Poisson>) -> Self
Computes the posterior distribution from the data
source§fn ln_m_cache(&self) -> Self::LnMCache
fn ln_m_cache(&self) -> Self::LnMCache
Compute the cache for the log marginal likelihood.
source§fn ln_m_with_cache(
&self,
cache: &Self::LnMCache,
x: &DataOrSuffStat<'_, u32, Poisson>
) -> f64
fn ln_m_with_cache( &self, cache: &Self::LnMCache, x: &DataOrSuffStat<'_, u32, Poisson> ) -> f64
Log marginal likelihood with supplied cache.
source§fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u32, Poisson>) -> Self::LnPpCache
fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u32, Poisson>) -> Self::LnPpCache
Compute the cache for the Log posterior predictive of y given x. Read more
source§fn ln_pp_with_cache(&self, cache: &Self::LnPpCache, y: &u32) -> f64
fn ln_pp_with_cache(&self, cache: &Self::LnPpCache, y: &u32) -> f64
Log posterior predictive of y given x with supplied ln(norm)
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
source§impl ConjugatePrior<u8, Poisson> for Gamma
impl ConjugatePrior<u8, Poisson> for Gamma
source§fn posterior(&self, x: &DataOrSuffStat<'_, u8, Poisson>) -> Self
fn posterior(&self, x: &DataOrSuffStat<'_, u8, Poisson>) -> Self
Computes the posterior distribution from the data
source§fn ln_m_cache(&self) -> Self::LnMCache
fn ln_m_cache(&self) -> Self::LnMCache
Compute the cache for the log marginal likelihood.
source§fn ln_m_with_cache(
&self,
cache: &Self::LnMCache,
x: &DataOrSuffStat<'_, u8, Poisson>
) -> f64
fn ln_m_with_cache( &self, cache: &Self::LnMCache, x: &DataOrSuffStat<'_, u8, Poisson> ) -> f64
Log marginal likelihood with supplied cache.
source§fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u8, Poisson>) -> Self::LnPpCache
fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u8, Poisson>) -> Self::LnPpCache
Compute the cache for the Log posterior predictive of y given x. Read more
source§fn ln_pp_with_cache(&self, cache: &Self::LnPpCache, y: &u8) -> f64
fn ln_pp_with_cache(&self, cache: &Self::LnPpCache, y: &u8) -> f64
Log posterior predictive of y given x with supplied ln(norm)
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
source§impl ContinuousDistr<Poisson> for Gamma
impl ContinuousDistr<Poisson> for Gamma
source§impl ContinuousDistr<f32> for Gamma
impl ContinuousDistr<f32> for Gamma
source§impl ContinuousDistr<f64> for Gamma
impl ContinuousDistr<f64> for Gamma
source§impl<'de> Deserialize<'de> for Gamma
impl<'de> Deserialize<'de> for Gamma
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 PartialEq<Gamma> for Gamma
impl PartialEq<Gamma> for Gamma
source§impl Rv<f32> for Gamma
impl Rv<f32> for Gamma
source§impl Rv<f64> for Gamma
impl Rv<f64> for Gamma
Auto Trait Implementations§
impl RefUnwindSafe for Gamma
impl Send for Gamma
impl Sync for Gamma
impl Unpin for Gamma
impl UnwindSafe for Gamma
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<Fx> Rv<Datum> for Fxwhere
Fx: RvDatum,
impl<Fx> Rv<Datum> for Fxwhere Fx: RvDatum,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§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 more§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).§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.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.