Compare commits

..

No commits in common. "b50f40fe8af49397c68367814228cef5f4b46516" and "455452d64bba74ecaa9e54ee8890b82abe6fd8cb" have entirely different histories.

2 changed files with 4 additions and 38 deletions

View File

@ -1,7 +1,6 @@
use crate::{BridgeInfo, BridgeInfoType};
use lox_library::proto::trust_promotion::UNTRUSTED_INTERVAL;
use nalgebra::{Cholesky, DMatrix, DVector};
use rand::Rng;
use nalgebra::DVector;
use statrs::distribution::{Continuous, MultivariateNormal, Normal};
use std::{
cmp::min,
@ -213,9 +212,7 @@ impl NormalAnalyzer {
}
// Returns the mean vector, vector of individual standard deviations, and
// covariance matrix. If the standard deviation for a variable is 0 and/or
// the covariance matrix is not positive definite, add some noise to the
// data and recompute.
// covariance matrix
fn stats(data: &[&[u32]]) -> (Vec<f64>, Vec<f64>, Vec<f64>) {
let n = data.len();
@ -270,33 +267,7 @@ impl NormalAnalyzer {
cov_mat
};
// If any standard deviation is 0 or the covariance matrix is not
// positive definite, add some noise and recompute.
let mut recompute = false;
for sd in &sd_vec {
if *sd <= 0.0 {
recompute = true;
}
}
if Cholesky::new(DMatrix::from_vec(n, n, cov_mat.clone())).is_none() {
recompute = true;
}
if !recompute {
(mean_vec, sd_vec, cov_mat)
} else {
// Add random noise and recompute
let mut new_data = vec![vec![0; data[0].len()]; n];
let mut rng = rand::thread_rng();
for i in 0..n {
for j in 0..data[i].len() {
// Add 1 to some randomly selected values
new_data[i][j] = data[i][j] + rng.gen_range(0..=1);
}
}
// Compute stats on modified data
Self::stats(&new_data.iter().map(Vec::as_slice).collect::<Vec<&[u32]>>())
}
}
}

View File

@ -20,18 +20,13 @@ pub mod negative_report;
pub mod positive_report;
pub mod request_handler;
#[cfg(feature = "simulation")]
#[cfg(any(test, feature = "simulation"))]
pub mod simulation {
pub mod extra_infos_server;
pub mod state;
pub mod user;
}
#[cfg(test)]
pub mod simulation {
pub mod extra_infos_server;
}
use analysis::Analyzer;
use extra_info::*;
use negative_report::*;