Skip to main content

community_to_membership

Function community_to_membership 

Source
pub fn community_to_membership(
    merges: &[(i64, i64)],
    nodes: usize,
    steps: usize,
) -> Result<(Vec<i64>, Vec<i64>)>
Expand description

Cuts a dendrogram after steps merges, returning the membership vector and the size of each community.

The dendrogram has nodes leaves (the vertices) and is given by its merges, in the format of Graph::community_fastgreedy, Graph::community_walktrap or Graph::community_edge_betweenness: the i-th pair joins two dendrogram nodes into node nodes + i. After steps merges, nodes - steps communities remain, numbered from zero. steps may not exceed the number of merges. Time complexity: O(|V|). Dendrogram::cut does the same given a number of communities.

Binds igraph_community_to_membership.

§Errors

ErrorKind::InvalidValue if steps is too large or the merges are malformed.

§Examples

use igraph::community::community_to_membership;
// 4 leaves: merge 0+1 into 4, 2+3 into 5, then 4+5 into 6.
let merges = [(0, 1), (2, 3), (4, 5)];
let (membership, sizes) = community_to_membership(&merges, 4, 2).unwrap();
assert_eq!(membership, vec![1, 1, 0, 0]);
assert_eq!(sizes, vec![2, 2]);