pub fn modularity_directed(
graph: &Graph,
membership: &[u32],
resolution: f64,
) -> IgraphResult<Option<f64>>Expand description
Directed modularity (Leicht-Newman, ALGO-CO-001b).
Counterpart of igraph_modularity(_, _, NULL_weights, resolution, /*directed=*/true, _). The directed analogue of modularity:
Q = (1 / m) Σ_{ij} (A_ij − γ k_out_i * k_in_j / m) δ(c_i, c_j)where m = ecount, k_out_i = out_degree(i), k_in_j = in_degree(j),
and A_ij is the directed adjacency matrix (each directed edge
contributes 1 to one entry, not symmetric). Reference: Leicht &
Newman (2008).
Undirected graphs route to modularity with the same membership
and resolution (matches python-igraph’s “ignored on undirected”
semantics).
§Examples
use rust_igraph::{Graph, modularity_directed};
// Two directed triangles connected by a single bridge:
// 0→1→2→0, 3→4→5→3, plus 2→3.
// Partition {0,1,2} vs {3,4,5} gives a positive Q (hand-checked
// value: 18/49 ≈ 0.367).
let mut g = Graph::new(6, true).unwrap();
for &(u, v) in &[(0u32, 1), (1, 2), (2, 0), (3, 4), (4, 5), (5, 3), (2, 3)] {
g.add_edge(u, v).unwrap();
}
let q = modularity_directed(&g, &[0, 0, 0, 1, 1, 1], 1.0).unwrap();
assert!(q.is_some());
assert!(q.unwrap() > 0.3);