1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use rand::Rng;
/// Defines the Probability Distribution trait
pub trait ProbabilityDistribution {
/// Evaluates the Probability Density Function (PDF)
///
/// The probability density function `f(x)` is such that
/// (see Eq 9 on page 1033 of the Reference):
///
/// ```text
/// b
/// ⌠
/// P(a < X ≤ b) = │ f(v) dv = F(b) - F(a)
/// ⌡
/// a
///
/// with b > a
/// ```
///
/// where `X` is the continuous random variable, `P(a < X ≤ b)` is the probability that `X` is in the
/// semi-open interval `(a, b]`, and `F(x)` is the cumulative probability distribution (CDF).
///
/// Note that, for continuous random variables, the following probabilities are all the same
/// (page 1033 of the reference):
///
/// ```text
/// prob = P(a < X < b)
/// = P(a < X ≤ b)
/// = P(a ≤ X < b)
/// = P(a ≤ X ≤ b)
/// ```
///
/// # References
///
/// * Kreyszig, E (2011) Advanced engineering mathematics; in collaboration with Kreyszig H,
/// Edward JN 10th ed 2011, Hoboken, New Jersey, Wiley
fn pdf(&self, x: f64) -> f64;
/// Evaluates the Cumulative Distribution Function (CDF)
///
/// The cumulative distribution function (or simply *distribution*) `F(x)` is such that
/// (see Eq 1 on page 1029 of the Reference):
///
/// ```text
/// x
/// ⌠
/// P(X ≤ x) = │ f(v) dv = F(x)
/// ⌡
/// -∞
/// ```
///
/// where `X` is the continuous random variable, `P(X ≤ x)` is the probability that `X`
/// assumes values not exceeding `x`, and `f(x)` is the probability density function (PDF).
///
/// # References
///
/// * Kreyszig, E (2011) Advanced engineering mathematics; in collaboration with Kreyszig H,
/// Edward JN 10th ed 2011, Hoboken, New Jersey, Wiley
fn cdf(&self, x: f64) -> f64;
/// Returns the Mean
fn mean(&self) -> f64;
/// Returns the Variance
fn variance(&self) -> f64;
/// Generates a pseudo-random number belonging to this probability distribution
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> f64;
}