IYSE 6740 - Homework 2

1. Eigenfaces and simple face recognition

Import and transform images

Here the .gif images for each subject are imported, converted to matrices, and vectorized. The shape of each image is 243x320, meaning we will need to lower the resolution of each image to about 60x80.

Differentiate training and testing sets for each of the two subjects

Each row represents a lower resolution (i.e. 60x80), vectorized greyscale image.

Generate eigenfaces from each training set

Finding weight vectors to extract different "eigenfaces" that correspond to each subject's pictures' first few principal components. We don't need to normalize the features before PCA because they are all already on the 0 to 255 scale for a pixel in a black and white image.

1 (a)

Subject 1 - First 6 eigenfaces

Subject 2 - First 6 eigenfaces

Analysis:

There appear to be similar patterns in the first 6 eigenfaces for both subjects. The first eigenface, or the image reconstructed using the eigenvector with the largest eigenvalue, appears to be differentiating based on the person's face vs the background. This makes sense because that would be a robust, consistent feature of each image.

From there, the eigenfaces seem to be based off of more and more detailed, less consistent features. For example, the seecond eigenface (for both subjects) appears to capture the shadow created by angled photos of the subject. Then, the orientation of the face and facial features begin to be captured by later eigenfaces.

1 (b) Simple face recognition

Capture pixel means from each of the two training sets

Analysis:

The projection residuals computed above are essentially communicating the difference between each eigenface and the vectorized test image. A smaller projection residual is associated with greater similarity between a subject's eigenface and the test image.

Looking at the projection residual matrix s above, we can see that, when a test image is matched with the correct eigenface, the projection residual value is at least an order of magnitude less than the projection residuals in mismatched cases (e.g., subject 2's test image with the top eigenface of subject 1).

Using this knowledge, a binary classification threshold could be established that is compared against projection residuals in order to determine whether or not it is likely that the test image being evaluated is a match with the eigenface it is being compared against.

1 (c) - bonus

I do think this facial recognition strategy can work well. Given the opportunity to improve this system, I would look into making use of more than just the top eigenface for each class.

The top eigenvectors could be selected using an elbow diagram of the absolute values of their eigenvalues. Then, after weighting each eigenface by the magnitude of its corresponding eigenvalue, the multiple eigenfaces could be blended into a more holistic representation of the face. This blended eigenface could then be compared to test images using the projection residual calculation and a classification threshold.

2. Order of faces using ISOMAP

$\epsilon$-ISOMAP (Isometric Feature Mapping) is applied in order to achieve non-linear feature reduction

Import images for ISOMAP

Create data matrix that contains 698 vectorized images as rows

2 (a)

Step 1)

Create adjacency matrix A (aka the weighted nearest neighbor graph). Without using the $\epsilon$ threshold, the mean distance is about 21.

The following two images are located on the bottom left of the adjacency matrix graph and are generally facing to the right:

The following three images are located on the right of the adjacency matrix graph and are generally facing to the left:

2 (b)

Implementing the ISOMAP algorithm

Step 2) Using the weighted graph A, compute the pairwise shortest distance matrix D

Given a distance matrix A (m x m), this returns shortest path matrix D (m x m) where D[i, j] = the shortest path from image i to image j along the graph. The shortest path is computed using the Floyd-Warshall algorithm.

Step 3) Use the centering matrix H to compute matrix C

Step 4) Compute leading two eigenvectors w1, w2 and eigenvalues $\lambda$1, $\lambda$2 of C

Z is storing the two-dimensional low-dimensional embedding

Scatterplot showing the overall 2D pattern similar to the lecture slides

The scatterplot above shows the embedding space with 20 images accompanying various data points. The overall pattern of the two-dimensional plot generally matches the results from the paper and the lecture slides when using epsilon = 12 (i.e. the distance theshold for the weighted nearest neighbor graph).

One key difference is that the x-axis in my visual is displaying the faces from right-left pose, whereas the paper displays the faces with left-right poses on the x-axis. However, like the paper and the lecture slides, the y-axis is displaying the images from Up-Down poses (i.e. faces the bottom are looking down and faces at the top are looking up).

2 (c)

Repeat using Manhattan distance between images

When using Euclidean distance, $\epsilon$=12 resulted in 48 neighbors for the first image. Therefore, when choosing epsilon for Manhattan distance, I will start by trying to achieve a similar number of neighbors for the first image.

A similar pattern was achieved by using $\epsilon$=515 when calculating neighbor distance with Manhattan distance. Because of the new distance norm, the neighbor threshold had to be recalculated. The starting point for this recalculating was based on achieving a similar number of nearest neighbors for the first image as was achieved using Euclidean distance.

The overall pattern of the two-dimensional low-dimensional representation of the data looks very similar to what was achieved using Euclidean distance. However, the orientation of the faces has now been flipped. The y-axis is now down-up (it was up-down before) and the x-axis is now left-right (it was right-left before).

2 (d)

Repeat using PCA

Using the implementation of PCA written in Question 1, I projected the images into the top two principal components. Clearly, the projection from ISOMAP is much more meaningful than the projection using PCA. The PCA projection is unable to capture the manifold structure of the data, manifesting as much weaker patterns when trying to discern the left-right and down-up poses by the faces.

3. PCA: Food consumption in European countries

Import food consumption data

Create numpy array from DataFrame

3 (a)

The data matrix for this part is set up so that each column corresponds to a country and each row corresponds to a food. The country name column was removed before converting the dataframe to a matrix.

Performing PCA and extracting top 2 eigenvalue/eigenvector pairs

There appear to be some regional groupings in primary food consumption for different countries. Northern European countries are grouped in the bottom right, while southwestern European countries are grouped on the left. This leads me to believe that those regional country groupings tend to consume similar foods. Interestingly, England is plotted relatively far from any other countries, possibly meaning that the food consumption there differs significantly from in other countries.

3 (b)

The data matrix for this part is set up so that each row corresponds to a country and each column corresponds to a food. The country name column was removed before converting the dataframe to a matrix.

Along the 1st principal component (along the x-axis), garlic and olive oil appear to have fairly average consumption by country (whereas real coffee and potatoes are located at each extreme in terms of the 1st principal component). However, along the 2nd principal component, garlic and olive oil have significantly lower values than the rest of the foods. This points to garlic and olive oil being a food that represents a distinction between different countries consumption habits.