Skip to article frontmatterSkip to article content

The normal equations

We now solve the general linear least-squares problem in Definition 3.1.1. That is, given ARm×n\mathbf{A}\in\mathbb{R}^{m \times n} and bRm\mathbf{b}\in\mathbb{R}^m, with m>nm>n, find the xRn\mathbf{x}\in\mathbb{R}^n that minimizes bAx2\| \mathbf{b} - \mathbf{A}\mathbf{x} \|_2.

There is a concise explicit solution. In the following proof we make use of the elementary algebraic fact that for two vectors u\mathbf{u} and v\mathbf{v},

(u+v)T(u+v)=uTu+uTv+vTu+vTv=uTu+2vTu+vTv. (\mathbf{u}+\mathbf{v})^T(\mathbf{u}+\mathbf{v}) = \mathbf{u}^T\mathbf{u} + \mathbf{u}^T\mathbf{v} + \mathbf{v}^T\mathbf{u} + \mathbf{v}^T\mathbf{v} = \mathbf{u}^T\mathbf{u} + 2\mathbf{v}^T\mathbf{u} + \mathbf{v}^T\mathbf{v}.

The normal equations have a geometric interpretation, as shown in Figure 3.2.1. The vector in the range (column space) of A\mathbf{A} that lies closest to b\mathbf{b} makes the vector difference Axb\mathbf{A}\mathbf{x}-\mathbf{b} perpendicular to the range. Thus for any z\mathbf{z}, we must have (Az)T(Axb)=0(\mathbf{A} \mathbf{z})^T(\mathbf{A}\mathbf{x}-\mathbf{b})=0, which is satisfied if AT(Axb)=0\mathbf{A}^T(\mathbf{A}\mathbf{x}-\mathbf{b})=\boldsymbol{0}.

Geometry of the normal equations. The smallest residual is orthogonal to the range of the matrix \mathbf{A}.

Figure 3.2.1:Geometry of the normal equations. The smallest residual is orthogonal to the range of the matrix A\mathbf{A}.

3.2.1Pseudoinverse and definiteness

If we associate the left-hand side of the normal equations as (ATA)x(\mathbf{A}^T\mathbf{A})\,\mathbf{x}, we recognize (3.2.3) as a square n×nn\times n linear system to solve for x\mathbf{x}.

Mathematically, the overdetermined least-squares problem Axb\mathbf{A}\mathbf{x}\approx \mathbf{b} has the solution x=A+b\mathbf{x}=\mathbf{A}^+\mathbf{b}.

Computationally we can generalize the observation about Julia from Chapter 2: backslash is equivalent mathematically to left-multiplication by the inverse (in the square case) or pseudoinverse (in the rectangular case) of a matrix. One can also compute the pseudoinverse directly using pinv, but as with matrix inverses, this is rarely necessary in practice.

The matrix ATA\mathbf{A}^T\mathbf{A} appearing in the pseudoinverse has some important properties.

3.2.2Implementation

The definition of the pseudoinverse involves taking the inverse of a matrix, so it is not advisable to use the pseudoinverse computationally. Instead, we use the definition of the normal equations to set up a linear system, which we already know how to solve. In summary, the steps for solving the linear least squares problem Axb\mathbf{A}\mathbf{x}\approx\mathbf{b} are:

Steps 1 and 3 of Algorithm 3.2.1 dominate the flop count.

In the last step we can exploit the fact, proved in Theorem 3.2.2, that N\mathbf{N} is symmetric and positive definite, and use Cholesky factorization as in Exploiting matrix structure. This detail is included in Function 3.2.2.

3.2.3Conditioning and stability

We have already used A\b as the native way to solve the linear least-squares problem Axb\mathbf{A}\mathbf{x}\approx\mathbf{b} in Julia. The algorithm employed by the backslash does not proceed through the normal equations, because of instability.

The conditioning of the linear least-squares problem relates changes in the solution x\mathbf{x} to those in the data, A\mathbf{A} and b\mathbf{b}. A full accounting of the condition number is too messy to present here, but we can get the main idea. We start by generalizing our previous definition of the matrix condition number.

Provided that the minimum residual norm bAx\|\mathbf{b}-\mathbf{A}\mathbf{x}\| is relatively small, the conditioning of the linear least-squares problem is close to κ(A)\kappa(\mathbf{A}).

As an algorithm, the normal equations begin by computing the data for the n×nn\times n system (ATA)x=ATb(\mathbf{A}^T\mathbf{A})\mathbf{x} = \mathbf{A}^T \mathbf{b}. When these equations are solved, perturbations to the data can be amplified by a factor κ(ATA)\kappa(\mathbf{A}^T\mathbf{A}).

The following can be proved using results in Chapter 7.

This squaring of the condition number in the normal equations is the cause of instability. If κ(A)\kappa(\mathbf{A}) is large, the squaring of it can destabilize the normal equations: while the solution of the least-squares problem is sensitive, finding it via the normal equations makes it doubly so.

3.2.4Exercises