Trait statrs::distribution::Discrete
source · pub trait Discrete<K, T> {
// Required methods
fn pmf(&self, x: K) -> T;
fn ln_pmf(&self, x: K) -> T;
}
Expand description
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§
sourcefn pmf(&self, x: K) -> T
fn pmf(&self, x: K) -> T
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));
sourcefn ln_pmf(&self, x: K) -> T
fn ln_pmf(&self, x: K) -> T
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));