pub fn compare_communities(
comm1: &[i64],
comm2: &[i64],
method: CommunityComparison,
) -> Result<f64>Expand description
Compares two partitions of the same set with the given measure.
CommunityComparison::Vi: variation of information (Meilă 2003),VI = H(C1) + H(C2) − 2 MI(C1, C2)in natural units; 0 iff equal.CommunityComparison::Nmi: normalized mutual information (Danon et al. 2005),2 MI / (H(C1) + H(C2))in(0, 1]; 1 iff equal.CommunityComparison::SplitJoin: split-join distance (van Dongen 2000), the sum of bothsplit_join_distances.CommunityComparison::Rand: Rand index (1971), fraction of vertex pairs on which the two partitions agree.CommunityComparison::AdjustedRand: Hubert–Arabie adjusted Rand index, corrected for chance (may be negative;NaNwhen undefined).
Community ids need not be contiguous. Time complexity: O(n log n).
Binds igraph_compare_communities.
§Errors
ErrorKind::InvalidValue if the lengths
differ, or for the Rand indices with fewer than two elements.
§Examples
use igraph::prelude::*;
use igraph::community::compare_communities;
let a = [2, 0, 2, 1, 1, 0, 2, 2, 1, 2];
let b = [1, 1, 2, 1, 1, 0, 2, 2, 0, 2];
let rand = compare_communities(&a, &b, CommunityComparison::Rand).unwrap();
assert!((rand - 0.711111).abs() < 1e-6);
// Relabeling does not matter:
let vi = compare_communities(&[0, 1], &[1, 0], CommunityComparison::Vi).unwrap();
assert_eq!(vi, 0.0);