Struct rv::dist::Kumaraswamy

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

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§

source§

impl Kumaraswamy

source

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

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());
source

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

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

source

pub fn uniform() -> Self

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());
source

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

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);
source

pub fn a(&self) -> f64

Get the a parameter

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

pub fn b(&self) -> f64

Get the b parameter

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

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

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());
source

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

Set the value of the a parameter without input validation

source

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

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());
source

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

Set the value of the b parameter without input validation

Trait Implementations§

source§

impl Cdf<f32> for Kumaraswamy

source§

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

The value of the Cumulative Density Function at x Read more
source§

fn sf(&self, x: &X) -> f64

Survival function, 1 - CDF(x)
source§

impl Cdf<f64> for Kumaraswamy

source§

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

The value of the Cumulative Density Function at x Read more
source§

fn sf(&self, x: &X) -> f64

Survival function, 1 - CDF(x)
source§

impl Clone for Kumaraswamy

source§

fn clone(&self) -> Kumaraswamy

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl ContinuousDistr<f32> for Kumaraswamy

source§

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

The value of the Probability Density Function (PDF) at x Read more
source§

fn ln_pdf(&self, x: &X) -> f64

The value of the log Probability Density Function (PDF) at x Read more
source§

impl ContinuousDistr<f64> for Kumaraswamy

source§

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

The value of the Probability Density Function (PDF) at x Read more
source§

fn ln_pdf(&self, x: &X) -> f64

The value of the log Probability Density Function (PDF) at x Read more
source§

impl Debug for Kumaraswamy

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Kumaraswamy

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Kumaraswamy

source§

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 Display for Kumaraswamy

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Entropy for Kumaraswamy

source§

fn entropy(&self) -> f64

The entropy, H(X)
source§

impl From<&Kumaraswamy> for String

source§

fn from(kuma: &Kumaraswamy) -> String

Converts to this type from the input type.
source§

impl InverseCdf<f32> for Kumaraswamy

source§

fn invcdf(&self, p: f64) -> f32

The value of the x at the given probability in the CDF Read more
source§

fn quantile(&self, p: f64) -> X

Alias for invcdf
source§

fn interval(&self, p: f64) -> (X, X)

Interval containing p proportion for the probability Read more
source§

impl InverseCdf<f64> for Kumaraswamy

source§

fn invcdf(&self, p: f64) -> f64

The value of the x at the given probability in the CDF Read more
source§

fn quantile(&self, p: f64) -> X

Alias for invcdf
source§

fn interval(&self, p: f64) -> (X, X)

Interval containing p proportion for the probability Read more
source§

impl Mean<f32> for Kumaraswamy

source§

fn mean(&self) -> Option<f32>

Returns None if the mean is undefined
source§

impl Mean<f64> for Kumaraswamy

source§

fn mean(&self) -> Option<f64>

Returns None if the mean is undefined
source§

impl Median<f32> for Kumaraswamy

source§

fn median(&self) -> Option<f32>

Returns None if the median is undefined
source§

impl Median<f64> for Kumaraswamy

source§

fn median(&self) -> Option<f64>

Returns None if the median is undefined
source§

impl Mode<f32> for Kumaraswamy

source§

fn mode(&self) -> Option<f32>

Returns None if the mode is undefined or is not a single value
source§

impl Mode<f64> for Kumaraswamy

source§

fn mode(&self) -> Option<f64>

Returns None if the mode is undefined or is not a single value
source§

impl PartialEq for Kumaraswamy

source§

fn eq(&self, other: &Kumaraswamy) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Rv<f32> for Kumaraswamy

source§

fn ln_f(&self, x: &f32) -> f64

Probability function Read more
source§

fn draw<R: Rng>(&self, rng: &mut R) -> f32

Single draw from the Rv Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>

Multiple draws of the Rv Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Rv<f64> for Kumaraswamy

source§

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

Probability function Read more
source§

fn draw<R: Rng>(&self, rng: &mut R) -> f64

Single draw from the Rv Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>

Multiple draws of the Rv Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Serialize for Kumaraswamy

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Support<f32> for Kumaraswamy

source§

fn supports(&self, x: &f32) -> bool

Returns true if x is in the support of the Rv Read more
source§

impl Support<f64> for Kumaraswamy

source§

fn supports(&self, x: &f64) -> bool

Returns true if x is in the support of the Rv Read more

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<Fx> Rv<Datum> for Fx
where Fx: RvDatum,

source§

fn ln_f(&self, x: &Datum) -> f64

Probability function Read more
source§

fn draw<R>(&self, rng: &mut R) -> Datum
where R: Rng,

Single draw from the Rv Read more
source§

fn sample<R>(&self, n: usize, rng: &mut R) -> Vec<Datum>
where R: Rng,

Multiple draws of the Rv Read more
source§

fn sample_stream<'r, R>( &'r self, rng: &'r mut R ) -> Box<dyn Iterator<Item = Datum> + 'r>
where R: Rng,

Create a never-ending iterator of samples Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
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

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> DeserializeOwnedAlias for T

source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

source§

impl<T> SendAlias for T

source§

impl<T> SendSyncUnwindSafe for T
where T: Send + Sync + UnwindSafe + ?Sized,

source§

impl<T> SerializeAlias for T
where T: Serialize,

source§

impl<T> SyncAlias for T