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(f64::INFINITY).is_err());
assert!(gam.set_shape(f64::NEG_INFINITY).is_err());
assert!(gam.set_shape(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(f64::INFINITY).is_err());
assert!(gam.set_rate(f64::NEG_INFINITY).is_err());
assert!(gam.set_rate(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
fn posterior(&self, x: &DataOrSuffStat<'_, u16, Poisson>) -> 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,
x: &DataOrSuffStat<'_, u16, Poisson>,
) -> f64
fn ln_m_with_cache( &self, cache: &Self::MCache, x: &DataOrSuffStat<'_, u16, Poisson>, ) -> f64
Log marginal likelihood with supplied cache.
Source§fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u16, Poisson>) -> Self::PpCache
fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u16, Poisson>) -> 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: &u16) -> f64
fn ln_pp_with_cache(&self, cache: &Self::PpCache, y: &u16) -> 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 ConjugatePrior<u32, Poisson> for Gamma
impl ConjugatePrior<u32, Poisson> for Gamma
fn posterior(&self, x: &DataOrSuffStat<'_, u32, Poisson>) -> 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,
x: &DataOrSuffStat<'_, u32, Poisson>,
) -> f64
fn ln_m_with_cache( &self, cache: &Self::MCache, x: &DataOrSuffStat<'_, u32, Poisson>, ) -> f64
Log marginal likelihood with supplied cache.
Source§fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u32, Poisson>) -> Self::PpCache
fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u32, Poisson>) -> 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: &u32) -> f64
fn ln_pp_with_cache(&self, cache: &Self::PpCache, y: &u32) -> 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 ConjugatePrior<u8, Poisson> for Gamma
impl ConjugatePrior<u8, Poisson> for Gamma
fn posterior(&self, x: &DataOrSuffStat<'_, u8, Poisson>) -> 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,
x: &DataOrSuffStat<'_, u8, Poisson>,
) -> f64
fn ln_m_with_cache( &self, cache: &Self::MCache, x: &DataOrSuffStat<'_, u8, Poisson>, ) -> f64
Log marginal likelihood with supplied cache.
Source§fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u8, Poisson>) -> Self::PpCache
fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u8, Poisson>) -> 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: &u8) -> f64
fn ln_pp_with_cache(&self, cache: &Self::PpCache, y: &u8) -> 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<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 HasDensity<Poisson> for Gamma
impl HasDensity<Poisson> for Gamma
Source§impl HasDensity<f32> for Gamma
impl HasDensity<f32> for Gamma
Source§impl HasDensity<f64> for Gamma
impl HasDensity<f64> for Gamma
Source§impl Parameterized for Gamma
impl Parameterized for Gamma
type Parameters = GammaParameters
fn emit_params(&self) -> Self::Parameters
fn from_params(params: Self::Parameters) -> Self
Source§impl Sampleable<Poisson> for Gamma
impl Sampleable<Poisson> for Gamma
Source§impl Sampleable<f32> for Gamma
impl Sampleable<f32> for Gamma
Source§impl Sampleable<f64> for Gamma
impl Sampleable<f64> for Gamma
Auto Trait Implementations§
impl !Freeze for Gamma
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<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.