Skip to main content

get_ind_matrix

Function get_ind_matrix 

Source
pub fn get_ind_matrix(
    label_endtime: &[(usize, usize)],
    bar_index: &[usize],
) -> Result<Vec<Vec<u8>>, InputError>
Expand description

Builds the indicator matrix of which labels span which bars (AFML Snippet 4.3).

label_endtime[i] = (start, end) is label i’s inclusive span in bar positions and bar_index lists the bars to report, in the order the rows should appear. Entry [r][i] is 1 when start <= bar_index[r] <= end and 0 otherwise, so the result has bar_index.len() rows and label_endtime.len() columns. A span reaching past the bars listed is truncated silently; bar_index does not have to be contiguous.

§Errors

InputError::OutOfRange if any label has start > end.

use openquant::sampling::get_ind_matrix;

let ind = get_ind_matrix(&[(0, 1), (1, 9)], &[0, 1, 2]).unwrap();
assert_eq!(ind, vec![vec![1, 0], vec![1, 1], vec![0, 1]]);
assert!(get_ind_matrix(&[(3, 2)], &[0, 1]).is_err());