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
extern crate special;
use self::special::{Error, Gamma};
use std::f64::consts::PI;
pub fn gaussian(x: f64, mu: f64, sigma: f64) -> f64 {
1f64 / ((2f64 * PI).sqrt() * sigma) * (-0.5 * ((x - mu) / sigma).powi(2)).exp()
}
pub fn gamma(x: f64) -> f64 {
x.gamma()
}
pub fn digamma(x: f64) -> f64 {
x.digamma()
}
pub fn erf(x: f64) -> f64 {
x.error()
}
pub fn erfc(x: f64) -> f64 {
x.compl_error()
}
pub fn erf_inv(x: f64) -> f64 {
x.inv_error()
}
pub fn beta(a: f64, b: f64) -> f64 {
gamma(a) * gamma(b) / gamma(a + b)
}