function K = modker(A) % Given an (undirected) adjacency matrix A, % modker(A) constructs its corresponding % Modularity Kernel matrix d = sum(A); n = length(d); m = sum(d)/2; % the number of edges P = (d'*d)./(2*m); % P(i,j) = d(i)*d(j)/(2*m); M = A-P; [MV,MD] = eig(full(M)); [Md,idx] = sort(diag(MD)); MV = MV(:,idx); MX = MV(:,Md>0) * sparse(diag(sqrt(Md(Md>0)))); K = MX*MX'; end