Least Squares and Pseudoinverses

Replace an unreachable target with its closest column-space projection, interpret the orthogonal residual, and use the pseudoinverse to select the minimum-norm least-squares solution.

When a target lies outside a matrix's column space, the system Ax=bA\mathbf{x}=\mathbf{b} has no exact solution. Least squares replaces the unreachable target with its closest reachable approximation. The pseudoinverse then provides one consistent rule for choosing the parameters.

An Inconsistent System Still Has a Best Approximation

Suppose one number xx is expected to satisfy both

x=1andx=3.x=1 \qquad\text{and}\qquad x=3.

No value satisfies both equations. In matrix form,

[11]Ax=[13]b.\underbrace{\begin{bmatrix}1\\1\end{bmatrix}}_{A}x =\underbrace{\begin{bmatrix}1\\3\end{bmatrix}}_{\mathbf{b}}.

The reachable predictions are all points [x,x]T[x,x]^{\mathsf T} on a line. The target [1,3]T[1,3]^{\mathsf T} lies outside that line. Least squares chooses the reachable point closest to the target.

This situation is common when several noisy measurements constrain fewer unknown quantities. The equations may disagree slightly even though a useful approximation exists.

The Residual Measures the Remaining Error

For a proposed parameter vector x\mathbf{x}, define

b^=Axandr=bb^.\widehat{\mathbf{b}}=A\mathbf{x} \qquad\text{and}\qquad \mathbf{r}=\mathbf{b}-\widehat{\mathbf{b}}.

Here b^\widehat{\mathbf{b}} is the fitted or predicted output, and r\mathbf{r} is the residual. Least squares chooses

x=argminx  bAx22.\mathbf{x}^{\star} =\underset{\mathbf{x}}{\arg\min}\; \|\mathbf{b}-A\mathbf{x}\|_2^2.

Read this as: “among all parameter vectors x\mathbf{x}, choose the one that makes the squared distance between the target b\mathbf{b} and prediction AxA\mathbf{x} as small as possible.”

The notation argmin\arg\min asks for the input at which the expression is smallest, rather than the smallest value itself.

For the scalar example, the objective is

L(x)=(1x)2+(3x)2.L(x)=(1-x)^2+(3-x)^2.

Expanding and completing the square gives

L(x)=2x28x+10=2(x2)2+2,L(x)=2x^2-8x+10=2(x-2)^2+2,

so the minimum occurs at x=2x=2. The fitted output is [2,2]T[2,2]^{\mathsf T} and the residual is [1,1]T[-1,1]^{\mathsf T}. Least squares does not make an impossible system exact; it makes the squared residual as small as possible.

Exercise: Find a one-parameter least-squares fit

Minimize (2x)2+(6x)2(2-x)^2+(6-x)^2. What value of xx gives the least-squares fit?

Compute it first, then check your number.

Review

Not marked done.

Your checked work will be saved automatically.

Correct records the checked result. Done is your learning status, and you can undo it.

Clearing an answer or resetting code starts the response again. It does not remove Done or Review.

Your checked work will be saved automatically.

HintBalance the two residuals

At the midpoint, the two residuals have equal magnitude and opposite signs.

SolutionComplete the square

Expanding gives

(2x)2+(6x)2=2x216x+40=2(x4)2+8.(2-x)^2+(6-x)^2=2x^2-16x+40=2(x-4)^2+8.

The nonnegative squared term is smallest at x=4x=4. At this point the two residuals are 2-2 and 22, so neither direction of movement can reduce their total squared magnitude.

Least Squares Is an Orthogonal Projection

Every prediction AxA\mathbf{x} lies in Col(A)\operatorname{Col}(A). The closest prediction AxA\mathbf{x}^{\star} is the orthogonal projection of b\mathbf{b} onto that column space.

At the closest point, the residual

r=bAx\mathbf{r}^{\star}=\mathbf{b}-A\mathbf{x}^{\star}

is orthogonal to every column of AA. Writing all those dot products together gives

ATr=0.A^{\mathsf T}\mathbf{r}^{\star}=\mathbf{0}.

Substituting the residual definition produces the normal equations:

ATAx=ATb.A^{\mathsf T}A\mathbf{x}^{\star}=A^{\mathsf T}\mathbf{b}.

The normal equations say that, at the least-squares solution, every column of AA has zero dot product with the residual. They describe perpendicularity, not a new kind of average.

The word “normal” refers to perpendicularity: the residual is normal to the column space.

Exercise: Identify the optimal residual direction

At a least-squares solution, how is the residual related to Col(A)\operatorname{Col}(A)?

Choose the geometric condition

Select one choice, then check.

Review

Not marked done.

Your checked work will be saved automatically.

Correct records the checked result. Done is your learning status, and you can undo it.

Clearing an answer or resetting code starts the response again. It does not remove Done or Review.

Your checked work will be saved automatically.

HintUse the projection geometry

Draw the shortest segment from the target to the column space.

SolutionThe residual is perpendicular

The fitted output is the orthogonal projection of b\mathbf{b} onto the column space. Therefore the displacement from the fit to the target is perpendicular to every column-space direction:

ATr=0.A^{\mathsf T}\mathbf{r}^{\star}=\mathbf{0}.

The Best Prediction May Have Several Parameter Vectors

The fitted output AxA\mathbf{x}^{\star} is unique because an orthogonal projection onto a subspace is unique. The parameter vector x\mathbf{x}^{\star} need not be unique.

If AA has a nontrivial null space and zNull(A)\mathbf{z}\in\operatorname{Null}(A), then

A(x+z)=Ax.A(\mathbf{x}^{\star}+\mathbf{z}) =A\mathbf{x}^{\star}.

All these parameter vectors produce the same fit and the same residual. A least-squares parameter solution is unique exactly when AA has full column rank. In that case ATAA^{\mathsf T}A is invertible and

x=(ATA)1ATb.\mathbf{x}^{\star} =(A^{\mathsf T}A)^{-1}A^{\mathsf T}\mathbf{b}.

This formula explains the solution but is not usually the preferred numerical procedure. Forming ATAA^{\mathsf T}A can worsen conditioning; QR or singular value decomposition is generally more reliable.

Exercise: Recognize nonunique parameters

Suppose x\mathbf{x}^{\star} minimizes the squared residual and z\mathbf{z} is a nonzero null vector of AA. What can be said about x+z\mathbf{x}^{\star}+\mathbf{z}?

Choose the consequence

Select one choice, then check.

Review

Not marked done.

Your checked work will be saved automatically.

Correct records the checked result. Done is your learning status, and you can undo it.

Clearing an answer or resetting code starts the response again. It does not remove Done or Review.

Your checked work will be saved automatically.

HintApply the matrix to the sum

Use linearity and the definition of the null space.

SolutionNull-space movement preserves the fit

Since Az=0A\mathbf{z}=\mathbf{0},

A(x+z)=Ax+Az=Ax.A(\mathbf{x}^{\star}+\mathbf{z}) =A\mathbf{x}^{\star}+A\mathbf{z} =A\mathbf{x}^{\star}.

The fitted output and residual are unchanged, so the shifted vector is another least-squares solution.

The Pseudoinverse Chooses One Canonical Solution

The Moore–Penrose pseudoinverse, written A+A^{+}, is defined for every matrix—square or rectangular, full rank or rank deficient. The vector

x+=A+b\mathbf{x}^{+}=A^{+}\mathbf{b}

has two linked properties:

  1. it minimizes bAx2\|\mathbf{b}-A\mathbf{x}\|_2;
  2. among all vectors with that minimum residual, it has the smallest Euclidean norm x2\|\mathbf{x}\|_2.

Thus the pseudoinverse handles both difficulties:

  • if the target is unreachable, it chooses a closest reachable prediction;
  • if several parameter vectors give that prediction, it chooses the minimum-norm one.

When a square matrix is invertible, A+=A1A^{+}=A^{-1}. The pseudoinverse is not an ordinary inverse for every matrix; in general, neither A+AA^{+}A nor AA+AA^{+} must be the identity. Instead, these products act as projections onto the appropriate retained subspaces.

Exercise: Choose among equally good fits

Several parameter vectors produce the same minimum least-squares residual. Which one does A+bA^{+}\mathbf{b} select?

Choose the selection rule

Select one choice, then check.

Review

Not marked done.

Your checked work will be saved automatically.

Correct records the checked result. Done is your learning status, and you can undo it.

Clearing an answer or resetting code starts the response again. It does not remove Done or Review.

Your checked work will be saved automatically.

HintRecall the second optimization criterion

First minimize the residual; then minimize the parameter norm among ties.

SolutionUse the minimum-norm solution

The pseudoinverse first attains the smallest possible residual and then selects, among all equally good fits, the vector with minimum x2\|\mathbf{x}\|_2.

Singular Values Explain the Pseudoinverse

The later singular value decomposition lesson will factor a matrix as

A=UΣVT.A=U\Sigma V^{\mathsf T}.

In that coordinate system, the pseudoinverse reciprocates nonzero singular values and leaves zero singular values at zero:

A+=VΣ+UT.A^{+}=V\Sigma^{+}U^{\mathsf T}.

A zero singular value represents a direction erased by the matrix. Replacing it with 1/01/0 would be undefined and would pretend to recover information that the output does not contain.

Exercise: Interpret a zero singular value

Why does the pseudoinverse leave the reciprocal of a zero singular value at zero rather than attempting to compute 1/01/0?

Choose the reason

Select one choice, then check.

Review

Not marked done.

Your checked work will be saved automatically.

Correct records the checked result. Done is your learning status, and you can undo it.

Clearing an answer or resetting code starts the response again. It does not remove Done or Review.

Your checked work will be saved automatically.

HintTrack the lost direction

Every magnitude along that input direction produces the same zero output component.

SolutionDo not invent erased information

A zero singular value collapses an input direction to zero. Because the output contains no evidence of the original magnitude, no inverse-like operation can reconstruct it uniquely.

Compare least squares and the pseudoinverse

Edit the matrix or target. Both methods produce a least-squares fit; the pseudoinverse also remains defined for rank-deficient matrices.

Ready to run.

The repeated columns make the parameter vector nonunique. The pseudoinverse splits the shared contribution evenly, giving the minimum-norm solution. The final output confirms that the residual is orthogonal to both columns.

Before Using Least Squares

Separate three objects: the parameter vector x\mathbf{x}, the fitted output AxA\mathbf{x}, and the residual bAx\mathbf{b}-A\mathbf{x}. Check whether the target is exactly reachable, whether the parameters are unique, and whether a minimum-norm selection is appropriate. In numerical work, use a least-squares solver rather than explicitly forming (ATA)1(A^{\mathsf T}A)^{-1}.

The next lesson studies eigenvectors: special directions that a square matrix keeps on the same line. That viewpoint begins a different route into matrix structure and repeated transformations.

Review

Not marked done.