Algorithm
Louvain community detection
activeNeeds verification
Greedy, multi-level modularity optimisation that moves nodes between communities, then aggregates communities into super-nodes and repeats.
Definition
Intuition
Keep moving each node to the neighbouring community that most increases modularity; when nothing improves, collapse communities and do it again at a coarser level.
Complexity
| Time | Roughly O(E log V) in practice |
|---|---|
| Space | O(V + E) |
Python
import networkx as nx
comms = nx.community.louvain_communities(G, seed=42)Cypher (Neo4j GDS)
CALL gds.louvain.stream('myGraph')
YIELD nodeId, communityId RETURN communityId, count(*) AS size
ORDER BY size DESCProcedure names and options vary between GDS versions; check the GDS docs for your version.
An interactive step-by-step visualizer for this algorithm is planned for phase 3.
Profile
| Time complexity | Roughly O(E log V) in practice |
|---|---|
| Space complexity | O(V + E) |
Relationships
- Belongs to
- Introduced by
- Succeeded by
- Leiden community detection— Leiden fixes badly connected communities
- Prerequisite of
- Part of
- Prerequisites
- Community structure and modularity(Concept)
- Implemented by
- Graphology(Library / framework)
- igraph(Library / framework)
- Neo4j Graph Data Science(Library / framework)
- NetworkX(Library / framework)
- Related
- Louvain method(Timeline event)