fn init_windows(
len_vec: usize,
min_win_size: usize,
max_win_size: usize,
step_win_size: usize,
step_slide: usize,
) -> Vec<Vec<usize>> {
assert!(
min_win_size >= 2,
"Minimum window size must be greater than or equal to 2."
);
assert!(!(max_win_size < min_win_size || max_win_size > len_vec), "Maximum window size must be greater than or equal to the minimum window size and less than or equal to the length of the vector.");
assert!(
!(step_win_size < 1 || step_slide < 1),
"Step widths of window size and slide must be greater than or equal to 1."
);
let mut windows: Vec<Vec<usize>> = Vec::new();
let win_sizes = (min_win_size..=max_win_size).step_by(step_win_size);
for win_size in win_sizes {
let n_windows = (len_vec - win_size).div_ceil(step_slide);
for _w in 0..n_windows {
let start = _w * step_slide;
let end = start + win_size;
if end > (len_vec - 1) {
break;
}
assert!(
start < end,
"Window size is larger than the length of the vector."
);
windows.push(vec![start, end]);
}
}
windows
}
pub fn init_windows_from_ratio(
len_vec: usize,
ratio_min_window: f64,
ratio_max_window: f64,
ratio_step_window: f64,
ratio_step_sliding: f64,
) -> Vec<Vec<usize>> {
assert!(ratio_min_window > 0.0);
assert!(ratio_max_window < 1.0);
assert!(ratio_min_window < ratio_max_window);
assert!(ratio_step_window > 0.0);
assert!(ratio_step_sliding > 0.0);
assert!(len_vec > 10);
let min_win_size = (len_vec as f64 * ratio_min_window).round() as usize;
let max_win_size = (len_vec as f64 * ratio_max_window).round() as usize;
let step_win_size = (len_vec as f64 * ratio_step_window).round() as usize;
let step_slide = (len_vec as f64 * ratio_step_sliding).round() as usize;
init_windows(
len_vec,
min_win_size,
max_win_size,
step_win_size,
step_slide,
)
}