Struct russell_stat::DistributionFrechet

source ·
pub struct DistributionFrechet { /* private fields */ }
Expand description

Implements the Frechet distribution

This is a Type II Extreme Value Distribution (largest value)

See: https://en.wikipedia.org/wiki/Fr%C3%A9chet_distribution

Frechet

Implementations§

source§

impl DistributionFrechet

source

pub fn new(location: f64, scale: f64, shape: f64) -> Result<Self, StrError>

Allocates a new instance

§Input
  • location – location parameter
  • shape – shape parameter

Trait Implementations§

source§

impl ProbabilityDistribution for DistributionFrechet

source§

fn pdf(&self, x: f64) -> f64

Evaluates the Probability Density Function (PDF)

§Examples
use russell_lab::math::NAPIER;
use russell_stat::*;

fn main() -> Result<(), StrError> {
    let (location, scale, shape) = (0.0, 1.0, 2.0);
    let dist = DistributionFrechet::new(location, scale, shape)?;
    assert_eq!(dist.pdf(1.0), 2.0 / NAPIER);
    // Mathematica: PDF[FrechetDistribution[2, 1], 1] == 2/E
    Ok(())
}
source§

fn cdf(&self, x: f64) -> f64

Evaluates the Cumulative Distribution Function (CDF)

§Examples
use russell_lab::approx_eq;
use russell_stat::*;

fn main() -> Result<(), StrError> {
    // Example from <https://reference.wolfram.com/language/ref/FrechetDistribution.html>
    let (location, scale, shape) = (0.0, 6.3, 0.71);
    let dist = DistributionFrechet::new(location, scale, shape)?;
    let p_xx_less_than_30 = dist.cdf(30.0);
    let p_xx_greater_than_30 = 1.0 - p_xx_less_than_30;
    println!("P(X > 30) = {}", p_xx_greater_than_30);
    approx_eq(p_xx_greater_than_30, 0.2812192884182272, 1e-15);
    Ok(())
}
source§

fn mean(&self) -> f64

Returns the Mean

§Examples
use russell_lab::{approx_eq, math::SQRT_PI};
use russell_stat::*;

fn main() -> Result<(), StrError> {
    let (location, scale, shape) = (0.0, 3.0, 2.0);
    let dist = DistributionFrechet::new(location, scale, shape)?;
    approx_eq(dist.mean(), 3.0 * SQRT_PI, 1e-15);
    // Mathematica: Mean[FrechetDistribution[2, 3]]
    Ok(())
}
source§

fn variance(&self) -> f64

Returns the Variance

§Examples
use russell_lab::approx_eq;
use russell_stat::*;

fn main() -> Result<(), StrError> {
    let (location, scale, shape) = (0.0, 3.0, 4.0);
    let dist = DistributionFrechet::new(location, scale, shape)?;
    approx_eq(dist.variance(), 2.4372698060239768, 1e-14);
    // Mathematica: N[Variance[FrechetDistribution[4, 3]], 17]
    Ok(())
}
source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> f64

Generates a pseudo-random number belonging to this probability distribution

§Examples
use russell_stat::*;

fn main() -> Result<(), StrError> {
    let (location, scale, shape) = (0.0, 3.0, 4.0);
    let dist = DistributionFrechet::new(location, scale, shape)?;
    let mut rng = get_rng();
    println!("sample = {}", dist.sample(&mut rng));
    Ok(())
}

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V