fraug/transforms/
accuracy.rs

1use crate::Dataset;
2
3/// Computes maximum absolute difference between two Datasets and check if all differences are within a tolerance.
4pub fn compare_datasets_within_tolerance(
5    original: &Dataset,
6    reconstructed: &Dataset,
7    tolerance: f64,
8) -> (f64, bool) {
9    let mut max_diff = 0.0;
10    let mut all_within = true;
11
12    for (orig_sample, recon_sample) in original.features.iter().zip(&reconstructed.features) {
13        for (&orig, &recon) in orig_sample.iter().zip(recon_sample.iter()) {
14            let diff = (orig - recon).abs();
15            if diff > max_diff {
16                max_diff = diff;
17            }
18            if diff > tolerance {
19                all_within = false;
20            }
21        }
22    }
23
24    (max_diff, all_within)
25}