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.)
}