Docsity

Least Squares Problems - Lecture Notes | CS 51500, Study notes of Linear Algebra

Partial preview of the text

Download Least Squares Problems - Lecture Notes | CS 51500 and more Study notes Linear Algebra in PDF only on Docsity!

Chapter 3

LEAST SQUARES PROBLEMS

the sea

E

F

C

D

B

A

One application is geodesy & surveying. Let z = elevation, and suppose we have the mea-

surements:

zA ≈ 1 .,

zB ≈ 2 .,

zC ≈ 3 .,

zB − zA ≈ 1 .,

zC − zB ≈ 2 .,

zC − zA ≈ 1.

This is overdetermined and inconsistent:

        1 0 0

0 1 0

zA

zB

zC

Another application is fitting a curve to given data:

x

y

y=ax+b

x 1 1

x 2 1

. . .

xn 1

[

a

b

]

y 1

y 2

. . .

yn

More generally Am×nxn ≈ bm where A is known exactly, m ≥ n, and b is subject to inde-

pendent random errors of equal variance (which can be achieved by scaling the equations).

Gauss (1821) proved that the “best” solution x

minimizes ‖b − Ax‖ 2 ,

i.e., the sum of the squares of the residual components. Hence, we might write Ax ≈ 2 b.

Even if the 2-norm is inappropriate, it is the easiest to work with.

3.1 The Normal Equations

3.2 QR Factorization

3.3 Householder Reflections

3.4 Givens Rotations

3.5 Gram-Schmidt Orthogonalization

3.6 Singular Value Decomposition

analytical argument

Let rank(A) = n. Therefore A

T A is nonsingular. Let x satisfy A

T r = 0 where r = b − Ax.

Then for any other value x + w

‖b − A(x + w)‖

2 2 =^ ‖r^ −^ Aw‖

2 2 =^ r

T r − 2 w

T A

T r + w

T A

T Aw

= ‖b − Ax‖

2 2 +^ ‖Aw‖

2

Hence, a solution of the normal equations is a solution of the least squares problem. The

solution x is a unique minimum if rank(A) = n because then ‖w‖

2 = 0 ⇒ w = 0.

r−Aw

Aw

r

R(A)

Ax

b

the pseudo-inverse

Assume rank(A) = n. Then

x = (A

T A)

− 1 A

T b.

We call (A

T A)

− 1 A

T = A

† the pseudo-inverse and we write

x = A

† b.

(The definition can be extended to the case rank(A) < n.) For a column vector v the pseudo-

inverse v

† = v

T /‖v‖

2 2.^ The product^ A

† A = In×n:

What about AA

† ? This is an orthogonal projector.

orthogonal projector

The product

vv

T

vTv

= vv

† produces an orthogonal projection of a vector onto span{v} because

  1. vv

† x ∈ span{v},

  1. x − vv

† x⊥ span {v}.

Alternatively,

vv

T

vTv

x is the closest vector to x that is some multiple of v.

T

T

x vv

vv

v

x

Similarly

AA

† = A(A

T A)

− 1 A

T , rank (A) = n ≤ m,

produces an orthogonal projection onto R(A), because AA

† b ∈ R(A) (since AA

† b = A(A

† b)).

For any b

b − AA

† b⊥R(A)

since A

T (b − AA

† b) = 0.

DEFN A matrix P is an orthogonal projector if for any x

x − P x⊥R(P )

⇔ ∀x (x − P x)

T P = 0

⇔ P

T P = P

P

T = P P

2 = P

symmetry idempotence

If S is a subspace of R

n , then its orthogonal complement S

⊥ := {x|x

T y = 0 for all y ∈ S}.)

Every v ∈ R

n has a unique decomposition v = x + y, x ∈ S, y ∈ S

⊥ .

solving the normal equations

The direct approach to solving (A

T A)x = A

T b is to

  1. form A

T A,

  1. What are the normal equations for a linear least squares problem Ax ≈ b?
  2. Express the linear least squares problem Ax ≈ b as a system of m + n equations in

m + n unknowns where m and n are the dimensions of A.

  1. If x satisfies the normal equations, show that no other vector can be a better solution

to the least squares problem.

  1. If y

′ is the orthogonal projection of y onto a subspace S, what two conditions does y

′

satisfy?

  1. What does

vv

T

vTv

do?

  1. Give a formula for the orthogonal projector onto a subspace S in terms of a basis a 1 ,

a 2 ,... , an for S.

  1. What two simple conditions must a matrix P satisfy for it to be an orthogonal projec-

tor?

  1. What is an oblique projector?
  2. What does idempotent mean?
  3. Why is the explicit use of the normal equations undesirable computationally?
  4. If we do use the normal equations, what method is used for the matrix factorization?

Exercises

  1. What can you say about a nonsingular orthogonal projector?
  2. (a) What is the orthogonal complement of R(A) where

A =

(b) What is the projector onto the orthogonal complement of R(A)?

(c) What is the projector onto R(A)?

  1. Construct the orthogonal projector onto the plane through (0,0,0), (1,1,0), (1,0,1).
  2. Assuming u and v are nonzero column vectors, show that I + uv

T is orthogonal only

if u = − 2 v/(v

T v).

  1. Assume that A ∈ R

m×n has linearly independent columns. Hence A

T A has a (unique)

Cholesky factorization. Prove that there exists a factorization A = Q 1 R 1 where Q 1 ∈

R

m×n has columns forming an orthonormal set and R 1 ∈ R

n×n is an upper triangular

matrix. What is the solution of the least squares problem Ax ≈ b in terms of Q 1 , R 1 ,

and b?

  1. Let x

∗ be a least squares solution to an overdetermined system Ax ≈ b. What is the

geometric interpretation of Ax

∗ ? When is Ax

∗ unique? When is x

∗ unique?

  1. Show that an upper triangular orthogonal matrix is diagonal. What are the diagonal

elements?

  1. Suppose that the matrix [ A B

0 C

]

is orthogonal where A and C are square submatrices. Prove in a logical, deductive

fashion that B = 0. (Hint: there is no need to have a formula for the inverse of a 2 × 2

block upper triangular matrix, and there is no need to consider individual elements,

columns, or rows or A, B, or C.)

  1. Show that ‖Qx‖ 2 = ‖x‖ 2 if Q is orthogonal.
  2. Show that if Q is an m by m orthogonal matrix and A is an m by n matrix, then

‖QA‖ 2 = ‖A‖ 2.

  1. Assume (^) [

Qˆ q

T ρ

]

is an orthogonal matrix where Qˆ is square and ρ is a scalar. What can we say about

Qˆ, q, and ρ? (The answer should be simplified.)

  1. (a) What is the orthogonal projector for span{v 1 , v 2 } where v 1 , v 2 are linearly inde-

pendent real vectors?

(b) How does this simplify if v 2 is orthogonal to v 1? In pariticular, what is the usual

way of expressing an orthogonal projector in this case?

3.2 QR Factorization

The least squares problem min x

‖b − Ax‖ 2 is simplified if A is reduced to upper triangular

form by means of orthogonal transformations:

Q

T A = R right triangular

  1. Assume that A ∈ R

m×n has linearly independent columns. Hence A

T A has a (unique)

Cholesky factorization. Prove that there exists a factorization A = Q 1 R 1 where Q 1 ∈

R

m×n has columns forming an orthonormal set and R 1 ∈ R

n×n is an upper triangular

matrix. What is the solution of the least squares problem Ax ≈ b in terms of Q 1 , R 1 ,

and b?

3.3 Householder Reflections

Definition (Householder) An elementary matrix has the form

I + rank one matrix.

It is easy to show that an elementary matrix has the form

I + uv

T , u 6 = 0, v 6 = 0.

An example of an elementary matrix is a Gauss transformation Mk = I − mke

T k. An elemen-

tary matrix is efficient computationally; it is easy to invert. It is not difficult to show that

an orthogonal elementary matrix has the form

I − 2

vv

T

v

T v

=: P.

P is symmetric and P

2 = I. Exercise. Prove this.

Recall that

vv

T

v

T v

x is the orthogonal projection of x onto v.

T

T

x

vv

vv

x

v

What does P = I − 2

vv

T

v

T v

do?

hyperplane

orthogonal to v

T

T

T

T

x−2 x

vv

vv

x

vv

vv

It reflects in the hyperplane through the origin orthogonal to v. (How should one store P?

How should one multiply by P ?) In sum

T

T

(Householder) reflection

vv

vv

P=I−

x

Px

v

Note that the length of v is irrelevant—only its direction matters.

In practice we want to determine v so that for some given x

P x =

α

0

.. .

for some α ∈ R.

reduction to triangular form

As in Gaussian elimination, we reduce A column by column.

Recursive description. The case m ≥ n = 1 is an exercise. Consider the case m ≥ n ≥ 2.

Determine orthogonal P such that

P A =

[

α a

T

0 A˜

]

P is to be constructed in the next section. Then

A = P

[

α a

T

0 A˜

]

and recursion gives A˜ = Q˜ R˜ so that

A = QR where Q = P

[

T

0 Q˜

]

and R =

[

α a

T

0 R˜

]

Nonrecursive description. First, determine orthogonal P 1 such that

P 1 A =

× × × ×

A˜

1

Similarly,

P˜

2

A˜

× × ×

0 A˜ 2

, P˜ 3 A˜ 2 =

× ×

0 A˜ 3

, P˜ 4 A˜ 3 =

×

Then         1

1

P˜

4

P 4

P˜

3

P 3

[

P˜

2

]

P 2

P 1 A =

× × × ×

0 × × ×

0 0 × ×

0 0 0 ×

R

Thus P 4 P 3 P 2 P 1 = Q

T , but we do not need to form this product. Rather we compute

Q

T b = P 4 (P 3 (P 2 (P 1 b))).

Note. If m = n, then n − 1 reductions suffice.

Householder orthogonalization At beginning of the k

th stage

r k−1,n

2n

r1n

k−

k−1,k−

22

11 12

k

k

A

r

r

r

r r

We want to find P˜k = I − βk v˜k v˜

T k such that

P˜

k

A˜

k− 1 =

rkk rkk+1 · · · rkn

. A˜k

the algorithm

Householder orthogonalization

for k = 1, 2,... , n do {

determine a Householder reflection P˜k = I − βk ˜vk v˜

T k such that

P˜

k

akk

ak+1,k

. . .

amk

rkk

0

. . .

0

for j = k + 1, k + 2,... , n do

rkj

ak+1,j

. . .

amj

= P˜k

akj

ak+1,j

. . .

amj

Determine the least squares solution of Ax ≈ b where

b =

[

]T

Do an efficient computation and show every step.

  1. Determine a reflection P = I − 2 v(v

T v)

− 1 v

T such that P x is a multiple of y where

x 6 = 0 and y 6 = 0. Of the two possibilities, which uses for v the sum of two vectors

separated by an angle of at most π/2.

  1. Prove or disprove: a Householder reflection is positive definite.
  2. Write an algorithm for overwriting b with Pn · · · P 2 P 1 b where Pk = I − βkvkv

T k and^ vk

= [ 0 · · · 0 vkk · · ·^ vmk ]

T

. Only the following array values should be referenced

by your algorithm

bi, 1 ≤ i ≤ m,

vik, k ≤ i ≤ m, 1 ≤ k ≤ n,

βk, 1 ≤ k ≤ n.

  1. Let

A =

Determine β 1 , β 2 , v 1 , v 2 and right triangular matrix R such that P 2 P 1 A = R where

Pi = I − βiviv

T i. (As a check confirm that^ A^ =^ P^1 P^2 R.)

  1. Assuming u and v are nonzero column vectors, show that I + uv

T is orthogonal only

if u = − 2 v/(v

T v).

  1. Count the number of multiplications for the Householder orthogonalization algorithm

as described in this section.

  1. Recall that for a Householder reflection P = I − 2

vv

T

v

T v

the vector P x is the mirror

reflection of a vector x in the hyperplane through the origin normal to v. Let x and

y be linearly independent vectors of equal Euclidean length. By means of a pictorial

argument determine a formula for v such that P x = y.

  1. Apply Householder orthogonalization to compute the QR decomposition of the matrix

Normalize the Householder vectors vk so that their first (nonzero) element is 1, as does

LAPACK, and calculate βk values. (Do not actually form the matrices Pk or worse yet

the matrix Qk.).

  1. The application of a Householder reduction to an m by n matrix A, n < m,

Pn · · · P 2 P 1 A = R

yields an upper triangular matrix R. This can be used to create a reduced QR factor-

ization A = Qˆ Rˆ where Qˆ is m by n and Rˆ is a square upper triangular matrix. What

is Rˆ in terms of P 1 , P 2 ,... , Pn, R? What is Qˆ in terms of P 1 , P 2 ,... , Pn, R?

  1. Given on the graph below is a vector x:

| | / x | / | / | / | / | / | / | / |/ ---------------------------------------+--------------------------------------- | | | | | | | | | | |

Construct the vector x

′ def = −sign(x 1 )‖x‖ 2 e 1 on this graph. Also construct on the graph

a vector v in terms of x and x

′ such that P x = x

′ where P = I − 2

vv

T

vTv

  1. Simplify ‖a − ‖a‖ 2 e 1 ‖

2 2 where^ a, e^1 ∈^ R

n and e

T 1 = [1,^0 ,... ,^ 0].

Exercises

  1. Apply the first 2 (out of 5) Givens rotations in the QR decomposition of the matrix

  1. Calculate a Givens rotation that zeros out the (4, 1) entry of

without

changing the 1st and 3rd rows.

3.5 Gram-Schmidt Orthogonalization

Recall that if P is an orthogonal projector for a subspace S, then y − P y⊥S.

The classical Gram-Schmidt process produces an orthonormal set q 1 , q 2 ,... , qn from a

linearly independent set a 1 , a 2 ,... , an, and, in particular, q 1 , q 2 ,... , qk are formed from a 1 ,

a 2 ,... , ak, k = 1, 2 ,... , n:

a

v

q 1

2

2

q 1 = a 1 /‖a 1 ‖ 2 ,

v 2 = a 2 − q 1 q

T 1 a^2 ,

q 2 = v 2 /‖v 2 ‖ 2 ,

3

3

2

1

v

a

q

q

v 3 = a 3 − q 1 q

T 1 a^3 −^ q^2 q

T 2 a^3 ,

q 3 = v 3 /‖v 3 ‖ 2.

More generally,

vj = aj −

j− 1 ∑

k=

qkq

T k aj^ ,

qj = vj /‖vj ‖ 2.

Gram-Schmidt orthogonalization computes a reduced QR factorization:

aj =

j− 1 ∑

k=

qk (q

T k aj^ ) ︸ ︷︷ ︸ rkj

  • ‖vj ‖ 2 ︸ ︷︷ ︸ rjj

qj

j ∑

k=

qkrkj ,

so

[

a 1 a 2 · · · an

]

[

q 1 q 2 · · · qn

]

r 11 r 12 · · · r 1 n

r 22 · · · r 2 n

.. .

rnn

or

A = Qˆ R,ˆ Rˆ =

‖v 1 ‖ 2 q

T 1 a^2 q

T 1 a^3 · · ·

‖v 2 ‖ 2 q

T 2 a^3 · · ·

‖v 3 ‖ 2 · · ·

.. .

This is a reduced QR factorization.

The algorithm is

for k = 1, 2,... , n do {

vk = ak;

for j = 1, 2,... , k − 1 do {

rjk = q

T j ak;

vk = vk − qj rjk;

rkk = ‖vk‖ 2 ;

qk = vk/rkk;

}