% Newman-Girvan community finding algorithm % Source: Newman, Girvan, "Finding and evaluating % community structure in networks" % Algorithm idea: % 1. Calculate betweenness scores for all edges in the network. % 2. Find the edge with the highest score and remove it from the network. % 3. Recalculate betweenness for all remaining edges. % 4. Repeat from step 2. % % INPUTs: adjacency matrix (nxn), number of modules (k) % OUTPUTs: modules (components) and modules history - % each "current" module, Q - modularity metric % % Other routines used: edgeBetweenness.m, isConnected.m, % findConnComp.m, subgraph.m, numEdges.m % GB: last updated, Oct 11 2012 function [modules,module_hist,Q] = newmanGirvan(adj,k) n=size(adj,1); module_hist{1} = [1:n]; % current component modules{1}=[1:n]; curr_mod=1; adj_temp=adj; while length(modules)