Modularity Lab
What is Modularity?
Modularity measures how good a community partition is. It compares the actual number of edges within communities to the expected number if edges were placed randomly (keeping the same node degrees). A high modularity means the community structure is stronger than random.
The Formula
Symbol Definitions
| Symbol | Meaning |
|---|---|
| Aij | 1 if nodes i and j are connected, 0 otherwise |
| ki | degree of node i |
| kj | degree of node j |
| m | total number of edges |
| ci | community assignment of node i |
| δ(ci, cj) | 1 if ci = cj (same community), 0 otherwise |
| kikj / 2m | expected number of edges between i and j in a random graph with the same degree distribution |
| Q | modularity score — positive means stronger-than-random community structure |
Interpretation
- Q ≈ 0: no better than random
- Q > 0.3: moderate community structure
- Q > 0.7: strong community structure
- Q can be negative if the partition is worse than random
Interactive Modularity Lab
Network Graph
Modularity Score
Community Membership
Modularity Contribution Table
Each pair of nodes contributes to the total modularity. Positive contributions (green) come from connected nodes in the same community. Negative contributions (red) come from unconnected nodes in the same community.
| Node i | Node j | Aij | ki | kj | Expected | Same Community? | Contribution |
|---|
Move One Node Experiment
Explore how moving a single node affects modularity. Select a node and see the impact of moving it to different communities.
How Louvain Algorithm Maximises Modularity
The Louvain algorithm starts with each node in its own community, then greedily moves nodes to neighbouring communities to maximise Q. This is a simplified teaching version showing the first phase only.
Louvain Animation
Step Details
Click "Run Louvain" to start the algorithm.