probability_rs/dist/
mod.rs1use crate::rng;
4
5pub mod bernoulli;
6pub mod beta;
7pub mod binomial;
8pub mod chisquared;
9pub mod exponential;
10pub mod gamma;
11pub mod geometric;
12pub mod lognormal;
13pub mod normal;
14pub mod poisson;
15pub mod uniform;
16pub trait Moments {
18 fn mean(&self) -> f64;
19 fn variance(&self) -> f64;
20 fn std_dev(&self) -> f64 {
21 self.variance().sqrt()
22 }
23 fn skewness(&self) -> f64;
25 fn kurtosis(&self) -> f64;
27 fn kurtosis_full(&self) -> f64 { self.kurtosis() + 3.0 }
29 fn entropy(&self) -> f64;
31
32}
33
34pub trait Distribution {
36 type Value;
37 fn cdf(&self, x: Self::Value) -> f64;
38 fn sample<R: rng::RngCore>(&self, rng: &mut R) -> Self::Value;
39 fn in_support(&self, x: Self::Value) -> bool;
40}
41
42pub trait Continuous: Distribution<Value = f64> {
44 fn pdf(&self, x: f64) -> f64;
46 fn inv_cdf(&self, p: f64) -> f64;
48}
49
50pub trait Discrete: Distribution<Value = i64> {
52 fn pmf(&self, x: Self::Value) -> f64;
54 fn inv_cdf(&self, p: f64) -> Self::Value;
55}
56
57#[derive(Debug, Clone, Copy, PartialEq, Eq)]
59pub enum DistError {
60 InvalidParameter,
61}