Skip to main content

modularity

Function modularity 

Source
pub fn modularity(
    graph: &Graph,
    membership: &[u32],
    resolution: f64,
) -> IgraphResult<Option<f64>>
Expand description

Modularity of graph with respect to community assignment membership.

membership[v] is the integer community label of vertex v; labels need not be consecutive (we reindex internally). Returns None for ecount == 0 (modularity is undefined — matches upstream’s NaN).

§Errors

§Examples

use rust_igraph::{Graph, modularity};

// Two K3 triangles plus a single bridge edge: communities [0,0,0,1,1,1]
// give a high (positive) modularity.
let mut g = Graph::with_vertices(6);
for &(u, v) in &[(0, 1), (0, 2), (1, 2), (3, 4), (3, 5), (4, 5), (2, 3)] {
    g.add_edge(u, v).unwrap();
}
let q = modularity(&g, &[0, 0, 0, 1, 1, 1], 1.0).unwrap();
assert!(q.is_some());
assert!(q.unwrap() > 0.3);