We now revisit least squares as an optimization problem. In Unit 4, residual orthogonality led to the normal equations. Here we obtain the same equations by minimizing a loss function and setting its gradient equal to zero.
This asks for the minimum of the quantity \(\|A\mathbf{x}-\mathbf{b}\|^2\text{.}\) We now use the methods of optimization we have developed to solve this problem in a series of exercises.
Expanding in components, \(g(\mathbf{x}) = d_1 x_1 + \cdots + d_n x_n\text{,}\) and we see that \(D_i g(\mathbf{x}) = d_i\text{,}\) i.e., so that \(\nabla g(\mathbf{x}) = \mathbf{d}\text{.}\)
\begin{align*}
h(\mathbf{x}) \amp = (A \mathbf{x} - \mathbf{b})^T (A \mathbf{x} - \mathbf{b})\\
\amp = \mathbf{x}^T A^T A \mathbf{x} - \mathbf{x}^T A^T \mathbf{b} - \mathbf{b}^T A \mathbf{x} + \mathbf{b}^T \mathbf{b}\\
\amp = \mathbf{x}^T A^T A \mathbf{x} - 2 \mathbf{b}^T A \mathbf{x} + \mathbf{b}^T \mathbf{b}\\
\amp = \mathbf{x}^T A^T A \mathbf{x} - 2 (A^T \mathbf{b}) \cdot \mathbf{x} + \mathbf{b}^T \mathbf{b}\text{.}
\end{align*}
Taking gradients thus gives that
\begin{align*}
\nabla h \amp = ((A^T A) + (A^T A)^T) \mathbf{x} - 2 A^T \mathbf{b} + 0\\
\amp = 2 (A^T A \mathbf{x} - A^T \mathbf{b})\text{.}
\end{align*}
So the critical points of \(h\) occur when \(A^T A \mathbf{x} = A^T \mathbf{b}\text{.}\) This vector-equation is called the normal equation for the least squares problem.
Unit 4 interpreted this as residual orthogonality: the residual is orthogonal to the columns of \(A\text{.}\) Unit 5 interprets the same condition as a zero-gradient equation for
Determine whether any critical point is a local minimum, local maximum, or saddle point. Using this information, solve the least squares optimization problem.
So we need to determine whether \(A^TA\) is positive definite, negative definite, or indefinite. Letβs consider the quadratic form \(\mathbf{x}^T(A^TA)\mathbf{x}\) for any nonzero vector \(\mathbf{x} \in \R^n\text{:}\)
Since \(A\mathbf{x} \neq \mathbf{0}\) for \(\mathbf{x} \neq \mathbf{0}\) - to see why, \(A\) has linearly independent columns and so has rank \(n\text{.}\) By the rank-nullity theorem TheoremΒ 2.4.31, \(\operatorname{nullity}(A)=n-\operatorname{rank}(A)=0\text{,}\) and this means \(\ker(A) = \{ \mathbf{0} \}\text{.}\) So we conclude that \(\mathbf{x}^T(A^TA)\mathbf{x}\) is always positive when \(\mathbf{x} \neq \mathbf{0}\text{.}\) But if \(\mathbf{x}\) is a unit eigenvector for \(A^T A\) with eigenvalue \(\lambda\text{,}\) then we also find that
which must be positive since \(\mathbf{x}^T (A^T A) \mathbf{x}\) is always positive. So \(A^T A\) only has positive eigenvalues. So \(H_h\) is positive definite by TheoremΒ 5.4.14, and so \(h\) has a local minimum at any critical point.
has a single global optimum, at the unique solution to the normal equation \(A^T A \mathbf{x} = A^T \mathbf{b}\text{,}\) i.e., for \(\mathbf{x} = (A^T A)^{-1} A^T \mathbf{b}\text{.}\) So we have found a minimizer to the least squares problem.
This equation is not new. In Unit 4, the normal equations came from residual orthogonality. Now we derive the same equations by minimizing \(h(\mathbf{x})=\|A\mathbf{x}-\mathbf{b}\|^2\text{.}\) The condition \(\nabla h(\mathbf{x})=\mathbf{0}\) gives \(A^TA\mathbf{x}=A^T\mathbf{b}\text{.}\)