Average uniqueness of indicator matrix (single value).
(ind_mat: &[Vec<u8>])
| 20 | |
| 21 | /// Average uniqueness of indicator matrix (single value). |
| 22 | pub fn get_ind_mat_average_uniqueness(ind_mat: &[Vec<u8>]) -> f64 { |
| 23 | let cols = ind_mat.first().map(|r| r.len()).unwrap_or(0); |
| 24 | if cols == 0 { |
| 25 | return 0.0; |
| 26 | } |
| 27 | let mut uniq_sum = 0.0; |
| 28 | let mut count = 0; |
| 29 | for col in 0..cols { |
| 30 | let mut numer = 0.0; |
| 31 | let mut denom = 0.0; |
| 32 | for row in ind_mat { |
| 33 | if row[col] == 1 { |
| 34 | let conc = row.iter().map(|v| *v as f64).sum::<f64>(); |
| 35 | numer += 1.0 / conc; |
| 36 | denom += 1.0; |
| 37 | } |
| 38 | } |
| 39 | if denom > 0.0 { |
| 40 | uniq_sum += numer / denom; |
| 41 | count += 1; |
| 42 | } |
| 43 | } |
| 44 | if count > 0 { |
| 45 | uniq_sum / count as f64 |
| 46 | } else { |
| 47 | 0.0 |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /// Per-label uniqueness series. |
| 52 | pub fn get_ind_mat_label_uniqueness(ind_mat: &[Vec<u8>]) -> Vec<Vec<f64>> { |