MCPcopy Create free account
hub / github.com/Open-Quant/openquant / get_ind_mat_average_uniqueness

Function get_ind_mat_average_uniqueness

crates/openquant/src/sampling.rs:22–49  ·  view source on GitHub ↗

Average uniqueness of indicator matrix (single value).

(ind_mat: &[Vec<u8>])

Source from the content-addressed store, hash-verified

20
21/// Average uniqueness of indicator matrix (single value).
22pub 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.
52pub fn get_ind_mat_label_uniqueness(ind_mat: &[Vec<u8>]) -> Vec<Vec<f64>> {

Calls 1

lenMethod · 0.80

Tested by 2