1use crate::iter_maybe_parallel;
4use crate::matrix::FdMatrix;
5use crate::streaming_depth::{
6 FullReferenceState, SortedReferenceState, StreamingBd, StreamingDepth, StreamingMbd,
7};
8#[cfg(feature = "parallel")]
9use rayon::iter::ParallelIterator;
10
11#[must_use = "expensive computation whose result should not be discarded"]
30pub fn band_1d(data_obj: &FdMatrix, data_ori: &FdMatrix) -> Vec<f64> {
31 if data_obj.nrows() == 0 || data_ori.nrows() < 2 || data_obj.ncols() == 0 {
32 return Vec::new();
33 }
34 let state = FullReferenceState::from_reference(data_ori);
35 let streaming = StreamingBd::new(state);
36 streaming.depth_batch(data_obj)
37}
38
39#[must_use = "expensive computation whose result should not be discarded"]
43pub fn modified_band_1d(data_obj: &FdMatrix, data_ori: &FdMatrix) -> Vec<f64> {
44 if data_obj.nrows() == 0 || data_ori.nrows() < 2 || data_obj.ncols() == 0 {
45 return Vec::new();
46 }
47 let state = SortedReferenceState::from_reference(data_ori);
48 let streaming = StreamingMbd::new(state);
49 streaming.depth_batch(data_obj)
50}
51
52#[must_use = "expensive computation whose result should not be discarded"]
57pub fn modified_epigraph_index_1d(data_obj: &FdMatrix, data_ori: &FdMatrix) -> Vec<f64> {
58 let nobj = data_obj.nrows();
59 let nori = data_ori.nrows();
60 let n_points = data_obj.ncols();
61
62 if nobj == 0 || nori == 0 || n_points == 0 {
63 return Vec::new();
64 }
65
66 iter_maybe_parallel!(0..nobj)
67 .map(|i| {
68 let mut total = 0.0;
69
70 for j in 0..nori {
71 let mut count = 0.0;
72
73 for t in 0..n_points {
74 let xi = data_obj[(i, t)];
75 let xj = data_ori[(j, t)];
76
77 if xi <= xj {
79 count += 1.0;
80 }
81 }
82
83 total += count / n_points as f64;
84 }
85
86 total / nori as f64
87 })
88 .collect()
89}