Struct statrs::distribution::InverseGamma
source · [−]pub struct InverseGamma { /* private fields */ }
Expand description
Implements the Inverse Gamma distribution
Examples
use statrs::distribution::{InverseGamma, Continuous};
use statrs::statistics::Distribution;
use statrs::prec;
let n = InverseGamma::new(1.1, 0.1).unwrap();
assert!(prec::almost_eq(n.mean().unwrap(), 1.0, 1e-14));
assert_eq!(n.pdf(1.0), 0.07554920138253064);
Implementations
sourceimpl InverseGamma
impl InverseGamma
sourcepub fn new(shape: f64, rate: f64) -> Result<InverseGamma>
pub fn new(shape: f64, rate: f64) -> Result<InverseGamma>
Constructs a new inverse gamma distribution with a shape (α)
of shape
and a rate (β) of rate
Errors
Returns an error if shape
or rate
are NaN
.
Also returns an error if shape
or rate
are not in (0, +inf)
Examples
use statrs::distribution::InverseGamma;
let mut result = InverseGamma::new(3.0, 1.0);
assert!(result.is_ok());
result = InverseGamma::new(0.0, 0.0);
assert!(result.is_err());
Trait Implementations
sourceimpl Clone for InverseGamma
impl Clone for InverseGamma
sourcefn clone(&self) -> InverseGamma
fn clone(&self) -> InverseGamma
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Continuous<f64, f64> for InverseGamma
impl Continuous<f64, f64> for InverseGamma
sourceimpl ContinuousCDF<f64, f64> for InverseGamma
impl ContinuousCDF<f64, f64> for InverseGamma
sourcefn cdf(&self, x: f64) -> f64
fn cdf(&self, x: f64) -> f64
Calculates the cumulative distribution function for the inverse gamma
distribution at x
Formula
Γ(α, β / x) / Γ(α)
where the numerator is the upper incomplete gamma function,
the denominator is the gamma function, α
is the shape,
and β
is the rate
sourcefn sf(&self, x: f64) -> f64
fn sf(&self, x: f64) -> f64
Calculates the survival function for the inverse gamma
distribution at x
Formula
Γ(α, β / x) / Γ(α)
where the numerator is the lower incomplete gamma function,
the denominator is the gamma function, α
is the shape,
and β
is the rate
sourcefn inverse_cdf(&self, p: T) -> K
fn inverse_cdf(&self, p: T) -> K
Due to issues with rounding and floating-point accuracy the default
implementation may be ill-behaved.
Specialized inverse cdfs should be used whenever possible.
Performs a binary search on the domain of cdf
to obtain an approximation
of F^-1(p) := inf { x | F(x) >= p }
. Needless to say, performance may
may be lacking. Read more
sourceimpl Debug for InverseGamma
impl Debug for InverseGamma
sourceimpl Distribution<f64> for InverseGamma
impl Distribution<f64> for InverseGamma
sourcefn sample<R: Rng + ?Sized>(&self, r: &mut R) -> f64
fn sample<R: Rng + ?Sized>(&self, r: &mut R) -> f64
Generate a random value of T
, using rng
as the source of randomness.
sourcefn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T> where
R: Rng,
fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T> where
R: Rng,
Create an iterator that generates random values of T
, using rng
as
the source of randomness. Read more
sourceimpl Distribution<f64> for InverseGamma
impl Distribution<f64> for InverseGamma
sourcefn entropy(&self) -> Option<f64>
fn entropy(&self) -> Option<f64>
Returns the entropy of the inverse gamma distribution
Formula
α + ln(β * Γ(α)) - (1 + α) * ψ(α)
where α
is the shape, β
is the rate, Γ
is the gamma function,
and ψ
is the digamma function
sourceimpl Max<f64> for InverseGamma
impl Max<f64> for InverseGamma
sourceimpl Min<f64> for InverseGamma
impl Min<f64> for InverseGamma
sourceimpl Mode<Option<f64>> for InverseGamma
impl Mode<Option<f64>> for InverseGamma
sourceimpl PartialEq<InverseGamma> for InverseGamma
impl PartialEq<InverseGamma> for InverseGamma
sourcefn eq(&self, other: &InverseGamma) -> bool
fn eq(&self, other: &InverseGamma) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
impl Copy for InverseGamma
impl StructuralPartialEq for InverseGamma
Auto Trait Implementations
impl RefUnwindSafe for InverseGamma
impl Send for InverseGamma
impl Sync for InverseGamma
impl Unpin for InverseGamma
impl UnwindSafe for InverseGamma
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
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.