pub fn class_homophily(graph: &Graph, labels: &[u32]) -> IgraphResult<f64>Expand description
Class-balanced homophily ratio (adjusted for class imbalance).
h_class = (1/C) Σ_k [ h_k - |C_k|/|V| ] / (1 - |C_k|/|V|)
where h_k is the proportion of edges from class-k vertices that
connect to other class-k vertices, and |C_k|/|V| is the class
proportion (baseline under random connectivity).
Range: approximately [-1, 1]. Values near 0 indicate behavior consistent with random label assignment. Negative values indicate heterophily beyond random expectation.
§Examples
use rust_igraph::{Graph, class_homophily};
// Complete bipartite K_{2,2} with labels [0,0,1,1]
// All edges cross classes → strong heterophily
let g = Graph::from_edges(&[(0,2),(0,3),(1,2),(1,3)], false, Some(4)).unwrap();
let h = class_homophily(&g, &[0, 0, 1, 1]).unwrap();
assert!(h < 0.0);