Struct rv::dist::Kumaraswamy[][src]

pub struct Kumaraswamy { /* fields omitted */ }

Kumaraswamy distribution, Kumaraswamy(α, β) over x in (0, 1).

Examples

The relationship between the CDF and the inverse CDF.

let kuma = Kumaraswamy::new(2.1, 3.4).unwrap();

let x = 0.6_f64;
let p: f64 = kuma.cdf(&x);
let y: f64 = kuma.invcdf(p);

assert::close(x, y, 1E-10);

Kumaraswamy(a, 1) is equivalent to Beta(a, 1) and Kumaraswamy(1, b) is equivalent to Beta(1, b)

let kuma = Kumaraswamy::new(1.0, 3.5).unwrap();
let beta = Beta::new(1.0, 3.5).unwrap();

let xs = rv::misc::linspace(0.1, 0.9, 10);

for x in xs.iter() {
    assert::close(kuma.f(x), beta.f(x), 1E-10);
}

Implementations

impl Kumaraswamy[src]

pub fn new(a: f64, b: f64) -> Result<Self, KumaraswamyError>[src]

Create a Beta distribution with even density over (0, 1).

Example


let kuma_good = Kumaraswamy::new(1.0, 1.0);
assert!(kuma_good.is_ok());

// Invalid negative parameter
let kuma_bad  = Kumaraswamy::new(-5.0, 1.0);
assert!(kuma_bad.is_err());

pub fn new_unchecked(a: f64, b: f64) -> Self[src]

Creates a new Kumaraswamy without checking whether the parameters are valid.

pub fn uniform() -> Self[src]

Create a Kumaraswamy distribution with even density over (0, 1).

Example

let kuma = Kumaraswamy::uniform();
assert_eq!(kuma, Kumaraswamy::new(1.0, 1.0).unwrap());

pub fn centered(a: f64) -> Result<Self, KumaraswamyError>[src]

Create a Kumaraswamy distribution with median 0.5

Notes

The distribution will not necessarily be symmetrical about x = 0.5, i.e., for c < 0.5, f(0.5 - c) may not equal f(0.5 + c).

Examples

// Bowl-shaped
let kuma_1 = Kumaraswamy::centered(0.5).unwrap();
let median_1: f64 = kuma_1.median().unwrap();
assert::close(median_1, 0.5, 1E-10);
assert::close(kuma_1.cdf(&0.5), 0.5, 1E-10);
assert::close(kuma_1.b(), 0.5644763825137, 1E-10);

// Cone-shaped
let kuma_2 = Kumaraswamy::centered(2.0).unwrap();
let median_2: f64 = kuma_2.median().unwrap();
assert::close(median_2, 0.5, 1E-10);
assert::close(kuma_2.cdf(&0.5), 0.5, 1E-10);
assert::close(kuma_2.b(), 2.409420839653209, 1E-10);

The PDF will most likely not be symmetrical about 0.5

fn absolute_error(a: f64, b: f64) -> f64 {
    (a - b).abs()
}

let kuma = Kumaraswamy::centered(2.0).unwrap();
assert!(absolute_error(kuma.f(&0.1), kuma.f(&0.9)) > 1E-8);

pub fn a(&self) -> f64[src]

Get the a parameter

Example

let kuma = Kumaraswamy::new(1.0, 5.0).unwrap();
assert_eq!(kuma.a(), 1.0);

pub fn b(&self) -> f64[src]

Get the b parameter

Example

let kuma = Kumaraswamy::new(1.0, 5.0).unwrap();
assert_eq!(kuma.b(), 5.0);

pub fn set_a(&mut self, a: f64) -> Result<(), KumaraswamyError>[src]

Set the value of the a parameter

Example

let mut kuma = Kumaraswamy::new(1.0, 5.0).unwrap();
assert_eq!(kuma.a(), 1.0);

kuma.set_a(2.3).unwrap();
assert_eq!(kuma.a(), 2.3);

Will error for invalid values

assert!(kuma.set_a(2.3).is_ok());
assert!(kuma.set_a(0.0).is_err());
assert!(kuma.set_a(std::f64::INFINITY).is_err());
assert!(kuma.set_a(std::f64::NEG_INFINITY).is_err());
assert!(kuma.set_a(std::f64::NAN).is_err());

pub fn set_a_unchecked(&mut self, a: f64)[src]

Set the value of the a parameter without input validation

pub fn set_b(&mut self, b: f64) -> Result<(), KumaraswamyError>[src]

Set the value of the b parameter

Example

let mut kuma = Kumaraswamy::new(1.0, 5.0).unwrap();
assert_eq!(kuma.b(), 5.0);

kuma.set_b(2.3).unwrap();
assert_eq!(kuma.b(), 2.3);

Will error for invalid values

assert!(kuma.set_b(2.3).is_ok());
assert!(kuma.set_b(0.0).is_err());
assert!(kuma.set_b(std::f64::INFINITY).is_err());
assert!(kuma.set_b(std::f64::NEG_INFINITY).is_err());
assert!(kuma.set_b(std::f64::NAN).is_err());

pub fn set_b_unchecked(&mut self, b: f64)[src]

Set the value of the b parameter without input validation

Trait Implementations

impl Cdf<f32> for Kumaraswamy[src]

impl Cdf<f64> for Kumaraswamy[src]

impl Clone for Kumaraswamy[src]

impl ContinuousDistr<f32> for Kumaraswamy[src]

impl ContinuousDistr<f64> for Kumaraswamy[src]

impl Debug for Kumaraswamy[src]

impl Default for Kumaraswamy[src]

impl Display for Kumaraswamy[src]

impl Entropy for Kumaraswamy[src]

impl InverseCdf<f32> for Kumaraswamy[src]

impl InverseCdf<f64> for Kumaraswamy[src]

impl Mean<f32> for Kumaraswamy[src]

impl Mean<f64> for Kumaraswamy[src]

impl Median<f32> for Kumaraswamy[src]

impl Median<f64> for Kumaraswamy[src]

impl Mode<f32> for Kumaraswamy[src]

impl Mode<f64> for Kumaraswamy[src]

impl PartialEq<Kumaraswamy> for Kumaraswamy[src]

impl Rv<f32> for Kumaraswamy[src]

impl Rv<f64> for Kumaraswamy[src]

impl Support<f32> for Kumaraswamy[src]

impl Support<f64> for Kumaraswamy[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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