Sequential bootstrap (indices of samples).
(
ind_mat: &[Vec<u8>],
sample_length: Option<usize>,
warmup_samples: Option<Vec<usize>>,
)
| 90 | |
| 91 | /// Sequential bootstrap (indices of samples). |
| 92 | pub fn seq_bootstrap( |
| 93 | ind_mat: &[Vec<u8>], |
| 94 | sample_length: Option<usize>, |
| 95 | warmup_samples: Option<Vec<usize>>, |
| 96 | ) -> Vec<usize> { |
| 97 | let n_labels = ind_mat.first().map(|r| r.len()).unwrap_or(0); |
| 98 | let target_len = sample_length.unwrap_or(n_labels); |
| 99 | let mut phi: Vec<usize> = Vec::new(); |
| 100 | let mut warm = warmup_samples.unwrap_or_default(); |
| 101 | let mut prev_conc = vec![0.0; ind_mat.len()]; |
| 102 | |
| 103 | while phi.len() < target_len { |
| 104 | let avg_unique = bootstrap_loop_run(ind_mat, &prev_conc); |
| 105 | let sum: f64 = avg_unique.iter().sum(); |
| 106 | let prob_iter = avg_unique.iter().map(|p| if sum > 0.0 { *p / sum } else { 1.0 }); |
| 107 | let dist = WeightedIndex::new(prob_iter).unwrap(); |
| 108 | let mut rng = thread_rng(); |
| 109 | let choice = warm.pop().unwrap_or_else(|| dist.sample(&mut rng)); |
| 110 | phi.push(choice); |
| 111 | for (i, row) in ind_mat.iter().enumerate() { |
| 112 | prev_conc[i] += row[choice] as f64; |
| 113 | } |
| 114 | } |
| 115 | phi |
| 116 | } |
| 117 | |
| 118 | /// Average uniqueness from triple barrier events (index + t1). |
| 119 | pub fn get_av_uniqueness_from_triple_barrier( |