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

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]

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 Debug for Uniform
[src]

Formats the value using the given formatter.

impl Copy for Uniform
[src]

impl Clone for Uniform
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for Uniform
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Sample<f64> for Uniform
[src]

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

impl IndependentSample<f64> for Uniform
[src]

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

impl Distribution<f64> for Uniform
[src]

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

Examples

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

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

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

Calculates the cumulative distribution function for the uniform distribution at x

Remarks

Returns 0.0 if x < min and 1.0 if x >= max

Formula

(x - min) / (max - min)

impl Min<f64> for Uniform
[src]

Returns the minimum value in the domain of a given distribution representable by a double-precision float. May panic depending on the implementor. Read more

impl Max<f64> for Uniform
[src]

Returns the maximum value in the domain of a given distribution representable by a double-precision float. May panic depending on the implementor. Read more

impl Mean<f64> for Uniform
[src]

Returns the mean for the continuous uniform distribution

Formula

(min + max) / 2

impl Variance<f64> for Uniform
[src]

Returns the variance for the continuous uniform distribution

Formula

(max - min)^2 / 12

Returns the standard deviation for the continuous uniform distribution

Formula

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

impl Entropy<f64> for Uniform
[src]

Returns the entropy for the continuous uniform distribution

Formula

ln(max - min)

impl Skewness<f64> for Uniform
[src]

Returns the skewness for the continuous uniform distribution

Formula

0

impl Median<f64> for Uniform
[src]

Returns the median for the continuous uniform distribution

Formula

(min + max) / 2

impl Mode<f64> for Uniform
[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 Continuous<f64, f64> for Uniform
[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)

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