[][src]Struct statrs::distribution::DiscreteUniform

pub struct DiscreteUniform { /* fields omitted */ }

Implements the Discrete Uniform distribution

Examples

use statrs::distribution::{DiscreteUniform, Discrete};
use statrs::statistics::Mean;

let n = DiscreteUniform::new(0, 5).unwrap();
assert_eq!(n.mean(), 2.5);
assert_eq!(n.pmf(3), 1.0 / 6.0);

Methods

impl DiscreteUniform[src]

pub fn new(min: i64, max: i64) -> Result<DiscreteUniform>[src]

Constructs a new discrete uniform distribution with a minimum value of min and a maximum value of max.

Errors

Returns an error if max < min

Examples

use statrs::distribution::DiscreteUniform;

let mut result = DiscreteUniform::new(0, 5);
assert!(result.is_ok());

result = DiscreteUniform::new(5, 0);
assert!(result.is_err());

Trait Implementations

impl Distribution<f64> for DiscreteUniform[src]

fn sample<R: Rng>(&self, r: &mut R) -> f64[src]

Generate a random sample from the discrete uniform distribution using r as the source of randomness in the range [min, max]

Examples

use rand::StdRng;
use statrs::distribution::{DiscreteUniform, Distribution};

let mut r = rand::StdRng::new().unwrap();
let n = DiscreteUniform::new(0, 5).unwrap();
print!("{}", n.sample::<StdRng>(&mut r));

impl Univariate<i64, f64> for DiscreteUniform[src]

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

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

Formula

This example is not tested
(floor(x) - min + 1) / (max - min + 1)

impl Discrete<i64, f64> for DiscreteUniform[src]

fn pmf(&self, x: i64) -> f64[src]

Calculates the probability mass function for the discrete uniform distribution at x

Remarks

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

Formula

This example is not tested
1 / (max - min + 1)

fn ln_pmf(&self, x: i64) -> f64[src]

Calculates the log probability mass function for the discrete uniform distribution at x

Remarks

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

Formula

This example is not tested
ln(1 / (max - min + 1))

impl Min<i64> for DiscreteUniform[src]

fn min(&self) -> i64[src]

Returns the minimum value in the domain of the discrete uniform distribution

Remarks

This is the same value as the minimum passed into the constructor

impl Max<i64> for DiscreteUniform[src]

fn max(&self) -> i64[src]

Returns the maximum value in the domain of the discrete uniform distribution

Remarks

This is the same value as the maximum passed into the constructor

impl Mean<f64> for DiscreteUniform[src]

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

Returns the mean of the discrete uniform distribution

Formula

This example is not tested
(min + max) / 2

impl Variance<f64> for DiscreteUniform[src]

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

Returns the variance of the discrete uniform distribution

Formula

This example is not tested
((max - min + 1)^2 - 1) / 12

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

Returns the standard deviation of the discrete uniform distribution

Formula

This example is not tested
sqrt(((max - min + 1)^2 - 1) / 12)

impl Entropy<f64> for DiscreteUniform[src]

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

Returns the entropy of the discrete uniform distribution

Formula

This example is not tested
ln(max - min + 1)

impl Skewness<f64> for DiscreteUniform[src]

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

Returns the skewness of the discrete uniform distribution

Formula

This example is not tested
0

impl Median<f64> for DiscreteUniform[src]

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

Returns the median of the discrete uniform distribution

Formula

This example is not tested
(max + min) / 2

impl Mode<i64> for DiscreteUniform[src]

fn mode(&self) -> i64[src]

Returns the mode for the discrete uniform distribution

Remarks

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

Formula

This example is not tested
N/A // (max + min) / 2 for the middle element

impl Copy for DiscreteUniform[src]

impl Clone for DiscreteUniform[src]

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

Performs copy-assignment from source. Read more

impl PartialEq<DiscreteUniform> for DiscreteUniform[src]

impl Debug for DiscreteUniform[src]

impl IndependentSample<f64> for DiscreteUniform[src]

fn ind_sample<R: Rng>(&self, r: &mut R) -> f64[src]

Generate a random independent sample from a discrete uniform distribution using r as the source of randomness. Refer here for implementation details

impl Sample<f64> for DiscreteUniform[src]

fn sample<R: Rng>(&mut self, r: &mut R) -> f64[src]

Generate a random sample from a discrete uniform distribution using r as the source of randomness. Refer here for implementation details

Auto Trait Implementations

impl Send for DiscreteUniform

impl Unpin for DiscreteUniform

impl Sync for DiscreteUniform

impl UnwindSafe for DiscreteUniform

impl RefUnwindSafe for DiscreteUniform

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

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

impl<T> From<T> for T[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<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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