A Bit of History
In 2019, V.A. Traag, L. Waltman, and N.J. van Eck from Leiden University published "From Louvain to Leiden: guaranteeing well-connected communities" in Scientific Reports. For over a decade, the Louvain Method (2008) was the gold standard for large-scale community detection. However, Traag et al. discovered that Louvain's greedy node movement could split a community into disconnected components, leaving up to 25% of communities internally disconnected in real-world networks! The Leiden Algorithm solved this by adding an explicit refinement phase and fast queue-based node tracking.
The Flaw in Louvain
Why did Louvain produce disconnected communities?
- In Louvain, when a bridge node leaves a community, two distant sub-clusters in that community become topologically disconnected.
- However, if the modularity formula still finds that keeping them in the same community label yields a higher overall score than creating new individual communities, Louvain keeps them assigned to the same community ID!
- When Louvain aggregates these nodes in Phase 2, it contracts a disconnected "community" into a single super-node, permanently hiding the topological disconnect.
Working Principle: Three Phases
Leiden addresses Louvain's weakness by splitting the process into three distinct phases:
- Phase 1: Local Moving of Nodes: Nodes are moved between communities to optimize modularity or Constant Potts Model (CPM). Unlike Louvain, Leiden uses a fast queue of affected nodes so only nodes whose neighborhood changed are re-evaluated.
- Phase 2: Refinement of Communities (The Core Innovation): Communities found in Phase 1 are refined into well-connected sub-communities. Nodes are moved randomly into sub-communities within their main community, guaranteed not to disconnect them.
- Phase 3: Aggregation Based on Refined Partition: Instead of aggregating based on the raw Phase 1 partition (which might be weakly connected), Leiden aggregates based on the refined sub-community partition.
Key Insight
By aggregating the graph based on the refined sub-communities rather than the primary communities, Leiden guarantees that every super-node in the aggregated graph represents a strictly connected component of the original graph!
Sub-community Refinement
In the refinement phase, a node $u$ inside community $\mathcal{C}$ can merge into a sub-community $\mathcal{S} \subset \mathcal{C}$ probabilistically based on the modularity delta \(\Delta Q\):
$$\Pr(u \to \mathcal{S}) \propto \exp\left( \frac{\Delta Q}{\gamma} \right)$$
where $\gamma$ is a tuning parameter. This randomized, constrained movement splits poorly-connected regions before the graph is aggregated, preventing disconnected sub-graphs from merging.
Worked Example
Consider two dense cliques $A$ and $B$ connected by a single bottleneck path $x \to y \to z$:
- In Louvain, $y$ might move to clique $A$, and $z$ might move to clique $B$. If $x$ later leaves, $A$ and $B$ might remain labeled as one community even if no path connects them!
- In Leiden, after Phase 1 identifies the candidate community $\{A, x, y, z, B\}$, Phase 2's refinement discovers that $A$ and $B$ have no direct edges. It refines the group into two sub-communities $\{A, x, y\}$ and $\{z, B\}$.
- In Phase 3, Leiden creates two separate super-nodes for $\{A, x, y\}$ and $\{z, B\}$, preserving proper topological connectivity.
Complexity & Benchmarks
Leiden is both higher quality and faster than Louvain because of its queue-based update mechanism:
| Metric | Louvain Method | Leiden Algorithm |
|---|---|---|
| Guaranteed Connected Communities? | No (up to 25% disconnected) | Yes (100% connected) |
| Node Re-evaluation Strategy | Full pass over all $V$ nodes | Fast Queue of changed node neighborhoods |
| Empirical Speed | Fast ($O(E)$ per level) | 2x - 5x Faster than Louvain |
Implementation
Real-World Applications
Single-Cell RNA Sequencing (scRNA-seq) Cell Clustering
In computational biology, single-cell analysis tools (such as Seurat and Scanpy) represent cell similarity graphs with millions of single cells. The Leiden algorithm is the universal standard for clustering single cells into cell types because internally disconnected clusters would misclassify cell lineages!
Exercises
- Construct a 7-node graph where the Louvain method creates a disconnected community, and show how Leiden's refinement phase fixes it.
- Explain how queue-based node selection in Phase 1 speeds up Leiden compared to Louvain's full scans.
- Compare the Constant Potts Model (CPM) quality function with standard Modularity $Q$ in Leiden.
- Challenge: Implement Phase 2 (Sub-community refinement) with probabilistic node assignment.
Limitations
Randomization & Resolution Limit
While Leiden guarantees 100% connected communities, its sub-community refinement phase is non-deterministic (randomized). Additionally, if configured to optimize standard modularity $Q$, it still inherits modularity's resolution limit (failing to find tiny communities in massive graphs), which is why CPM (Constant Potts Model) is often preferred for multi-scale analysis.