Struct russell_stat::DistributionUniform

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

Implements the continuous Uniform distribution

See: https://en.wikipedia.org/wiki/Continuous_uniform_distribution

Uniform

Implementations§

source§

impl DistributionUniform

source

pub fn new(xmin: f64, xmax: f64) -> Result<Self, StrError>

Allocates a new instance

§Input
  • xmin – min x value
  • xmax – max x value

Trait Implementations§

source§

impl ProbabilityDistribution for DistributionUniform

source§

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

Evaluates the Probability Density Function (PDF)

§Examples
use russell_stat::*;

fn main() -> Result<(), StrError> {
    let dist = DistributionUniform::new(1.0, 2.0)?;
    assert_eq!(dist.pdf(1.5), 1.0);
    Ok(())
}
source§

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

Evaluates the Cumulative Distribution Function (CDF)

§Examples
use russell_stat::*;

fn main() -> Result<(), StrError> {
    let dist = DistributionUniform::new(1.0, 2.0)?;
    assert_eq!(dist.cdf(1.5), 0.5);
    Ok(())
}
source§

fn mean(&self) -> f64

Returns the Mean

§Examples
use russell_stat::*;

fn main() -> Result<(), StrError> {
    let dist = DistributionUniform::new(1.0, 2.0)?;
    assert_eq!(dist.mean(), 1.5);
    Ok(())
}
source§

fn variance(&self) -> f64

Returns the Variance

§Examples
use russell_stat::*;

fn main() -> Result<(), StrError> {
    let dist = DistributionUniform::new(1.0, 2.0)?;
    assert_eq!(dist.variance(), 1.0 / 12.0);
    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 dist = DistributionUniform::new(1.0, 2.0)?;
    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