[][src]Trait statrs::distribution::Discrete

pub trait Discrete<T, K> {
    fn pmf(&self, x: T) -> K;
fn ln_pmf(&self, x: T) -> K; }

The Discrete trait provides an interface for interacting with discrete statistical distributions

Remarks

All methods provided by the Discrete trait are unchecked, meaning they can panic if in an invalid state or encountering invalid input depending on the implementing distribution.

Required methods

fn pmf(&self, x: T) -> K

Returns the probability mass function calculated at x for a given distribution. May panic depending on the implementor.

Examples

use statrs::distribution::{Discrete, Binomial};
use statrs::prec;

let n = Binomial::new(0.5, 10).unwrap();
assert!(prec::almost_eq(n.pmf(5), 0.24609375, 1e-15));

fn ln_pmf(&self, x: T) -> K

Returns the log of the probability mass function calculated at x for a given distribution. May panic depending on the implementor.

Examples

use statrs::distribution::{Discrete, Binomial};
use statrs::prec;

let n = Binomial::new(0.5, 10).unwrap();
assert!(prec::almost_eq(n.ln_pmf(5), (0.24609375f64).ln(), 1e-15));
Loading content...

Implementors

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 Discrete<u64, f64> for Bernoulli[src]

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

Calculates the probability mass function for the bernoulli distribution at x.

Formula

This example is not tested
if x == 0 { 1 - p }
else { p }

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

Calculates the log probability mass function for the bernoulli distribution at x.

Formula

This example is not tested
else if x == 0 { ln(1 - p) }
else { ln(p) }

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

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

Calculates the probability mass function for the binomial distribution at x

Formula

This example is not tested
(n choose k) * p^k * (1 - p)^(n - k)

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

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

Formula

This example is not tested
ln((n choose k) * p^k * (1 - p)^(n - k))

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

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

Calculates the probability mass function for the categorical distribution at x

Formula

This example is not tested
p_x

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

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

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 Discrete<u64, f64> for Hypergeometric[src]

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

Calculates the probability mass function for the hypergeometric distribution at x

Formula

This example is not tested
(K choose x) * (N-K choose n-x) / (N choose n)

where N is population, K is successes, and n is draws

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

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

Formula

This example is not tested
ln((K choose x) * (N-K choose n-x) / (N choose n))

where N is population, K is successes, and n is draws

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

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

Calculates the probability mass function for the poisson distribution at x

Formula

This example is not tested
(λ^k * e^(-λ)) / x!

where λ is the rate

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

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

Formula

This example is not tested
ln((λ^k * e^(-λ)) / x!)

where λ is the rate

impl<'a> Discrete<&'a [u64], f64> for Multinomial[src]

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

Calculates the probability mass function for the multinomial distribution with the given x's corresponding to the probabilities for this distribution

Panics

If the elements in x do not sum to n or if the length of x is not equivalent to the length of p

Formula

This example is not tested
(n! / x_1!...x_k!) * p_i^x_i for i in 1...k

where n is the number of trials, p_i is the ith probability, x_i is the ith x value, and k is the total number of probabilities

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

Calculates the log probability mass function for the multinomial distribution with the given x's corresponding to the probabilities for this distribution

Panics

If the elements in x do not sum to n or if the length of x is not equivalent to the length of p

Formula

This example is not tested
ln((n! / x_1!...x_k!) * p_i^x_i) for i in 1...k

where n is the number of trials, p_i is the ith probability, x_i is the ith x value, and k is the total number of probabilities

Loading content...