projects / proj-math-002
Next task →
Projects/Foundations/Spectral clustering from a k-NN Laplacian — real-data stress test
Level 2 · foundational · ~7 h

Spectral clustering from a k-NN Laplacian — real-data stress test

Recover the ten digit communities of MNIST without using labels when building the affinity graph, and compare with k-means on raw pixels. Repeat on a real dataset, report a table with confidence intervals over three trials, and explain which assumption broke.
Add to portfolio →

Problem statement

  • 01Recover the ten digit communities of MNIST without using labels when building the affinity graph, and compare with k-means on raw pixels. Repeat on a real dataset, report a table with confidence intervals over three trials, and explain which assumption broke.

Real-world motivation

  • 01Eigenvectors of a graph Laplacian expose manifold structure that Euclidean k-means cannot see. The real-data stress test setting forces concrete choices about data, scale and evaluation.

Learning objectives

  • 01Build a sparse k-NN affinity graph
  • 02Compute the normalized Laplacian eigenvectors
  • 03Evaluate cluster quality against labels
  • 04Report wall-clock seconds on one pinned CPU core alongside the baseline metrics.

Technical architecture

  • 01sparse k-NN graph with adaptive Gaussian kernel
  • 02L_sym = I - D^-1/2 A D^-1/2
  • 03row-normalize eigenvectors then run k-means

Mathematical foundations

  • 01$A_{ij}=\exp(-\lVert x_i-x_j\rVert^2/(\sigma_i\sigma_j))$ for mutual k-NN pairs
  • 02$\min_{Y^\top Y=I}\mathrm{tr}(Y^\top L_{sym}Y)$ solved by the bottom eigenvectors

Dataset and sources

  • 01MNIST 70k subset
  • 02UCI Sparse Matrix collection

Step-by-step tasks

  • 01Frame the task and freeze the real-data stress test evaluation protocol with a fixed random seed.
  • 02Implementation 1: Build A with scipy.sparse and mutual 10-NN
  • 03Implementation 2: Select sigma by the median heuristic
  • 04Implementation 3: Use eigsh(k=11, which='SM') and cluster the rows of Y
  • 05Verification 1: Assert all eigenvalues of L_sym are nonnegative
  • 06Verification 2: Check Y.T @ Y is within 1e-5 of identity
  • 07Run the ablation grid and report wall-clock seconds on one pinned CPU core over three independent trials.

Implementation requirements

  • 01Build A with scipy.sparse and mutual 10-NN
  • 02Select sigma by the median heuristic
  • 03Use eigsh(k=11, which='SM') and cluster the rows of Y
  • 04Log all hyperparameters and the random seed for the real-data stress test run.

Testing requirements

  • 01Assert all eigenvalues of L_sym are nonnegative
  • 02Check Y.T @ Y is within 1e-5 of identity
  • 03Measure wall-clock seconds on one pinned CPU core over at least three seeds.

Evaluation metrics

  • 01NMI
  • 02ARI
  • 03cluster purity
  • 04wall-clock seconds on one pinned CPU core

Expected outputs

  • 01cluster assignments
  • 02eigenvalue spectrum plot

Common failure modes

  • 01disconnected graph yields trivial components
  • 02sigma too small isolates every point
  • 03real data violates the synthetic noise model and the baseline overfits

Stretch goals

  • 01add a Nyström out-of-sample extension
  • 02compare with UMAP embeddings
  • 03profile the method with cProfile and report the dominant kernel

Research extensions

  • 01derive a consistency rate for k-NN affinity under sampling
  • 02study spectral clustering with corrupted affinity edges

GitHub submission requirements

  • 01A repository whose README states the real-data stress test protocol and the exact command to reproduce it.
  • 02Source for the scratch implementation, a test file, and a results table with uncertainty estimates.
  • 03A two-page report explaining failures on MNIST 70k subset and what the ablation revealed.

Completion rubric

  • 01correct sparse Laplacian construction
  • 02justified sigma selection
  • 03NMI within 3 points of the reference
  • 04Extra credit: profile the method with cProfile and report the dominant kernel

Submit when every rubric item is satisfied and your repository contains runnable code plus a reproduction command.