Laplacian eigenmaps embed points so that neighbours in a kNN graph stay close: minimise subject to , which leads to the generalised eigenproblem with .
heat_kernel_graph(X, k, sigma): symmetric weights. Node is a neighbour of if it is among the nearest points to by Euclidean distance (excluding ; distance ties go to the smaller index). Set if and are neighbours in either direction, else ; zero diagonal.
laplacian_eigenmaps(X, k, sigma, n_components): build the graph, solve through the symmetric matrix (if is its unit eigenvector, solves the generalised problem with ), discard the eigenvector of the smallest eigenvalue (the constant direction), keep the next n_components in increasing eigenvalue order, and flip the sign of each column so that its entry of largest absolute value is positive (first such entry on ties). Return (Z, eigvals): the (N, n_components) embedding and the kept eigenvalues.
dirichlet_energy(W, Z): over all ordered pairs, as a Python float.
The graphs in the tests are connected.