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
extern crate float_cmp;
use self::float_cmp::approx_eq;
pub fn print_all_measures(bayes_risk_estimate: f64, random_guessing: f64) {
println!("Multiplicative Leakage: {}",
multiplicative_leakage(bayes_risk_estimate, random_guessing));
println!("Additive Leakage: {}",
additive_leakage(bayes_risk_estimate, random_guessing));
println!("Bayes security measure: {}",
bayes_security_measure(bayes_risk_estimate, random_guessing));
println!("Min-entropy Leakage: {}",
min_entropy_leakage(bayes_risk_estimate, random_guessing));
}
pub fn multiplicative_leakage(bayes_risk: f64, random_guessing: f64) -> f64 {
assert!(!approx_eq!(f64, random_guessing, 0.),
"Random guessing error cannot be 0");
(1.-bayes_risk) / (1.-random_guessing)
}
pub fn additive_leakage(bayes_risk: f64, random_guessing: f64) -> f64 {
assert!(!approx_eq!(f64, random_guessing, 0.),
"Random guessing error cannot be 0");
random_guessing - bayes_risk
}
pub fn bayes_security_measure(bayes_risk: f64, random_guessing: f64) -> f64 {
assert!(!approx_eq!(f64, random_guessing, 0.),
"Random guessing error cannot be 0");
bayes_risk / random_guessing
}
pub fn min_entropy_leakage(bayes_risk: f64, random_guessing: f64) -> f64 {
assert!(!approx_eq!(f64, random_guessing, 0.),
"Random guessing error cannot be 0");
- (1.-random_guessing).log(2.) + (1.-bayes_risk).log(2.)
}