Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Open In Colab Binder

Dataset: AT&T Olivetti Faces (1990s, AT&T Laboratories Cambridge). 40 people × 10 photographs, each a 64×64 grayscale image, with pixel values already normalized to [0,1][0,1]. The photographs were taken at different times and contain natural differences in lighting, facial expression, and glasses; no data augmentation of any kind has been applied.

Historical background: in 1991, Turk and Pentland at MIT applied the SVD (equivalent to PCA) to face recognition and called the results Eigenfaces. The name has a double meaning: they are the eigenvectors of the covariance matrix of the faces, and visually they are “face-like ghosts.”

This experiment uses the Olivetti Faces dataset built into sklearn (AT&T Laboratories, 40 people × 10 photographs) and is divided into four parts:

PartTopicCorresponding material
1Exploring and centering the data§11.3 centering matrix
2Extracting eigenfaces with the SVD§11.1 right singular vectors
3Reconstruction and recognition accuracy§11.2 Eckart-Young theorem
4Interactive exploration§11.3 equivalence with PCA

Part 1: Loading and Centering the Data

1.1 Why Subtract the Mean First?

All faces share the same basic structure (the positions and outlines of the eyes and nose). If the mean is not subtracted first, the 0-th singular vector v0\mathbf{v}_0 of the SVD is wasted on describing “the common outline of everyone,” rather than “the differences between different people.”

The centering operation:

X~=X−1mfˉ⊤,fˉ=1m∑j=0m−1xj∈R4096\tilde{\mathbf{X}} = \mathbf{X} - \mathbf{1}_m \bar{\mathbf{f}}^\top, \qquad \bar{\mathbf{f}} = \frac{1}{m} \sum_{j=0}^{m-1} \mathbf{x}_j \in \mathbb{R}^{4096}

Here fˉ\bar{\mathbf{f}} is the pixel-by-pixel average of all the faces—the mean face.

Part 2: Extracting Eigenfaces with the SVD

Apply the SVD to the centered data matrix X~∈R400×4096\tilde{\mathbf{X}} \in \mathbb{R}^{400 \times 4096}:

X~=UΣV⊤\tilde{\mathbf{X}} = \mathbf{U} \boldsymbol{\Sigma} \mathbf{V}^{\top}
MatrixShapeMeaning
U\mathbf{U}400×400400 \times 400Row ii = the “coordinate coefficients” of face ii in the feature space
Σ\boldsymbol{\Sigma}400×400400 \times 400 (diagonal)σ0≥σ1≥⋯≥0\sigma_0 \geq \sigma_1 \geq \cdots \geq 0, measuring the importance of each direction
V⊤\mathbf{V}^{\top}400×4096400 \times 4096Row ii, vi⊤\mathbf{v}_i^{\top} = eigenface ii (a principal axis direction in pixel space)

Part 3: Reconstruction and Recognition

3.1 The Reconstruction Formula

The projection and reconstruction of an arbitrary centered face x~\tilde{\mathbf{x}} in the truncated eigenface space:

x~^k=∑i=0k−1⟨x~,vi⟩⏟eigenface coordinate civi=VkVk⊤x~\hat{\tilde{\mathbf{x}}}_k = \sum_{i=0}^{k-1} \underbrace{\langle \tilde{\mathbf{x}}, \mathbf{v}_i \rangle}_{\text{eigenface coordinate } c_i} \mathbf{v}_i = \mathbf{V}_k \mathbf{V}_k^{\top} \tilde{\mathbf{x}}

Reconstruction error: ∥x~−x~^k∥2=∑i=kr−1ci2\|\tilde{\mathbf{x}} - \hat{\tilde{\mathbf{x}}}_k\|^2 = \sum_{i=k}^{r-1} c_i^2 (the sum of squares of the discarded components)

3.2 The Recognition Method (1-NN)

In the kk-dimensional space of eigenface coordinates, find the known face at the smallest Euclidean distance:

p^=arg⁡min⁡j≠query∥c(j)−c(query)∥2,c(j)=Vk⊤x~j\hat{p} = \arg\min_{j \neq \text{query}} \| \mathbf{c}^{(j)} - \mathbf{c}^{(\text{query})} \|_2, \qquad \mathbf{c}^{(j)} = \mathbf{V}_k^{\top} \tilde{\mathbf{x}}_j

Part 4: Interactive Exploration

Use the sliders to adjust kk and the test face, and observe three aspects in real time:

  1. Left: the reconstruction of the selected face from kk eigenfaces

  2. Middle: the clustering of all the faces in the plane of principal components 0 and 1

  3. Right: the recognition result—who is the nearest neighbor of the query face?

Summary of the Experiment

Connection with the Eckart-Young Theorem of §11.2

The reconstruction-error curve of Part 3a is an intuitive manifestation of the Eckart-Young theorem:

∥X~−X~^k∥F2=∑i=kr−1σi2\|\tilde{\mathbf{X}} - \hat{\tilde{\mathbf{X}}}_k\|_F^2 = \sum_{i=k}^{r-1} \sigma_i^2

The rank-kk approximation given by the truncated SVD minimizes the Frobenius error among all rank-kk matrices. “Reconstructing with kk eigenfaces” is not a heuristic but a choice with a rigorous guarantee of optimality.

Further Reflection

  • If lighting from different directions is added to the faces, which eigenfaces are affected? Which are not?

  • If two different people look very much alike, what happens to their distance in the feature space?

  • The 1-NN classifier of this experiment has no “training/test split.” What problem does this cause in practice?