apaClustering.Spectral.kMeans(LaplacianMatrix, nEigenvectors, nStarts, DoNormalizeRows)
=apaClustering.Spectral.kMeans(LaplacianMatrix, nEigenvectors, nStarts, DoNormalizeRows)Result
k-means clustering on the spectral embedding of a Laplacian matrix with k = nEigenvectors + 1 clusters. Returns an n x 1 vector of cluster labels from 0 to k - 1.
Syntax
LaplacianMatrix: n x n Laplacian matrix: L (apaGraph.LaplacianMatrix), L_sym (apaGraph.LaplacianMatrix.Sym) or L_rw (apaGraph.LaplacianMatrix.RW)
nEigenvectors: number of eigenvectors s, excluding the trivial eigenvector of the smallest eigenvalue; integer between 1 and n - 2. Determines the number of clusters k = s + 1; for k clusters, set nEigenvectors to k - 1. With DoNormalizeRows = TRUE the embedding has s + 1 columns, since the trivial eigenvector is included.
nStarts: optional; number of k-means++ starts; the solution with the lowest within-cluster sum of squares is returned; default: 10
DoNormalizeRows: optional; TRUE to scale each row of the embedding to unit length, with the embedding then also including the trivial eigenvector (Ng–Jordan–Weiss); FALSE to use the eigenvectors as they are; default: FALSE
Remarks
The spectral embedding consists of the eigenvectors of the 2nd to (s + 1)-th smallest eigenvalues of LaplacianMatrix; the eigenvector of the smallest eigenvalue (constant for L and L_rw) carries no cluster information and is skipped.
Symmetric matrices (L, L_sym) are decomposed directly, by Householder tridiagonalization followed by the implicit QL algorithm. The random-walk Laplacian L_rw = D^-1 L is not symmetric; its eigenvectors are computed from the similar symmetric matrix D^1/2 L_rw D^-1/2 and transformed back with D^-1/2. The node weights D are recovered from L_rw itself. A non‑symmetric matrix that is not of the form D^-1 W with a symmetric W returns an error. Eigenvectors are scaled to unit length; their sign is arbitrary.
Row normalization is recommended for L_sym, whose embedding rows scale with the square root of the node degree. The random starts use a fixed seed, so results are reproducible. The cluster labels are numbered in the order found and carry no meaning.
Pressing Esc aborts the calculation; the function then returns "Calculation aborted by user."
