[−][src]Struct statrs::distribution::Uniform

`pub struct Uniform { /* fields omitted */ }`

Implements the Continuous Uniform distribution

Examples

```use statrs::distribution::{Uniform, Continuous};
use statrs::statistics::Mean;

let n = Uniform::new(0.0, 1.0).unwrap();
assert_eq!(n.mean(), 0.5);
assert_eq!(n.pdf(0.5), 1.0);```

Methods

`impl Uniform`[src]

`pub fn new(min: f64, max: f64) -> Result<Uniform>`[src]

Constructs a new uniform distribution with a min of `min` and a max of `max`

Errors

Returns an error if `min` or `max` are `NaN`

Examples

```use statrs::distribution::Uniform;
use std::f64;

let mut result = Uniform::new(0.0, 1.0);
assert!(result.is_ok());

result = Uniform::new(f64::NAN, f64::NAN);
assert!(result.is_err());```

Trait Implementations

`impl Univariate<f64, f64> for Uniform`[src]

`fn cdf(&self, x: f64) -> f64`[src]

Calculates the cumulative distribution function for the uniform distribution at `x`

Formula

`(x - min) / (max - min)`

`impl Continuous<f64, f64> for Uniform`[src]

`fn pdf(&self, x: f64) -> f64`[src]

Calculates the probability density function for the continuous uniform distribution at `x`

Remarks

Returns `0.0` if `x` is not in `[min, max]`

Formula

`1 / (max - min)`

`fn ln_pdf(&self, x: f64) -> f64`[src]

Calculates the log probability density function for the continuous uniform distribution at `x`

Remarks

Returns `f64::NEG_INFINITY` if `x` is not in `[min, max]`

Formula

`ln(1 / (max - min))`

`impl Mean<f64> for Uniform`[src]

`fn mean(&self) -> f64`[src]

Returns the mean for the continuous uniform distribution

Formula

`(min + max) / 2`

`impl Variance<f64> for Uniform`[src]

`fn variance(&self) -> f64`[src]

Returns the variance for the continuous uniform distribution

Formula

`(max - min)^2 / 12`

`fn std_dev(&self) -> f64`[src]

Returns the standard deviation for the continuous uniform distribution

Formula

`sqrt((max - min)^2 / 12)`

`impl Entropy<f64> for Uniform`[src]

`fn entropy(&self) -> f64`[src]

Returns the entropy for the continuous uniform distribution

Formula

`ln(max - min)`

`impl Skewness<f64> for Uniform`[src]

`fn skewness(&self) -> f64`[src]

Returns the skewness for the continuous uniform distribution

Formula

`0`

`impl Median<f64> for Uniform`[src]

`fn median(&self) -> f64`[src]

Returns the median for the continuous uniform distribution

Formula

`(min + max) / 2`

`impl Mode<f64> for Uniform`[src]

`fn mode(&self) -> f64`[src]

Returns the mode for the continuous uniform distribution

Remarks

Since every element has an equal probability, mode simply returns the middle element

Formula

`N/A // (max + min) / 2 for the middle element`

`impl Clone for Uniform`[src]

`fn clone_from(&mut self, source: &Self)`1.0.0[src]

Performs copy-assignment from `source`. Read more

`impl Distribution<f64> for Uniform`[src]

`fn sample_iter<R>(&'a self, rng: &'a mut R) -> DistIter<'a, Self, R, T> where    R: Rng, `[src]

Create an iterator that generates random values of `T`, using `rng` as the source of randomness. Read more

Blanket Implementations

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

`type Owned = T`

The resulting type after obtaining ownership.

`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.