pub fn modularity_weighted(
graph: &Graph,
membership: &[u32],
resolution: f64,
weights: &[f64],
) -> IgraphResult<Option<f64>>Expand description
Weighted modularity (ALGO-CO-001c).
Counterpart of igraph_modularity(_, _, &weights, resolution, /*directed=*/false, _). Same Newman-Girvan formula as
modularity but with edge weights replacing the unit
adjacency: s_v = Σ w_e over incident edges (self-loops
contribute 2w per upstream IGRAPH_LOOPS), W = Σ w_e, and
Q_w = (1 / 2W) Σ_{ij} (w_ij − γ s_i s_j / 2W) δ(c_i, c_j)weights.len() must equal graph.ecount(). Returns None for
graphs with ecount == 0 or W == 0 (both modularity-undefined,
matches upstream NaN). Weights must be non-negative and finite —
igraph rejects negatives outright because the bound Q ∈ [-1, 1]
stops holding.
§Examples
use rust_igraph::{Graph, modularity_weighted};
// Unit weights collapse to unweighted modularity (CO-001).
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 weights = vec![1.0_f64; 7];
let q = modularity_weighted(&g, &[0, 0, 0, 1, 1, 1], 1.0, &weights).unwrap();
assert!(q.is_some());
assert!(q.unwrap() > 0.3);