Quiz: from PCA to autoencoders
Before this unit: Day 36: Neural networks.
See also: Day 30: Snakes and active shape models.
Short questions on encoders, decoders and PCA. Try each on paper first, then open the answer. An encoder maps an image to a few numbers z; a decoder maps z back to an image; an autoencoder trains both so that decode(encode(image)) is close to the image.
Q1. In one sentence each: what does the encoder do, what does the decoder do, and what is an autoencoder trained to achieve?
Think of the hourglass: wide, narrow, wide.
The encoder compresses an image into a few numbers z (its place in the latent space). The decoder rebuilds the whole image from z alone. Both are trained together so that the rebuilt image is as close as possible to the input, for many images at once.
Q2. PCA with one component, PC1 = (0.6,\ 0.8), a two-pixel image with the mean subtracted, \mathbf x = (1,\ 2). Encode, decode, and give the squared reconstruction error.
Encode = dot product with PC1. Decode = score × PC1.
Score = 0.6 + 1.6 = 2.2. Decoded 2.2 \cdot (0.6,\ 0.8) = (1.32,\ 1.76). Error (-0.32,\ 0.24), squared length 0.1024 + 0.0576 = 0.16.
Q3. Why must the bottleneck be narrow? What would an autoencoder with a 784-number bottleneck learn on 28\times28 images?
What is the cheapest way to make the output equal the input?
With a bottleneck as wide as the input it can pass the image straight through (or rotate it and rotate it back, as PCA with all components does). The reconstruction is perfect but z summarises nothing. A narrow bottleneck forces z to keep only the main ways in which the images differ.
Q4. For the same data, which has the smaller reconstruction error with 2 numbers per image: PCA, or a trained autoencoder whose encoder and decoder have no ReLU?
What is a network without bends?
They are (at best) equal. Without bends, encoder and decoder are linear maps, and among linear encoder/decoder pairs with 2 numbers PCA already has the smallest squared error. Only the bends let an autoencoder beat PCA.
Q5. Images of a cell that slowly elongates lie on a curve in pixel space. Why can a nonlinear autoencoder describe them with one number, where PCA needs several?
Straight line or curve?
PCA decodes along straight lines (flat subspaces), so a curved family needs several directions to hold its bends. A nonlinear decoder maps one number to a curve, which can follow the family: one number says how far along the elongation the cell is.
Q6. In a 28\times28 PCA, what does a principal component look like if you display it?
How many entries does it have?
It has 784 entries, so it can be shown as a 28\times28 image (an “eigen-image”), with positive and negative values. Decoding adds the mean image and the eigen-images weighted by the scores.