Expand description
Leiden community detection — find densely-connected clusters in weighted graphs.
The Leiden algorithm (Traag, Waltman & van Eck, 2019) partitions the nodes of a weighted undirected graph into communities that maximise the modularity objective:
Q = (1/2m) × Σ_{ij} [A_ij − γ × k_i × k_j / (2m)] × δ(c_i, c_j)where m is the total edge weight, k_i the weighted degree of node i, γ the
resolution parameter, and δ the Kronecker delta. Leiden improves on Louvain by
adding a refinement phase that prevents poorly-connected communities from merging.
§Features
- Weighted undirected graphs (parallel edges are summed)
- Configurable resolution parameter
γfor community granularity - Deterministic via
random_seed - Pure Rust, no unsafe, no external library dependencies
§Quick Start
use rune_leiden::Leiden;
// Two triangles connected by a single bridge edge
let edges = vec![
(0, 1, 1.0), (1, 2, 1.0), (0, 2, 1.0),
(3, 4, 1.0), (4, 5, 1.0), (3, 5, 1.0),
(2, 3, 0.01),
];
let result = Leiden::new().fit(6, &edges);
assert_eq!(result.n_communities, 2);
assert!(result.modularity >= 0.0);§CLI
rune-leiden edges.txt
rune-leiden edges.txt --resolution 0.5 --seed 123
cat edges.txt | rune-leiden -Structs§
- Community
Result - Result of a completed Leiden community-detection run.
- Leiden
- Builder for configuring and running the Leiden community-detection algorithm.