Real networks of collaborators are not colored by hand — communities are discovered from the graph's structure alone using modularity optimization (Newman & Girvan, 2004; the greedy variant here follows Clauset–Newman–Moore, 2004). The network below is a synthetic collaboration graph of quantum-tech researchers generated as a stochastic block model: nodes are wired into a handful of hidden "labs," with a high probability of an edge between two researchers in the same lab and a low probability across labs — exactly the kind of latent community structure real co-authorship and collaboration networks show.
Modularity Q measures how much more densely connected the current partition is, compared to a random graph with the same degree sequence:
Q = (1/2m) · Σ_ij [ A_ij − k_i·k_j / (2m) ] · δ(c_i, c_j)
equivalently, summed per community c:
Q = Σ_c [ L_c/m − (K_c / 2m)² ]
A_ij = adjacency matrix, k_i = degree of node i, m = total edges,
L_c = edges inside community c, K_c = sum of degrees in c,
δ(c_i,c_j) = 1 iff nodes i,j are in the same community
Detection starts with every node in its own singleton community (Q is very negative). At every step the algorithm computes, for every pair of communities that share at least one edge, the exact modularity gain from merging them:
ΔQ(c1,c2) = 2 · [ e(c1,c2)/m − (K_c1/2m)·(K_c2/2m) ]
It merges whichever pair gives the largest ΔQ, updates L_c, K_c and the inter-community edge counts exactly (no re-scan of the raw graph is needed), and repeats. This is a real greedy hill-climb on Q, not a scripted animation — merges stop the moment no remaining pair would increase Q, which is the algorithm's genuine local-maximum stopping condition. Watch the Q readout and the chart climb step by step as loosely-connected singleton nodes fuse into the labs the block model actually planted.