Projections onto Subspaces¶
Projection¶
If we have a vector \(\mathbf{b}\) and a line determined by a vector \(\mathbf{a}\), how do we find the point on the line that is closet to \(\mathbf{b}\)?
We can see from the figure that this closet point \(p\) is at the intersection formed by a line through \(\mathbf{b}\) that is orthogonal to \(\mathbf{a}\). If we think of \(\mathbf{p}\) as an approximation of \(\mathbf{b}\), then the length of \(\mathbf{e} = \mathbf{b} - \mathbf{p}\) is the error in that approximation.
We could try to find \(\mathbf{p}\) using trigonometry or calculus, but it's easier to use linear algebra. Since \(\mathbf{p}\) lies on the line through \(\mathbf{a}\), we know \(\mathbf{p} = \mathbf{a}x\) for some number \(x\). We also know that \(\mathbf{a}\) is perpendicular to \(\mathbf{e} = \mathbf{b} - \mathbf{a}x\):
and
Doubling \(\mathbf{b}\) will double \(\mathbf{p}\), doubling \(\mathbf{a}\) does not affect \(\mathbf{p}\).
Projection Matrix¶
We'd like to write this projection in terms of a projection matrix
\(P\):
As
so the matrix is:
Note that \(\mathbf{a}\mathbf{a}^T\) is a \(3 \times 3\) matrix, not a number; matrix multiplication is not commutative.
The column space of \(P\) is spanned by \(\mathbf{a}\) because for any \(\mathbf{b}\), \(P\mathbf{b}\) lies on the line determined by \(\mathbf{a}\). The rank of \(P\) is \(1\). \(P\) is symmetric. \(P^2\mathbf{b} = P\mathbf{b}\) because the projection of a vector already on the line through \(\mathbf{a}\) is just that vector. In general, projection matrices have the properties:
Why Projection?¶
As we know, the equation \(A\mathbf{x} = \mathbf{b}\) may have no solution. The vector \(A\mathbf{x}\) is always in the column space of \(A\), and \(\mathbf{b}\) is unlikely to be in the column space. So, we project \(\mathbf{b}\) onto a vector \(\mathbf{p}\) in the column space of \(A\) and solve \(A\mathbf{\hat{x}} = \mathbf{p}\).
Projection in Higher Dimension¶
In \(\mathbb{R}^3\), how do we project a vector \(\mathbf{b}\) onto the closet point \(\mathbf{p}\) in a plane?
If \(\mathbf{a_1}\) and \(\mathbf{a_2}\) form a basis for the plane, then that plane is the column space of the matrix \(A = \begin{bmatrix} \mathbf{a_1} & \mathbf{a_2} \end{bmatrix}\).
We know that \(\mathbf{b} = \hat{x_1}\mathbf{a_1} + \hat{x_2}\mathbf{a_2} = A\mathbf{\hat{x}}\). We want to find \(\mathbf{\hat{x}}\). There are many ways to show that \(\mathbf{e} = \mathbf{b} - \mathbf{p} = \mathbf{b} - A\mathbf{\hat{x}}\) is orthogonal to the plane we're projecting onto, after wihch we can use the fact that \(\mathbf{e}\) is perpendicular to \(\mathbf{a_1}\) and \(\mathbf{a_2}\):
In matrix form:
When we were projecting onto a line, \(A\) only had one column and so this equation looked like:
Note that \(\mathbf{e} = \mathbf{b} - A\mathbf{\hat{x}}\) is in the nullspace of \(A^T\) and so is in the left nullspace of \(A\). We know that everything in the left nullspace of \(A\) is perpendicular to the column space of \(A\), so this is another confirmation that our calculation are correct.
We can rewrite the equation \(A^T(\mathbf{b} - A\mathbf{\hat{x}})\) as:
When projecting onto a line, \(A^TA\) was just a number; now it is a square matrix.
So instead of dividing by \(\mathbf{a}^T\mathbf{a}\) we now have to multiply by \((A^TA)^{-1}\).
In \(n\) dimensions:
It's tempting to try to simplify these expressions, but if \(A\) isn't a square matrix we can't say that \((A^TA)^{-1} = A^{-1}(A^T)^{-1}\).
If \(A\) does happen to be a square, invertible matrix then it's column space is the whole space and contains \(\mathbf{b}\). In this case \(P\) is the identity, as we find when we simplify. It is still true that:
Least Squares¶
Suppose we're given a collection of data points \((t, b)\):
and we want to find the closet line \(b = C + Dt\) to that collection. If the line went through all three points, we'd have:
Which is equivalent to:
In our example the line does not go through all three points, so this equation is not solvable. Instead we'll solve: