At a glance
- Running theme for the whole course: comprehension is compression. For every algorithm, ask where the compression happens.
- If all points lie on a line through the origin, store one representative vector plus one coefficient per point: \(d + n\) numbers instead of \(d \times n\), with exact reconstruction.
- A point off the line is replaced by a proxy on the line. The best proxy is the projection \((\mathbf{x}^\top\mathbf{w})\,\mathbf{w}\) when \(\lVert\mathbf{w}\rVert = 1\).
- Every line compresses equally well; lines differ in reconstruction error. Minimizing that error is the same as maximizing \(\mathbf{w}^\top C\,\mathbf{w}\), solved by the eigenvector of \(C\) with the largest eigenvalue.
- Residues can still carry structure, so repeat on the residues to get \(\mathbf{w}_2, \mathbf{w}_3, \dots\). Centre the data first, since every line here passes through the origin.
Unsupervised learning, made precise
The course begins with unsupervised learning, and within it with representation learning. The starting goal is deliberately vague: given a set of data points, understand something useful about them. Three words need pinning down: data points, understand and useful.
Data points are the easy part. Each is a vector of \(d\) real numbers, its features. Record the height, weight and age of 100 people and each person becomes a point in \(\mathbb{R}^3\), one coordinate per feature.
\(n\) is the number of data points (people, images, …) and \(d\) the number of features recorded for each.
Comprehension is compression
The lecture answers "what does it mean to understand?" with a quote from the computer scientist and philosopher Gregory Chaitin: comprehension is compression. Here, comprehending, understanding and learning are treated as the same thing. If you can compress information so that only its important part remains, and that part is enough to explain the data to someone else, you have learnt from the data.
Ask of every algorithm in this course: where exactly is the compression happening?
One representative, one coefficient per point
How many numbers does it take to store these four points?
The naive answer is \(4 \times 2 = 8\). But in every point the second coordinate is twice the first. So store one representative \([1, 2]^\top\) and, for each point, one coefficient: \(-7,\ 2.5,\ 0.5,\ 0\). That is 6 numbers, and the data comes back exactly: \(\mathbf{x}_2 = 2.5 \times [1, 2]^\top = [2.5, 5]^\top\).
| Stored | Numbers |
|---|---|
| Raw points, \(n \times d\) | 8 |
| Representative \([1, 2]\) | 2 |
| Coefficients \(-7, 2.5, 0.5, 0\) | 4 |
| Compressed total, \(d + n\) | 6 |
| A billion such points | 10⁹ + 2 |
Two points from this example matter later.
- The representative is not unique. Any nonzero vector on the line works. With \([1/\sqrt5,\ 2/\sqrt5]^\top\) the coefficients become \(-7\sqrt5,\ 2.5\sqrt5,\ 0.5\sqrt5,\ 0\) and reconstruction is still exact. The zero vector is not allowed, because nothing can be rebuilt from it. 14:03
- The general count. \(n\) points in \(d\) dimensions take \(d \times n\) numbers raw. If they all lie on one line through the origin, \(d + n\) numbers suffice: \(d\) for the representative and one per point.
When one point leaves the line
Take four points on \(y = x\), for example \([-5,-5]\), \([1,1]\), \([7,7]\) and \([10,10]\), and add one more, \(\mathbf{x}_5 = [5, 6]\), which is not on the line. One representative can no longer rebuild every point. There are three ways out:
| Option | Exact? | Numbers for 5 points | Verdict |
|---|---|---|---|
| Store the raw points | Yes | 10 | No compression |
| Two representatives \([1,0]\), \([0,1]\), two coefficients per point | Yes | 4 + 10 = 14 | Worse than raw: \(2n + 4\) |
| One representative; replace \(\mathbf{x}_5\) by a proxy on the line | No | 2 + 5 = 7 | Compresses, at a small loss |
Exact reconstruction and fewer representatives cannot both be kept. The lecture gives up exactness 21:26. Pretend the data set contained a proxy for \(\mathbf{x}_5\) on the line instead of \(\mathbf{x}_5\) itself, and compress as before.
The best proxy is the projection
The best proxy is the point on the line where we lose the least: the error vector we would have to add back to the proxy to recover \(\mathbf{x}\) should be as short as possible. A line through the origin is every multiple \(c\,\mathbf{w}\) of a nonzero representative \(\mathbf{w}\), so we choose the scalar \(c\):
Setting the derivative with respect to \(c\) to zero (the lecture leaves this as an exercise): \(-2w_1(x_1 - c w_1) - 2w_2(x_2 - c w_2) = 0\), so
The numerator is the dot product of \(\mathbf{x}\) and \(\mathbf{w}\); the denominator is the squared length of \(\mathbf{w}\). The same formula holds in any dimension.
Since any vector on the line can represent it, always pick \(\mathbf{w}\) with \(\lVert\mathbf{w}\rVert = 1\) (a point on the unit circle). The denominator disappears:
\[ \text{proxy of } \mathbf{x} \text{ on the line } \mathbf{w} = (\mathbf{x}^\top \mathbf{w})\,\mathbf{w}, \qquad \text{coefficient} = \mathbf{x}^\top\mathbf{w} \]Which line?
Nobody tells us which points lie on the line. Off-line points are the rule, not the exception: plot height against weight for a class of 100 people and perhaps no point sits exactly on the line we would draw. An exact linear relationship between features is a myth outside physical laws. So we always use proxies, and the line itself must be found from the data.
Any line gives the same compression: one representative plus one coefficient per point. What differs is how much we lose. The red line in the lecture beats the blue one because rebuilding the data from its proxies gives a smaller reconstruction error.
Goal: find the line through the origin with the least reconstruction error.
From reconstruction error to \(\mathbf{w}^\top C\,\mathbf{w}\)
For a line given by a unit vector \(\mathbf{w}\), add up each point's squared error. The lecture uses the average rather than the sum; the same \(\mathbf{w}\) minimizes both, and the average is easier to interpret later.
Write the squared length as a vector dotted with itself and expand. Using \(\mathbf{w}^\top\mathbf{w} = 1\):
The first term does not involve \(\mathbf{w}\), so dropping it does not change the minimizer. Minimizing \(-\tfrac1n\sum(\mathbf{x}_i^\top\mathbf{w})^2\) is the same as maximizing it without the minus sign. Finally, \((\mathbf{x}_i^\top\mathbf{w})^2 = \mathbf{w}^\top\mathbf{x}_i\,\mathbf{x}_i^\top\mathbf{w}\), and \(\mathbf{w}\) does not depend on \(i\), so it comes out of the sum:
\(C\) is an average of \(n\) matrices of size \(d \times d\), one per data point. The lecture calls it the covariance matrix. The maximizer is the eigenvector of \(C\) with the largest eigenvalue 16:00.
\(\frac1n\sum \mathbf{x}_i\mathbf{x}_i^\top\) is the usual covariance matrix only when the data has mean zero. Lecture 5 adds that step (centring) for a different reason. The lecture says more about why a covariance appears in an error-minimization problem later; for now the takeaway is that the problem has a well-understood eigenvector solution.
Is one line enough?
Treat the best-line solver as a black box: data goes in, a line comes out. That line is not always satisfying. Suppose 3-D data points all lie on a plane. The best line will lie in that plane (a line outside it would cost more to project onto), but the plane is the real structure, and a single line misses half of it.
The part we have been calling "error" may then carry information. Pure noise would point every which way. Here the error vectors, the residues \(\mathbf{x}_i - (\mathbf{x}_i^\top\mathbf{w})\mathbf{w}\), all line up along one direction.
A possible algorithm L5 · 7:42
- Repeated best-line fitting
- Input \(\{\mathbf{x}_1, \dots, \mathbf{x}_n\}\), \(\mathbf{x}_i \in \mathbb{R}^d\).
- Find the best line \(\mathbf{w}_1\): minimize the reconstruction error, equivalently maximize \(\mathbf{w}^\top C\mathbf{w}\).
- Replace each point by its residue: \(\mathbf{x}_i \leftarrow \mathbf{x}_i - (\mathbf{x}_i^\top\mathbf{w}_1)\,\mathbf{w}_1\).
- Repeat on the residue data set to get \(\mathbf{w}_2\), then \(\mathbf{w}_3\), and so on, at most \(d\) times.
Centre the data first
Every line here passes through the origin, because a proxy is a coefficient times the representative and a coefficient of 0 must give the origin. If the data sits far from the origin, the best line through the origin can miss the direction in which the data is spread. The lecture's example: the x-axis can beat the line that follows the data.
The fix is to centre the data before anything else: compute the mean and subtract it from every point. The new data set has its mean at the origin, so lines through the origin now follow the spread.
Open questions, answered in Part 3
L5 ends with four questions. Answering them turns the procedure into the first algorithm of the course, a representation learning algorithm for unsupervised learning.
- How do we solve \(\max_{\lVert\mathbf{w}\rVert=1} \mathbf{w}^\top C\mathbf{w}\)? (The hint: an eigenvector.)
- How many times should the residue step be repeated?
- Where exactly is the compression happening once there are several lines?
- With several lines and several coefficients per point, what representation are we actually learning?
Key terms
- Representation learning
- Finding a compact description of data points that keeps what matters.
- Comprehension is compression
- The course's running theme: learning means keeping only the important part of the data.
- Representative
- One vector shared by the whole data set that spans the chosen line.
- Coefficient
- The single number per point that scales the representative, \(\mathbf{x}^\top\mathbf{w}\) for unit \(\mathbf{w}\).
- Proxy
- The point on the line that stands in for an off-line point: its projection \((\mathbf{x}^\top\mathbf{w})\mathbf{w}\).
- Projection
- The closest point on a line to a given point; the error is perpendicular to the line.
- Reconstruction error
- Average squared distance between points and their proxies, \(f(\mathbf{w})\).
- Covariance matrix \(C\)
- \(\frac1n\sum\mathbf{x}_i\mathbf{x}_i^\top\) for centred data; the best line is its top eigenvector.
- Residue
- What is left of a point after removing its proxy: \(\mathbf{x} - (\mathbf{x}^\top\mathbf{w})\mathbf{w}\).
- Centring
- Subtracting the mean from every point so lines through the origin follow the data.
Test yourself
Q1How many numbers does it take to store 1,000 points in \(\mathbb{R}^{50}\) that all lie on one line through the origin?
\(d + n = 50 + 1000 = 1050\), instead of \(d \times n = 50{,}000\).
Q2Why is using the two representatives \([1,0]\) and \([0,1]\) a bad way to handle a point that is off the line?
It is exact, but every point then needs two coefficients, and the representatives add 4 more numbers: \(2n + 4\), which is more than the raw \(2n\).
Q3Project \(\mathbf{x} = [3, 1]\) onto the line spanned by \(\mathbf{w} = [1, 0]\). What is the proxy and the squared error?
\(\mathbf{w}\) already has length 1, so the coefficient is \(\mathbf{x}^\top\mathbf{w} = 3\) and the proxy is \([3, 0]\). The error vector is \([0, 1]\), squared error 1.
Q4Why can the term \(\frac1n\sum\lVert\mathbf{x}_i\rVert^2\) be dropped when choosing \(\mathbf{w}\)?
It does not depend on \(\mathbf{w}\). Adding a constant to every candidate's objective does not change which candidate is smallest.
Q5All lines through the origin give the same compression ratio. Then what makes one line better than another?
Its reconstruction error: how far the points are from their proxies on that line. The best line minimizes it.
Q6Why centre the data before looking for lines?
All candidate lines pass through the origin. If the data is far from the origin, the best such line is pulled toward the mean instead of following the direction the data varies in.