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
impl Kumaraswamy
sourcepub fn new(a: f64, b: f64) -> Result<Self, KumaraswamyError>
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());
sourcepub fn new_unchecked(a: f64, b: f64) -> Self
pub fn new_unchecked(a: f64, b: f64) -> Self
Creates a new Kumaraswamy without checking whether the parameters are valid.
sourcepub fn uniform() -> Self
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());
sourcepub fn centered(a: f64) -> Result<Self, KumaraswamyError>
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);
sourcepub fn a(&self) -> f64
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);
sourcepub fn b(&self) -> f64
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);
sourcepub fn set_a(&mut self, a: f64) -> Result<(), KumaraswamyError>
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(f64::INFINITY).is_err());
assert!(kuma.set_a(f64::NEG_INFINITY).is_err());
assert!(kuma.set_a(f64::NAN).is_err());
sourcepub fn set_a_unchecked(&mut self, a: f64)
pub fn set_a_unchecked(&mut self, a: f64)
Set the value of the a parameter without input validation
sourcepub fn set_b(&mut self, b: f64) -> Result<(), KumaraswamyError>
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(f64::INFINITY).is_err());
assert!(kuma.set_b(f64::NEG_INFINITY).is_err());
assert!(kuma.set_b(f64::NAN).is_err());
sourcepub fn set_b_unchecked(&mut self, b: f64)
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
impl Cdf<f32> for Kumaraswamy
source§impl Cdf<f64> for Kumaraswamy
impl Cdf<f64> for Kumaraswamy
source§impl Clone for Kumaraswamy
impl Clone for Kumaraswamy
source§fn clone(&self) -> Kumaraswamy
fn clone(&self) -> Kumaraswamy
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl ContinuousDistr<f32> for Kumaraswamy
impl ContinuousDistr<f32> for Kumaraswamy
source§impl ContinuousDistr<f64> for Kumaraswamy
impl ContinuousDistr<f64> for Kumaraswamy
source§impl Debug for Kumaraswamy
impl Debug for Kumaraswamy
source§impl Default for Kumaraswamy
impl Default for Kumaraswamy
source§impl<'de> Deserialize<'de> for Kumaraswamy
impl<'de> Deserialize<'de> for Kumaraswamy
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for Kumaraswamy
impl Display for Kumaraswamy
source§impl From<&Kumaraswamy> for String
impl From<&Kumaraswamy> for String
source§fn from(kuma: &Kumaraswamy) -> String
fn from(kuma: &Kumaraswamy) -> String
source§impl HasDensity<f32> for Kumaraswamy
impl HasDensity<f32> for Kumaraswamy
source§impl HasDensity<f64> for Kumaraswamy
impl HasDensity<f64> for Kumaraswamy
source§impl InverseCdf<f32> for Kumaraswamy
impl InverseCdf<f32> for Kumaraswamy
source§impl InverseCdf<f64> for Kumaraswamy
impl InverseCdf<f64> for Kumaraswamy
source§impl Mean<f32> for Kumaraswamy
impl Mean<f32> for Kumaraswamy
source§impl Mean<f64> for Kumaraswamy
impl Mean<f64> for Kumaraswamy
source§impl Median<f32> for Kumaraswamy
impl Median<f32> for Kumaraswamy
source§impl Median<f64> for Kumaraswamy
impl Median<f64> for Kumaraswamy
source§impl Mode<f32> for Kumaraswamy
impl Mode<f32> for Kumaraswamy
source§impl Mode<f64> for Kumaraswamy
impl Mode<f64> for Kumaraswamy
source§impl Parameterized for Kumaraswamy
impl Parameterized for Kumaraswamy
type Parameters = KumaraswamyParameters
fn emit_params(&self) -> Self::Parameters
fn from_params(params: Self::Parameters) -> Self
source§impl PartialEq for Kumaraswamy
impl PartialEq for Kumaraswamy
source§fn eq(&self, other: &Kumaraswamy) -> bool
fn eq(&self, other: &Kumaraswamy) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Sampleable<f32> for Kumaraswamy
impl Sampleable<f32> for Kumaraswamy
source§impl Sampleable<f64> for Kumaraswamy
impl Sampleable<f64> for Kumaraswamy
source§impl Serialize for Kumaraswamy
impl Serialize for Kumaraswamy
source§impl Support<f32> for Kumaraswamy
impl Support<f32> for Kumaraswamy
Auto Trait Implementations§
impl !Freeze for Kumaraswamy
impl RefUnwindSafe for Kumaraswamy
impl Send for Kumaraswamy
impl Sync for Kumaraswamy
impl Unpin for Kumaraswamy
impl UnwindSafe for Kumaraswamy
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.