-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathdist.rs
66 lines (59 loc) · 2.16 KB
/
dist.rs
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
extern crate peroxide;
use peroxide::fuga::*;
const SAMPLE_SIZE: usize = 10000;
fn main() {
example();
println!("Hello, World!")
}
fn example() {
let mu: f64 = 0.1;
let b = Bernoulli(mu);
let b_sample = b.sample(SAMPLE_SIZE);
println!("Bernoulli at mu = {}", mu);
println!("Number of samples: {}", SAMPLE_SIZE);
println!("Theoretical mean: {}", b.mean());
println!("Sample mean: {}", b_sample.mean());
println!("Theoretical var: {}", b.var());
println!("Sample var: {}", b_sample.var());
println!("PDF at x = 1: {}", b.pdf(1));
println!("PDF at x = 0: {}", b.pdf(0));
println!("");
let m = 0;
let s = 1;
let norm = Normal(m, s);
let norm_sample = norm.sample(SAMPLE_SIZE);
println!("Normal at (a,b) = ({},{})", m, s);
println!("Number of samples: {}", SAMPLE_SIZE);
println!("Theoretical mean: {}", norm.mean());
println!("Sample mean: {}", norm_sample.mean());
println!("Theoretical var: {}", norm.var());
println!("Sample var: {}", norm_sample.var());
println!("PDF at x = mean: {}", norm.pdf(0f64));
println!("");
let alpha = 3;
let beta = 2;
let be = Beta(alpha, beta);
let be_sample = be.sample(SAMPLE_SIZE);
println!("Beta at (a,b) = ({},{})", alpha, beta);
println!("Number of samples: {}", SAMPLE_SIZE);
println!("Theoretical mean: {}", be.mean());
println!("Sample mean: {}", be_sample.mean());
println!("Theoretical var: {}", be.var());
println!("Sample var: {}", be_sample.var());
println!("PDF at x = mean: {}", be.pdf(0.6));
println!("PDF at x = mode: {}", be.pdf(2f64 / 3f64));
println!("");
let alpha2 = 4;
let beta2 = 6;
let g = Gamma(alpha2, beta2);
let g_sample = g.sample(SAMPLE_SIZE);
println!("Gamma at (a,b) = ({},{})", alpha2, beta2);
println!("Number of samples: {}", SAMPLE_SIZE);
println!("Theoretical mean: {}", g.mean());
println!("Sample mean: {}", g_sample.mean());
println!("Theoretical var: {}", g.var());
println!("Sample var: {}", g_sample.var());
println!("PDF at x = mean: {}", g.pdf(0.666666));
println!("PDF at x = mode: {}", g.pdf(0.5));
println!("");
}