Struct statrs::distribution::Gamma
[−]
[src]
pub struct Gamma { /* fields omitted */ }
Implements the Gamma distribution
Examples
use statrs::distribution::{Gamma, Continuous}; use statrs::statistics::Mean; use statrs::prec; let n = Gamma::new(3.0, 1.0).unwrap(); assert_eq!(n.mean(), 3.0); assert!(prec::almost_eq(n.pdf(2.0), 0.270670566473225383788, 1e-15));
Methods
impl Gamma
[src]
fn new(shape: f64, rate: f64) -> Result<Gamma>
Constructs a new 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 <= 0.0
or rate <= 0.0
Examples
use statrs::distribution::Gamma; let mut result = Gamma::new(3.0, 1.0); assert!(result.is_ok()); let result = Gamma::new(0.0, 0.0); assert!(result.is_err());
fn shape(&self) -> f64
Returns the shape (α) of the gamma distribution
Examples
use statrs::distribution::Gamma; let n = Gamma::new(3.0, 1.0).unwrap(); assert_eq!(n.shape(), 3.0);
fn rate(&self) -> f64
Returns the rate (β) of the gamma distribution
Examples
use statrs::distribution::Gamma; let n = Gamma::new(3.0, 1.0).unwrap(); assert_eq!(n.rate(), 1.0);
Trait Implementations
impl Debug for Gamma
[src]
impl Copy for Gamma
[src]
impl Clone for Gamma
[src]
fn clone(&self) -> Gamma
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl PartialEq for Gamma
[src]
fn eq(&self, __arg_0: &Gamma) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Gamma) -> bool
This method tests for !=
.
impl Sample<f64> for Gamma
[src]
fn sample<R: Rng>(&mut self, r: &mut R) -> f64
Generate a random sample from a gamma
distribution using r
as the source of randomness.
Refer here for implementation details
impl IndependentSample<f64> for Gamma
[src]
fn ind_sample<R: Rng>(&self, r: &mut R) -> f64
Generate a random independent sample from a gamma
distribution using r
as the source of randomness.
Refer here for implementation details
impl Distribution<f64> for Gamma
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
Generate a random sample from a gamma distribution using
r
as the source of randomness. The implementation is based
on:
Examples
use rand::StdRng; use statrs::distribution::{Gamma, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Gamma::new(3.0, 1.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Univariate<f64, f64> for Gamma
[src]
impl Min<f64> for Gamma
[src]
fn min(&self) -> f64
Returns the minimum value in the domain of the gamma distribution representable by a double precision float
Formula
0
impl Max<f64> for Gamma
[src]
fn max(&self) -> f64
Returns the maximum value in the domain of the gamma distribution representable by a double precision float
Formula
INF
impl Mean<f64> for Gamma
[src]
impl Variance<f64> for Gamma
[src]
fn variance(&self) -> f64
Returns the variance of the gamma distribution
Formula
α / β^2
where α
is the shape and β
is the rate
fn std_dev(&self) -> f64
Returns the standard deviation of the gamma distribution
Formula
sqrt(α) / β
where α
is the shape and β
is the rate
impl Entropy<f64> for Gamma
[src]
fn entropy(&self) -> f64
Returns the entropy of the gamma distribution
Formula
α - ln(β) + ln(Γ(α)) + (1 - α) * ψ(α)
where α
is the shape, β
is the rate, Γ
is the gamma function,
and ψ
is the digamma function
impl Skewness<f64> for Gamma
[src]
impl Mode<f64> for Gamma
[src]
impl Continuous<f64, f64> for Gamma
[src]
fn pdf(&self, x: f64) -> f64
Calculates the probability density function for the gamma distribution
at x
Panics
If x <= 0.0
Remarks
Returns f64::INFINITY
if x == shape && rate == f64::INFINITY
Otherwise returns 0.0
if rate == f64::INFINITY
Formula
(β^α / Γ(α)) * x^(α - 1) * e ^(-β * x)
where α
is the shape, β
is the rate, and Γ
is the gamma function
fn ln_pdf(&self, x: f64) -> f64
Calculates the log probability density function for the gamma distribution
at x
Panics
If x <= 0.0
Remarks
Returns f64::INFINITY
if x == shape && rate == f64::INFINITY
Otherwise returns f64::NEG_INFINITY
if rate == f64::INFINITY
Formula
ln((β^α / Γ(α)) * x^(α - 1) * e ^(-β * x))
where α
is the shape, β
is the rate, and Γ
is the gamma function