Normalized cut asks for a partition whose clusters are weakly connected to each other relative to their size. W is a symmetric non-negative (N, N) affinity matrix with zero diagonal and positive degrees ; and .
ncut_value(W, labels): Shi and Malik's normalized cut over the clusters defined by labels (this is the book's definition without its leading , the normalisation under which the random-walk interpretation holds exactly).
escape_probabilities(W, in_S): for the random walk started from its stationary distribution , return (p_out, p_in) , where is the probability that one step goes to given that it starts in . in_S is a boolean mask.
shi_malik_bipartition(W): solve the generalised eigenproblem , , through the symmetric matrix (map its eigenvector back by ), take the eigenvector of the second-smallest eigenvalue and flip its sign so that its entry of largest absolute value is positive. Then search the splitting point: for every distinct value of except the largest (in increasing order), let and compute the normalized cut of ; keep the with the smallest value (first on ties). Return (labels, ncut, u) where labels[i] is 0 for the side containing node 0 and 1 for the other.