Skip to content
Graph Intelligence Hub
Menu

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

TimeRoughly O(E log V) in practice
SpaceO(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 DESC

Procedure 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 complexityRoughly O(E log V) in practice
Space complexityO(V + E)

Relationships

Succeeded by
Implemented by
Related