Beruflich Dokumente
Kultur Dokumente
Outline
Scientific Computing: An Introductory Survey
Chapter 3 Linear Least Squares
Michael T. Heath
Least Squares Data Fitting
Existence, Uniqueness, and Conditioning
Solving Linear Least Squares Problems
Scientific Computing
1 / 61
Michael T. Heath
Least Squares Data Fitting
Existence, Uniqueness, and Conditioning
Solving Linear Least Squares Problems
Least Squares
Data Fitting
Scientific Computing
2 / 61
Least Squares
Data Fitting
Scientific Computing
3 / 61
Michael T. Heath
Least Squares Data Fitting
Existence, Uniqueness, and Conditioning
Solving Linear Least Squares Problems
Least Squares
Data Fitting
Data Fitting
Scientific Computing
4 / 61
Least Squares
Data Fitting
Data Fitting
Polynomial fitting
m
X
f (t, x) = x1 + x2 t + x3 t2 + + xn tn1
i=1
Michael T. Heath
Least Squares Data Fitting
Existence, Uniqueness, and Conditioning
Solving Linear Least Squares Problems
Scientific Computing
5 / 61
Michael T. Heath
Least Squares Data Fitting
Existence, Uniqueness, and Conditioning
Solving Linear Least Squares Problems
Least Squares
Data Fitting
Scientific Computing
6 / 61
Least Squares
Data Fitting
Example, continued
For data
t 1.0 0.5 0.0 0.5 1.0
y
1.0
0.5 0.0 0.5 2.0
overdetermined 5 3 linear system is
1 1.0 1.0
1.0
1 0.5 0.25 x1
0.5
0.0 0.0
Ax =
1
x2 = 0.0 = b
1
0.5
0.5 0.25 x3
1
1.0 1.0
2.0
1 t1 t21
y1
1 t2 t22 x1
y2
2
Ax =
1 t3 t3 x2 = y3 = b
1 t4 t2 x3
y4
4
1 t5 t25
y5
so approximating polynomial is
p(t) = 0.086 + 0.4t + 1.4t2
Michael T. Heath
Scientific Computing
7 / 61
Michael T. Heath
Scientific Computing
8 / 61
Least Squares
Data Fitting
Example, continued
Scientific Computing
9 / 61
Michael T. Heath
Scientific Computing
Normal Equations
10 / 61
Orthogonality
Vectors v1 and v2 are orthogonal if their inner product is
zero, v1T v2 = 0
= b b 2x A b + x A Ax
2AT Ax 2AT b = 0
which reduces to n n linear system of normal equations
0 = AT r = AT (b Ax)
AT Ax = AT b
Michael T. Heath
Least Squares Data Fitting
Existence, Uniqueness, and Conditioning
Solving Linear Least Squares Problems
Scientific Computing
11 / 61
Michael T. Heath
Scientific Computing
Orthogonality, continued
12 / 61
Orthogonal Projectors
Matrix P is orthogonal projector if it is idempotent
(P 2 = P ) and symmetric (P T = P )
Michael T. Heath
Least Squares Data Fitting
Existence, Uniqueness, and Conditioning
Solving Linear Least Squares Problems
Scientific Computing
13 / 61
Michael T. Heath
kyk2
kAxk2
=
kbk2
kbk2
Michael T. Heath
14 / 61
kA+ k
Scientific Computing
kxk2
1 kbk2
cond(A)
kxk2
cos() kbk2
15 / 61
Michael T. Heath
Scientific Computing
16 / 61
Normal Equations
Orthogonal Methods
SVD
AT A = LLT
kEk2
kxk2
/ [cond(A)]2 tan() + cond(A)
kxk2
kAk2
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
17 / 61
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
square
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
triangular
18 / 61
Example, continued
1 1.0 1.0
1
1
1
1
1
1 0.5 0.25
0.0 0.0
AT A = 1.0 0.5 0.0 0.5 1.0
1
1.0
1
1
1
1
1
4.0
0.5
T
2.236
0
0
2.236
0
1.118
1.581
0 0
1.581
0 = LLT
= 0
1.118
0
0.935
0
0
0.935
Solving lower triangular system Lz = AT b by
T
forward-substitution gives z = 1.789 0.632 1.336
Solving upper triangular system LT x = z by
T
back-substitution gives x = 0.086 0.400 1.429
19 / 61
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
20 / 61
1 1
A = 0
0
where is positive number smaller than
mach
which is singular
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
21 / 61
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
22 / 61
Orthogonal Transformations
We seek alternative method that avoids numerical
difficulties of normal equations
We need numerically robust transformation that produces
easier problem without changing solution
What kind of transformation leaves least squares solution
unchanged?
Michael T. Heath
Least Squares Data Fitting
Existence, Uniqueness, and Conditioning
Solving Linear Least Squares Problems
Scientific Computing
Michael T. Heath
Scientific Computing
24 / 61
Normal Equations
Orthogonal Methods
SVD
Rx = b1
Residual is
krk22 = kb1 Rxk22 + kb2 k22
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
Normal Equations
Orthogonal Methods
SVD
25 / 61
QR Factorization
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
26 / 61
Orthogonal Bases
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
Computing QR Factorization
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
28 / 61
Householder Transformations
Householder transformation has form
H =I 2
vv T
vT v
1
0
0
Ha = . = . = e1
..
..
0
0
Gram-Schmidt orthogonalization
v = a e1
and = kak2 , with sign chosen to avoid cancellation
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
29 / 61
Normal Equations
Orthogonal Methods
SVD
30 / 61
where = kak2 = 3
Since a1 is positive, we
choose
negative
sign for to avoid
2
3
5
cancellation, so v = 1 0 = 1
2
0
2
To confirm that transformation works,
2
5
3
vT a
15
1 =
0
Ha = a 2 T v = 1 2
v v
30
2
2
0
Scientific Computing
Householder QR Factorization
T
If a = 2 1 2 , then we take
2
1
2
v = a e1 = 1 0 = 1 0
2
0
2
0
Michael T. Heath
Michael T. Heath
Least Squares Data Fitting
Existence, Uniqueness, and Conditioning
Solving Linear Least Squares Problems
31 / 61
Michael T. Heath
Scientific Computing
32 / 61
Normal Equations
Orthogonal Methods
SVD
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
33 / 61
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
34 / 61
1.789
2.236
0
1.118
0.362
0
0.191 0.405
0.309 0.655
H1 A =
0
, H1 b = 0.862
0
0.362
0.809 0.405
1.138
0
1.309
0.345
1
2.236
3.236
1 0 1
v1 =
1 0 = 1
1 0 1
1
0
1
Michael T. Heath
Michael T. Heath
Least Squares Data Fitting
Existence, Uniqueness, and Conditioning
Solving Linear Least Squares Problems
Example, continued
1 1.0 1.0
1.0
1 0.5 0.25
0.5
0.0 0.0
A=
1
, b = 0.0
1
0.5
0.5 0.25
2.0
1
1.0 1.0
Normal Equations
Orthogonal Methods
SVD
1 Ais
0
0
0
0.191 1.581 1.772
v2 =
0.309 0 = 0.309
0.809 0 0.809
1.309
0
1.309
35 / 61
Example, continued
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
36 / 61
Example, continued
1.789
2.236
0
1.118
0
1.581
0
0.632
, H2 H1 b = 1.035
0
0
0.725
H2 H1 A =
0.816
0
0
0.589
0.404
0
0
0.047
1.789
2.236
0
1.118
0.632
0
1.581
0
0
0.935
H3 H2 H1 A =
0
, H3 H2 H1 b = 1.336
0
0.026
0
0
0.337
0
0
0
0
0
0
0 0 0
v3 =
0.725 0.935 = 1.660
0.589 0 0.589
0.047
0
0.047
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
37 / 61
Givens Rotations
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
38 / 61
=
s c a2
0
p
with c2 + s2 = 1, or equivalently, = a21 + a22
=
a2 a1 s
0
Finally, c2 + s2 = 1, or =
a1
c= p 2
a1 + a22
=
0 a1 a22 /a1 s
a2 /a1
Michael T. Heath
Scientific Computing
a2
a21 + a22
39 / 61
Michael T. Heath
and
c=
a1
a21 + a22
p
a21 + a22 , implies
and
a2
s= p 2
a1 + a22
Scientific Computing
40 / 61
Normal Equations
Orthogonal Methods
SVD
Givens QR Factorization
T
Let a = 4 3
a1
a1
1
0 0 0 0
0
c 0 s 0
a2
0
0 1 0 0
a3 = a3
0 s 0 c 0 a4 0
a5
a5
0
0 0 0 1
Normal Equations
Orthogonal Methods
SVD
3
a2
= = 0.6
and s = p 2
5
a1 + a22
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
Givens QR Factorization
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
42 / 61
Gram-Schmidt Orthogonalization
Given vectors a1 and a2 , we seek orthonormal vectors q1
and q2 having same span
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
43 / 61
Gram-Schmidt Orthogonalization
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
44 / 61
Modified Gram-Schmidt
for k = 1 to n
qk = ak
for j = 1 to k 1
rjk = qjT ak
qk = qk rjk qj
end
rkk = kqk k2
qk = qk /rkk
end
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
45 / 61
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
46 / 61
Rank Deficiency
for k = 1 to n
rkk = kak k2
qk = ak /rkk
for j = k + 1 to n
rkj = qkT aj
aj = aj rkj qk
end
end
Michael T. Heath
Michael T. Heath
Least Squares Data Fitting
Existence, Uniqueness, and Conditioning
Solving Linear Least Squares Problems
Scientific Computing
47 / 61
Michael T. Heath
Scientific Computing
48 / 61
Normal Equations
Orthogonal Methods
SVD
Consider 3 2 matrix
0.641 0.242
A = 0.321 0.121
0.962 0.363
Computing QR factorization,
1.1997 0.4527
R=
0
0.0002
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
50 / 61
Normal Equations
Orthogonal Methods
SVD
Normal Equations
Orthogonal Methods
SVD
Scientific Computing
Scientific Computing
Michael T. Heath
Michael T. Heath
Least Squares Data Fitting
Existence, Uniqueness, and Conditioning
Solving Linear Least Squares Problems
Normal Equations
Orthogonal Methods
SVD
51 / 61
Example: SVD
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
52 / 61
Applications of SVD
Minimum norm solution to Ax
= b is given by
1 2 3
4 5 6
T
SVD of A =
7 8 9 is given by U V =
10 11 12
x=
X uT b
i
vi
i
i 6=0
.141
.825 .420 .351 25.5
0
0
.504
.574 .644
.344
.426
.298
.782 0
1.29 0
max
min
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
53 / 61
Pseudoinverse
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
54 / 61
Orthogonal Bases
Scientific Computing
Michael T. Heath
Scientific Computing
56 / 61
Normal Equations
Orthogonal Methods
SVD
Normal Equations
Orthogonal Methods
SVD
with Ei = ui viT
Ei has rank 1 and can be stored using only m + n storage
locations
Product Ei x can be computed using only m + n
multiplications
Condensed approximation to A is obtained by omitting
from summation terms corresponding to small singular
values
Approximation using k largest singular values is closest
matrix of rank k to A
Approximation is useful in image processing, data
compression, information retrieval, cryptography, etc.
< interactive example >
Michael T. Heath
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
57 / 61
Comparison of Methods
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
58 / 61
n3 ,
Scientific Computing
Normal Equations
Orthogonal Methods
SVD
Michael T. Heath
Michael T. Heath
Least Squares Data Fitting
Existence, Uniqueness, and Conditioning
Solving Linear Least Squares Problems
Scientific Computing
61 / 61
Michael T. Heath
Scientific Computing
60 / 61