Chapter 3 taught us to decide whether has a solution,
and to find them all when it does. Real data rarely
cooperates. Measure a quantity that depends linearly on
two unknowns, take ten measurements, and you have ten
equations in two unknowns; each measurement carries a
little error, and the ten equations are almost certainly
inconsistent. Refusing to answer is not useful. This
section replaces the question “which solves ?” with “which
comes closest?”,
and shows that the new question always has an answer,
computed by solving a square system.
The other half of the section handles the opposite
complaint. When a system is consistent but
underdetermined, there are too many solutions, and we
want a canonical one. Orthogonality picks it: exactly
one solution is perpendicular to the kernel, and it is
the shortest.
Throughout, or , and and carry the standard
inner product , with .
The
residual, and a piece of notation
Given and , write for the residual of a
candidate . The
system is consistent exactly when some makes . When none does,
we ask for the
making as short
as possible, that is, minimizing a sum of squares; hence the
name least squares.
Two observations turn this into geometry. First, as
ranges over
, the vector
ranges over
exactly the column space
(Theorem 0.9.3), a
finite-dimensional subspace. Second, minimizing over all
is therefore the
same as finding the point of nearest to . We already know that
point: it is , by Theorem 11.3.5. All
that remains is to turn “the residual is perpendicular
to ” into
equations, and for that we need one piece of
notation.
Recall the conjugate transpose of Definition 11.1.2:
the matrix with entries , obtained by transposing and then
conjugating every entry, so that over . Comparing entries
and using Theorem 0.9.5 together
with the rules for conjugation (Theorem 0.6.2) gives
whenever the sizes match. The third is the one
worth seeing done: , which is where the order
reverses. The one consequence we really use is the
following.
Lemma
11.4.1 (Moving a matrix across the inner
product)
Let . Then for all and ,
Proof. Regarding vectors as
columns, , a matrix identified with its entry.
Hence where the third equality uses . The second identity follows by
conjugating the first, since and .
The lemma is the matrix case of a general principle:
to move a map across an inner product, pay with its
adjoint. Section 6 develops that principle for
linear maps between abstract inner product spaces; here
the two lines above are all we need.
The normal
equations
Theorem
11.4.2 (Least Squares Theorem)
Let and , and write . For , the following are equivalent:
- (a) for every ;
- (b) ;
- (c) .
Moreover such an always exists. A
vector satisfying these conditions is called a
least-squares solution of , and the
equations in (c) are the normal
equations.
Idea. Condition (a) is a
minimization over ; condition (b) is the
same minimization rewritten in , where Theorem 11.3.5 has
already solved it. So (a) (b) is a
translation, not an argument. The content is (b) (c):
saying
is the same as saying the residual is perpendicular to
, and
“perpendicular to every column of ” is what
says. Existence is free, because lies in and so is
for some .
Proof. Since (Theorem 0.9.3),
condition (a) says that is a vector of at least as close to
as every other
vector of . By Theorem 11.3.5 the
unique such vector is . Hence (a) (b).
- (b) (c).
Write , the splitting of Theorem 11.3.2 (a)
with . For we have , so
holds if and only if is the -part of , that is, if and only
if . It
remains to see that Put . By Proposition 11.3.1,
if
and only if is
orthogonal to every , and by Lemma 11.4.1, If , all these vanish. Conversely, if all
vanish, take to get , hence by positive definiteness. So if and
only if , which rearranges to .
Existence. , so for some
, and
that satisfies
(b).
Three things are worth extracting. The normal
equations are a square system,
whatever the shape of . They are
always consistent, by the existence
clause, even when is not. And the minimizing value
is unique — it
is — even if
the minimizing
is not.
Warning. “Closest” is
measured by the inner product, so the answer moves when
the inner product does. Least squares is not a
coordinate-free notion: it minimizes for a
particular norm on , and rescaling one
coordinate — reporting one measurement in centimeters
instead of meters, say — is a change of inner product.
Concretely, for the data the least-squares line is
;
if the middle point is trusted twice as much, so that
the second coordinate of is weighted by , the best line becomes
. Both are
correct answers to their own question, and Exercise C1
works the general case out. Before fitting, decide which
errors count equally.
Quick check. The system may have no
solution at all, yet the normal equations
always have one. Where does the proof arrange that, and
what stops the same argument from solving itself?
Solution. The existence clause uses
that lies in
, and
every vector of is for some . So the normal
equations ask
to hit , a
target that is inside the column space by construction.
The original system asks to hit , which need not be in
at all.
Projecting first is exactly the step that moves the
target into reach; what is given up is the requirement
, which
becomes .
When is
the least-squares solution unique?
The minimizers of are the
solutions of the normal equations, so they form the
solution set of a linear system: a coset (Theorem 3.1.3). To
read off uniqueness we therefore need , and the
following small lemma computes it.
Lemma
11.4.3 (The null space of )
Let . Then .
Proof. If , then .
Suppose . Pair with and move across using Lemma 11.4.1: Hence by positive definiteness. This proves the
lemma.
This is the “pair it with itself” move once more, and
it is the whole reason the normal equations behave well.
It will return in Section 6 in the form for
a linear map
between inner product spaces, with the same two-line
proof; the matrix statement above is the case we need
now.
Corollary
11.4.4 (Uniqueness of the least-squares
solution)
Let and . The following are equivalent:
- (a) has exactly one
least-squares solution (for one, equivalently for every,
);
- (b) the columns of
are linearly
independent, that is ;
- (c) is
invertible.
In that case the least-squares solution is .
Proof. By Theorem 11.4.2 the
least-squares solutions are the solutions of , a
consistent system; by Theorem 3.1.3 its
solution set is a coset of , which is
by Lemma 11.4.3. So
the solution is unique, for one or for all, exactly
when . Now says
precisely that the only vanishing linear combination of
the columns of
is the trivial one, that is, that the columns are
independent; and by Theorem 3.5.7 this
is the same as . This proves (a) (b).
- (b) (c). The
matrix is
, so it
is invertible if and only if
(Theorem 3.4.4). By
Lemma 11.4.3 this
happens exactly when .
Finally, if is invertible,
multiplying the normal equations on the left by gives the
stated formula.
Warning. is not
.
The rule needs and to be invertible, and
in least squares
is usually not even square. Take The left side exists; the symbols and do not exist
at all, since is
. The
formula must be read as one
object applied
to , never
simplified.
Fitting a
line and a parabola
Example
(The least-squares line through four points)
Find the line that minimizes the sum of the squared
vertical errors at the four data points Compute the residual and the minimum value of
the sum of squares.
Solution. Asking for at the
four points is the system with and is exactly the sum of the squared
vertical errors. The columns of are independent (they
are not multiples of each other), so Corollary 11.4.4
gives a unique answer. Over , , and The normal equations , simplify
to and
;
subtracting twice the second from the first gives , so and . The least-squares
line is Its values at are , so the residual is and the minimum sum of squares is .
Check. The residual must be orthogonal to
both columns of :
and . Both hold, which confirms the normal
equations.
The same machinery fits any linear combination of
prescribed functions; only the columns of change. “Linear”
refers to the unknown coefficients, not to the shape of
the curve.
Example
(The least-squares parabola)
Find the quadratic minimizing the sum of squared
errors at
Solution. Now has columns , and : Because the nodes are symmetric about , every odd power sums
to zero: and . With and , The middle equation decouples: , so . The outer two are
and
; the
first gives , and substituting gives , so and . The least-squares
parabola is Its values at the nodes are , so
and the minimum sum of squares is .
Check. , and : the residual is orthogonal to all three
columns.
Two practical remarks. Choosing the nodes
symmetrically, as above, made nearly diagonal
and the arithmetic painless; the same trick appears
again in Section 9 when the columns are trigonometric
functions. And although the normal equations are the
right way to understand least squares, they are
not always the right way to compute it: Section
8 solves the same problem through a QR factorization,
which avoids forming at all.
The
minimum-norm solution
Now the opposite situation: is consistent,
but has a
non-trivial null space, so the solutions form an
infinite family (Theorem 3.1.3).
Which one should we report? Orthogonality answers.
Theorem
11.4.5 (Minimum-Norm Solution)
Let and let be such that is consistent.
Write .
Then:
- (a) exactly one
solution
of lies
in ;
- (b) for every other solution .
We call the
minimum-norm solution.
Idea. The solution set is a coset
, and .
Throwing away the -part of keeps it a solution,
because that part is in the kernel, and lands it in
. Once
there, Pythagoras compares it with every other solution:
the others differ from it by a kernel vector, which is
perpendicular to it and only adds length.
The subspace has a matrix
description that makes computable. For
, where the first step is Definition 11.3.1
together with (Theorem 0.9.3), the
second is Lemma 11.4.1, and
the last uses the choice with positive definiteness. So , and applying once more (Theorem 11.3.2 (b))
gives In words: the minimum-norm solution is the
unique solution that is a combination of the columns of
, that is, of
the conjugated rows of . Section 6 proves the
same statement for linear maps, together with the three
companion identities that make up the four fundamental
subspaces.
Example
(A minimum-norm solution)
Find the solution of smallest norm of
Solution. Here .
Subtracting the first equation from the second gives
, so
and
then . With the solutions are so . By Theorem 11.4.5 the
answer is the unique with :
Hence , with .
Check. It is a solution, since and , and it is orthogonal to the
kernel, since . By the identity above it must also be a combination
of the rows of ,
and it is: , half the second row.
Finally, the solution has , as Theorem 11.4.5 (b)
requires.
The two answers of this section — the least-squares
solution and the minimum-norm solution — are usually
wanted together: given any and , first minimize , then
among the minimizers take the shortest. Chapter 13
packages the combined answer as a single matrix, the
pseudoinverse , with in all
cases at once.
Exercises
A. Check your
understanding
Exercise
(A1)
- (a) Define a
least-squares solution of , and write down
the normal equations.
- (b) True or false:
if is
consistent, then its solutions are exactly its
least-squares solutions. Justify your answer.
- (c) Explain in one
sentence why the normal equations are always
consistent.
- (d) Give a condition
on the columns of equivalent to
uniqueness of the least-squares solution.
- (e) Where does the
minimum-norm solution of a consistent system live, and
why is it unique there?
- (f) True or false:
. Justify your answer.
Solution.
(a) A vector
with
for every . The normal
equations are (Theorem 11.4.2).
(b) True. If
then
, which is the smallest possible value, so
is a
least-squares solution; conversely a least-squares
solution has
, hence . Least squares extends the notion of a
solution without changing it when solutions
exist.
(c) Because the
target lies in
by
construction, so is solvable (Theorem 11.4.2,
existence).
(d) The columns
are linearly independent, equivalently , equivalently
is
invertible (Corollary 11.4.4).
(e) In . Two solutions there would differ
by an element of (Theorem 11.4.5).
(f) False, and
usually meaningless: need not be square, so
need not
exist, while can exist
perfectly well — see the example in the warning after Corollary 11.4.4.
B. Practice
Exercise
(B1: A least-squares line)
Find the least-squares line for the data
. Compute the residual, verify that it is
orthogonal to both columns of , and give the minimum
sum of squares.
Solution. With having columns and and , The normal equations are and . Multiplying
the first by and
the second by and
subtracting gives , so , and then . The line is .
Its values at are , so . Orthogonality: against
the first column and against the second. The minimum sum
of squares is .
Exercise
(B2: A least-squares parabola)
Find the least-squares quadratic for the
data , and the minimum sum of squares.
Hint: write down from the power
sums ,
.
Solution. The power sums are , , , , , so Solving: from the first two equations, and
;
eliminating gives
, so
. The
third equation is . Substituting into gives
, so
; then
becomes , so , ,
. The parabola
is Its values at are , so and the minimum sum of squares
is . Check: , , .
Exercise
(B3: A minimum-norm solution)
Find the minimum-norm solution of and verify that it is orthogonal to .
Solution. With the solutions are
, so . By Theorem 11.4.5 we
need : So , with
. It
solves the system, since
and , and confirms the
orthogonality. For comparison, .
C. Going deeper
Exercise
(C1: Weighted least squares)
Let , , and let be weights, with .
- (a) Show that is an inner product on .
- (b) Prove that the
minimizers of are exactly the
solutions of .
- (c) For the data
with weights , find the weighted least-squares line,
and compare it with the unweighted one.
Solution.
(a) It is
bilinear and symmetric because , and whenever some , because every
. (This
is where positivity of the weights is used; a zero
weight would destroy definiteness.)
(b) Write for the
norm induced by .
The quantity to minimize is exactly .
The proof of Theorem 11.4.2 used
nothing about the inner product except its axioms, so it
applies verbatim with
in place of the standard one: the minimizers are the
for which is -orthogonal
to , that
is, for which for all . Now and this vanishes for all exactly when
, by taking equal to that
vector.
(c) With having columns and , and , so and , giving and : the weighted line is . Unweighted, and ,
giving , , so and : the unweighted line is . The
middle point is trusted twice as much in the weighted
fit, and the line moves down to pass closer to it. The
weighted fit has weighted error ,
smaller than the weighted error of the
unweighted line, while the unweighted fit has plain
error , smaller
than the plain error of the weighted line:
each line wins the contest it was designed for.
Exercise
(C2: The residual, two ways)
Let be a
least-squares solution of and let .
Solution.
- (a) By Theorem 11.4.2,
with
, so
while . The two are
orthogonal, and , so Theorem 11.1.3
gives , which is the first
identity.
For the second, , since by orthogonality.
Expanding the other way, and using Lemma 11.4.1,
- (b) In Example (The least-squares line through four points),
, and , so matching the value found there. Only the data
already assembled for the normal equations is
needed.
Exercise
(C3: A rank-deficient least-squares problem)
Let
- (a) Show that is inconsistent
and that .
- (b) Describe
all least-squares solutions.
- (c) Find the one of
smallest norm, and the minimum sum of squares.
Solution.
(a) The third
column is the sum of the first two, so the columns are
dependent and ; the first two columns are independent, so
and
. A vector
lies in
exactly when ; here , so and the system is
inconsistent.
(b) By Theorem 11.4.2 the
least-squares solutions solve . Here
Row reducing, the third row is the sum of the
first two, and subtracting suitable multiples gives
and
.
Hence a coset of , as Lemma 11.4.3
predicts.
(c) The
minimizers form a coset of , so the argument
of Theorem 11.4.5
applies to it verbatim: the shortest is the one
orthogonal to . From we get and Every minimizer gives the same , with residual and
minimum sum of squares .
Check:
is orthogonal to and to , since and .