Skip to main content

le_community_to_membership

Function le_community_to_membership 

Source
pub fn le_community_to_membership(
    merges: &[[u32; 2]],
    steps: u32,
    membership: &[u32],
) -> IgraphResult<CommunityToMembershipResult>
Expand description

Cut an incomplete dendrogram after steps merges, starting from an initial (non-singleton) cluster assignment.

This is the more general form of community_to_membership: instead of assuming each dendrogram leaf is a single vertex, the leaves are the m contiguous clusters described by membership (so membership[v] ∈ [0, m)). The merges matrix then merges those clusters, and steps of those merges are applied. The output membership reassigns every vertex to its surviving cluster, and csize gives the vertex count of each.

This dendrogram shape is produced by divisive detectors that stop before splitting the graph down to individual vertices, such as igraph’s leading-eigenvector method.

Mirrors igraph_le_community_to_membership from references/igraph/src/community/leading_eigenvector.c.

§Errors

  • InvalidArgument if membership is empty, or steps >= m where m is the number of initial clusters.
  • InvalidArgument if membership is not a contiguous 0..m labelling (some cluster index in that range is unused).
  • Any error propagated from community_to_membership when applying the merges to the m initial clusters.

§Examples

use rust_igraph::le_community_to_membership;

// Six vertices in three initial clusters: {0,1}=0, {2,3}=1, {4,5}=2.
// One merge combines clusters 0 and 1.
let membership = [0, 0, 1, 1, 2, 2];
let r = le_community_to_membership(&[[0, 1]], 1, &membership).unwrap();
// Clusters 0 and 1 fuse; cluster 2 stays separate.
assert_eq!(r.membership, vec![0, 0, 0, 0, 1, 1]);
assert_eq!(r.csize, vec![4, 2]);