[][src]Struct statrs::distribution::Geometric

pub struct Geometric { /* fields omitted */ }

Implements the Geometric distribution

Examples

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

let n = Geometric::new(0.3).unwrap();
assert_eq!(n.mean(), 1.0 / 0.3);
assert_eq!(n.pmf(1), 0.3);
assert_eq!(n.pmf(2), 0.21);

Methods

impl Geometric[src]

pub fn new(p: f64) -> Result<Geometric>[src]

Constructs a new shifted geometric distribution with a probability of p

Errors

Returns an error if p is not in (0, 1]

Examples

use statrs::distribution::Geometric;

let mut result = Geometric::new(0.5);
assert!(result.is_ok());

result = Geometric::new(0.0);
assert!(result.is_err());

pub fn p(&self) -> f64[src]

Returns the probability p of the geometric distribution

Examples

use statrs::distribution::Geometric;

let n = Geometric::new(0.5).unwrap();
assert_eq!(n.p(), 0.5);

Trait Implementations

impl Distribution<f64> for Geometric[src]

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

Generates a random sample from the geometric distribution using r as the source of randomness

Examples

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

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

impl Univariate<u64, f64> for Geometric[src]

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

Calculates the cumulative distribution function for the geometric distribution at x

Formula

This example is not tested
1 - (1 - p) ^ (x + 1)

impl Discrete<u64, f64> for Geometric[src]

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

Calculates the probability mass function for the geometric distribution at x

Formula

This example is not tested
(1 - p)^(x - 1) * p

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

Calculates the log probability mass function for the geometric distribution at x

Formula

This example is not tested
ln((1 - p)^(x - 1) * p)

impl Min<u64> for Geometric[src]

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

Returns the minimum value in the domain of the geometric distribution representable by a 64-bit integer

Formula

This example is not tested
1

impl Max<u64> for Geometric[src]

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

Returns the maximum value in the domain of the geometric distribution representable by a 64-bit integer

Formula

This example is not tested
2^63 - 1

impl Mean<f64> for Geometric[src]

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

Returns the mean of the geometric distribution

Formula

This example is not tested
1 / p

impl Variance<f64> for Geometric[src]

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

Returns the standard deviation of the geometric distribution

Formula

This example is not tested
(1 - p) / p^2

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

Returns the standard deviation of the geometric distribution

Remarks

Returns NAN if p is 1

Formula

This example is not tested
sqrt(1 - p) / p

impl Entropy<f64> for Geometric[src]

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

Returns the entropy of the geometric distribution

Formula

This example is not tested
(-(1 - p) * log_2(1 - p) - p * log_2(p)) / p

impl Skewness<f64> for Geometric[src]

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

Returns the skewness of the geometric distribution

Formula

This example is not tested
(2 - p) / sqrt(1 - p)

impl Median<f64> for Geometric[src]

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

Returns the median of the geometric distribution

Remarks

Returns 1 if p is 1

Formula

This example is not tested
ceil(-1 / log_2(1 - p))

impl Mode<u64> for Geometric[src]

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

Returns the mode of the geometric distribution

Formula

This example is not tested
1

impl Copy for Geometric[src]

impl Clone for Geometric[src]

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

Performs copy-assignment from source. Read more

impl PartialEq<Geometric> for Geometric[src]

impl Debug for Geometric[src]

impl IndependentSample<f64> for Geometric[src]

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

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

impl Sample<f64> for Geometric[src]

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

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

Auto Trait Implementations

impl Send for Geometric

impl Unpin for Geometric

impl Sync for Geometric

impl UnwindSafe for Geometric

impl RefUnwindSafe for Geometric

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]