Don't scale bridge IPs in analysis

This commit is contained in:
Vecna 2024-04-26 12:58:03 -04:00
parent e889cba878
commit 273aaab38d
1 changed files with 7 additions and 8 deletions

View File

@ -7,8 +7,6 @@ use std::{
collections::{BTreeMap, HashSet},
};
const SCALE_BRIDGE_IPS: u32 = 8;
/// Provides a function for predicting which countries block this bridge
pub trait Analyzer {
/// Evaluate open-entry bridge. Returns true if blocked, false otherwise.
@ -71,7 +69,7 @@ pub fn blocked_in(
None => &new_map_binding,
};
let bridge_ips_today = match today_info.get(&BridgeInfoType::BridgeIps) {
Some(&v) => v / SCALE_BRIDGE_IPS,
Some(&v) => v,
None => 0,
};
let negative_reports_today = match today_info.get(&BridgeInfoType::NegativeReports) {
@ -98,7 +96,7 @@ pub fn blocked_in(
None => &new_map_binding,
};
bridge_ips[i as usize] = match day_info.get(&BridgeInfoType::BridgeIps) {
Some(&v) => v / SCALE_BRIDGE_IPS,
Some(&v) => v,
None => 0,
};
negative_reports[i as usize] = match day_info.get(&BridgeInfoType::NegativeReports)
@ -264,7 +262,7 @@ impl NormalAnalyzer {
sum +=
(var1[index] as f64 - var1_mean) * (var2[index] as f64 - var2_mean);
}
sum / var1.len() as f64
sum / (var1.len() - 1) as f64
});
}
}
@ -287,7 +285,7 @@ impl Analyzer for NormalAnalyzer {
) -> bool {
negative_reports_today > self.max_threshold
|| f64::from(negative_reports_today)
> self.scaling_factor * f64::from(bridge_ips_today) * SCALE_BRIDGE_IPS as f64
> self.scaling_factor * f64::from(bridge_ips_today)
}
/// Evaluate invite-only bridge based on last 30 days
@ -311,10 +309,11 @@ impl Analyzer for NormalAnalyzer {
let negative_reports_sd = sd_vec[1];
let mvn = MultivariateNormal::new(mean_vec, cov_mat).unwrap();
if mvn.pdf(&DVector::from_vec(vec![
let pdf = mvn.pdf(&DVector::from_vec(vec![
bridge_ips_today as f64,
negative_reports_today as f64,
])) < alpha
]));
if pdf < alpha
{
(negative_reports_today as f64) > negative_reports_mean + negative_reports_sd
|| (bridge_ips_today as f64) < bridge_ips_mean - bridge_ips_sd