The QR Factorization

Similar documents
AMS526: Numerical Analysis I (Numerical Linear Algebra)

The Singular Value Decomposition

Stability of the Gram-Schmidt process

Applied Mathematics 205. Unit II: Numerical Linear Algebra. Lecturer: Dr. David Knezevic

Math Fall Final Exam

AMS526: Numerical Analysis I (Numerical Linear Algebra)

Math 407: Linear Optimization

4.8 Arnoldi Iteration, Krylov Subspaces and GMRES

AM 205: lecture 8. Last time: Cholesky factorization, QR factorization Today: how to compute the QR factorization, the Singular Value Decomposition

Orthogonal Transformations

Conceptual Questions for Review

MATH 22A: LINEAR ALGEBRA Chapter 4

Math 520 Exam 2 Topic Outline Sections 1 3 (Xiao/Dumas/Liaw) Spring 2008

Least-Squares Systems and The QR factorization

MATH 167: APPLIED LINEAR ALGEBRA Least-Squares

Linear Analysis Lecture 16

Review problems for MA 54, Fall 2004.

Linear least squares problem: Example

Lecture notes: Applied linear algebra Part 1. Version 2

Math 102, Winter Final Exam Review. Chapter 1. Matrices and Gaussian Elimination

Linear Algebra Review. Vectors

STAT 309: MATHEMATICAL COMPUTATIONS I FALL 2018 LECTURE 9

Eigenvalue and Eigenvector Problems

MAT Linear Algebra Collection of sample exams

I. Multiple Choice Questions (Answer any eight)

linearly indepedent eigenvectors as the multiplicity of the root, but in general there may be no more than one. For further discussion, assume matrice

Cheat Sheet for MATH461

5.6. PSEUDOINVERSES 101. A H w.

Krylov Space Methods. Nonstationary sounds good. Radu Trîmbiţaş ( Babeş-Bolyai University) Krylov Space Methods 1 / 17

Matrix Factorization and Analysis

Linear Algebra, part 3 QR and SVD

Linear Algebra Massoud Malek

(a) If A is a 3 by 4 matrix, what does this tell us about its nullspace? Solution: dim N(A) 1, since rank(a) 3. Ax =

Orthonormal Transformations and Least Squares

ENGG5781 Matrix Analysis and Computations Lecture 8: QR Decomposition

Orthonormal Transformations

Pseudoinverse & Moore-Penrose Conditions

Householder reflectors are matrices of the form. P = I 2ww T, where w is a unit vector (a vector of 2-norm unity)

7. Symmetric Matrices and Quadratic Forms

Chapter 3 Transformations

Matrix decompositions

MATH 532: Linear Algebra

Notes on Eigenvalues, Singular Values and QR

Linear Algebra, part 3. Going back to least squares. Mathematical Models, Analysis and Simulation = 0. a T 1 e. a T n e. Anna-Karin Tornberg

Dot product and linear least squares problems

Numerical Linear Algebra Chap. 2: Least Squares Problems

LINEAR ALGEBRA 1, 2012-I PARTIAL EXAM 3 SOLUTIONS TO PRACTICE PROBLEMS

9. Numerical linear algebra background

Solution of Linear Equations

MATH 3511 Lecture 1. Solving Linear Systems 1

EE731 Lecture Notes: Matrix Computations for Signal Processing

5. Orthogonal matrices

AMS526: Numerical Analysis I (Numerical Linear Algebra)

Computational Linear Algebra

Problem 1. CS205 Homework #2 Solutions. Solution

Linear Algebra. Session 12

This can be accomplished by left matrix multiplication as follows: I

Numerical Methods. Elena loli Piccolomini. Civil Engeneering. piccolom. Metodi Numerici M p. 1/??

The Singular Value Decomposition

Diagonalizing Matrices

Linear Algebra Primer

ELE/MCE 503 Linear Algebra Facts Fall 2018

AMS526: Numerical Analysis I (Numerical Linear Algebra for Computational and Data Sciences)

Properties of Matrices and Operations on Matrices

A Brief Outline of Math 355

AMS526: Numerical Analysis I (Numerical Linear Algebra)

Preliminary/Qualifying Exam in Numerical Analysis (Math 502a) Spring 2012

CS 322 Homework 4 Solutions

Problem set 5: SVD, Orthogonal projections, etc.

Image Registration Lecture 2: Vectors and Matrices

The Singular Value Decomposition and Least Squares Problems

18.06 Professor Johnson Quiz 1 October 3, 2007

6. Orthogonality and Least-Squares

Review of some mathematical tools

Lecture 3: QR-Factorization

Orthogonalization and least squares methods

2. Linear algebra. matrices and vectors. linear equations. range and nullspace of matrices. function of vectors, gradient and Hessian

33AH, WINTER 2018: STUDY GUIDE FOR FINAL EXAM

Section 6.4. The Gram Schmidt Process

MATH 240 Spring, Chapter 1: Linear Equations and Matrices

Problem Set (T) If A is an m n matrix, B is an n p matrix and D is a p s matrix, then show

MATH 235: Inner Product Spaces, Assignment 7

Quantum Computing Lecture 2. Review of Linear Algebra

Math 6610 : Analysis of Numerical Methods I. Chee Han Tan

orthogonal relations between vectors and subspaces Then we study some applications in vector spaces and linear systems, including Orthonormal Basis,

Orthogonality. 6.1 Orthogonal Vectors and Subspaces. Chapter 6

P = A(A T A) 1 A T. A Om (m n)

Inverses. Stephen Boyd. EE103 Stanford University. October 28, 2017

Review of similarity transformation and Singular Value Decomposition

9. Numerical linear algebra background

UNIT 6: The singular value decomposition.

Lecture 9: Numerical Linear Algebra Primer (February 11st)

MATH36001 Generalized Inverses and the SVD 2015

1. Let m 1 and n 1 be two natural numbers such that m > n. Which of the following is/are true?

2. LINEAR ALGEBRA. 1. Definitions. 2. Linear least squares problem. 3. QR factorization. 4. Singular value decomposition (SVD) 5.

18.06SC Final Exam Solutions

Lecture 6, Sci. Comp. for DPhil Students

Krylov Subspace Methods that Are Based on the Minimization of the Residual

Numerical Methods I Non-Square and Sparse Linear Systems

YORK UNIVERSITY. Faculty of Science Department of Mathematics and Statistics MATH M Test #2 Solutions

Transcription:

The QR Factorization How to Make Matrices Nicer Radu Trîmbiţaş Babeş-Bolyai University March 11, 2009 Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 1 / 25

Projectors A projector is a square matrix P that satisfies P 2 = P Not necessarily an orthogonal projector (more later) If v range(p) then Pv = v Since v = Px, Pv = P 2 x = Px = v Projection along the line Pv v null(p) Since P(Pv v) = P 2 v Pv = 0 Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 2 / 25

Complementary Projectors The matrix I P is the complementary projector to P I P projects on the nullspace of P: If Pv = 0, then (I P)v = v, so null(p) range(i P) But for any v, (I P)v = v Pv null(p), so range(i P) null(p) Therefore range(i P) = null(p) and null(i P) = range(p) Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 3 / 25

Complementary Subspaces For a projector P, null(i P) null(p) = {0} or range(p) null(p) = {0} A projector separates C m into two spaces S 1, S 2, with range(p) = S 1 and null(p) = S 2 P is the projector onto S 1 along S 2 Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 4 / 25

Orthogonal Projectors An orthogonal projector projects onto S 1 along S 2, with S 1, S 2 orthogonal Theorem A projector P is orthogonal P = P Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 5 / 25

Proof Proof. ( ) If P = P, then the inner product between a vector Px S 1 and a vector (I P)y S 2 is zero: x P (I P)y = x (P P 2 )y = 0. Thus the projector is orthogonal. ( )We shall use SVD. Suppose P projects onto S 1 along S 2, where S 1 S 2 and S 1 has dimension n. Then an SVD of P can be constructed as follows. Let {q 1, q 2,..., q m } be an orthonormal basis for C m, where {q 1,..., q n } is a basis for S 1 and {q n+1,..., q m } is a basis for S 2. For j n, we have Pq j = q j, and for j > n, we have Pq j = 0. Now let Q be the unitary matrix whose jth column is q j. Then we have PQ = q 1... q n 0..., Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 6 / 25

Proof - continued so that Q PQ = 1... 1 0... = Σ, a diagonal matrix with ones in the first n entries and zeros everywhere else. Thus we have constructed a singular value decomposition of P: P = QΣQ. (1) (note that this is also an eigenvalue decomposition.) Since P = (QΣQ ) = QΣ Q = QΣQ, it follows that P is hermitian. Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 7 / 25

Projection with Orthonormal Basis Reduced SVD gives projector for orthonormal columns ˆQ P = ˆQ ˆQ Complement I ˆQ ˆQ also orthogonal, projects onto space orthogonal to range( ˆQ) Special case 1: Rank-1 Orthogonal Projector (gives component in direction q) P q = qq Special case 2: Rank m - 1 Orthogonal Projector (eliminates component in direction q) P q = I qq Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 8 / 25

Projection with Arbitrary Basis Project v to y range(a). Then y v range(a), or a j (y v) = 0, j Set y = Ax: a j (Ax v) = 0, j A (Ax v) = 0 A Ax = A v A A is nonsingular, so x = (A A) 1 A v Finally, we are interested in the projection y = Ax = A(A A) 1 A v giving the orthogonal projector P = A(A A) 1 A Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 9 / 25

The QR Factorization -Main Idea Find orthonormal vectors that span the successive spaces spanned by the columns of A: This means that (for full rank A), a 1 a 1, a 2 a 1, a 2, a 3... q 1, q 2,..., q j = a 1, a 2,..., a j, for j = 1;... ; n Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 10 / 25

The QR Factorization -Matrix Form In matrix form, q 1, q 2,..., q j = a 1, a 2,..., a j becomes a 1 a 2... a n = q 1 q 2... q n or A = ˆQ ˆR This is the reduced QR factorization of A r 11 r 12... r 1n r 22... r 2n.... r nn Add orthogonal extension to ˆQ and add rows to ˆR to obtain the full QR factorization Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 11 / 25

Figure: Full and reduced QR factorization Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 12 / 25

Full and Reduced QR Factorization Let A be an m n matrix. The full QR factorization of A is the factorization A = QR, where Q is m m unitary and R is m n upper-triangular A more compact representation is the reduced QR factorization A = ˆQ ˆR, where (for m n) Q is m n and R is n n Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 13 / 25

Gram-Schmidt Orthogonalization Find new q j orthogonal to q 1,..., q j 1 by subtracting components along previous vectors v j = a j (q 1a j )q 1 (q 2a j )q 2 (q j 1a j )q j 1 Normalize to get q j = v j / v j We then obtain a reduced QR factorization A = ˆQ ˆR, with r ij = q i a j, (i = j) and rjj = a j j 1 i=1 r ij q i 2 Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 14 / 25

Classical Gram-Schmidt Straight-forward application of Gram-Schmidt orthogonalization Numerically unstable Algorithm: Classical Gram-Schmidt for j := 1 to n do v j := a j ; for i := 1 to j 1 do r ij := q i a j; v j := v j r ij q i ; r jj := v j 2 ; q j := v j /r jj ; Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 15 / 25

Existence and Uniqueness Every A C m n (m n) has a full QR factorization and a reduced QR factorization Proof. For full rank A, Gram-Schmidt proves existence of A = ˆQ ˆR. Otherwise, when v j = 0 choose arbitrary vector orthogonal to previous q i. For full QR, add orthogonal extension to Q and zero rows to R. Each A C m n (m n) of full rank has unique A = ˆQ ˆR with r jj > 0. Proof. Again Gram-Schmidt, r jj > 0 determines the sign. Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 16 / 25

Gram-Schmidt Projections The orthogonal vectors produced by Gram-Schmidt can be written in terms of projectors where q 1 = P 1a 1 P 1 a 1, q 2 = P 2a 2 P 2 a 2,..., q n = P na n P n a n P j = I ˆQ j 1 ˆQ j 1 with ˆQ j 1 = q 1 q 2 q j 1 Pj projects orthogonally onto the space orthogonal to q 1,..., q j 1, and rank(pj) = m (j 1) Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 17 / 25

The Modified Gram-Schmidt Algorithm The projection Pj can equivalently be written as P j = P qj 1... P q2 P q1 where P q = I qq P q projects orthogonally onto the space orthogonal to q, and rank(p q ) = m 1 The Classical Gram-Schmidt algorithm computes an orthogonal vector by v j = P j a j while the Modified Gram-Schmidt algorithm uses v j = P qj 1... P q2 P q1 a j Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 18 / 25

Classical vs. Modified Gram-Schmidt Small modification of classical G-S gives modified G-S (but see next slide) Modified G-S is numerically stable (less sensitive to rounding errors) Classical/Modified Gram-Schmidt for j := 1 to n do v j := a j ; for i := 1 to j 1 do r ij := qi a j; (CGS) r ij := qi v j; (MGS) v j := v j r ij q i ; r jj := v j 2 ; q j := v j /r jj ; Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 19 / 25

Implementation of Modified Gram-Schmidt In modified G-S, P qi can be applied to all v j as soon as q i is known Makes the inner loop iterations independent (like in classical G-S) CGS for j := 1 to n do v j := a j ; for i := 1 to j 1 do r ij := q i a j; v j := v j r ij q i ; r j j := v j 2 ; q j := v j /r jj ; MGS for i = 1 to n do v i := a i ; for i := 1 to n do r ii := v i 2 ; q j := v j /r jj ; for j := i + 1 to n do r ij := q i v j; v j := v j r ij q i ; Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 20 / 25

Operation Count Count number of floating points operations flops in an algorithm Each +, -, *, /, or counts as one flop No distinction between real and complex No consideration of memory accesses or other performance aspects Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 21 / 25

Operation Count -Modified G-S Example: Count all +, -, *, / in the Modified Gram-Schmidt algorithm (not just the leading term) 1 for i := 1 to n 2 v i := a i 3 for i := 1 to n 4 r ii := v i m *, m 1 + 5 q i := v i /r ii m / 6 for j := i + 1 to n 7 r ij := q i v j m *, m 1 + 8 v j := v j r ij q i m *, m - Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 22 / 25

Operation Count -Modified G-S The total for each operation is ( #+ = # = # = n i=1 m 1 + n j=i+1 (m 1) ) n(n 1)(m 1) = n(m 1) + 2 n i=1 n i=1 n j=i+1 ( m + m = n j=i+1 = n(m 1) + n i=1 = 1 n(n + 1)(m 1) 2 n m(n i) = 1 mn(n 1) i=1 2 ) 2m 2mn(n 1) = mn + 2 n #/ = m = mn i=1 = mn + = mn 2 n i=1 2m(n i) = (m 1)(n i) = Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 23 / 25

Operation Count -Modified G-S and the total flop count is 1 2 n(n + 1)(m 1) + 1 2 mn(n 1) + mn2 + mn = 2mn 2 + mn 1 2 n2 1 2 n 2mn2 The symbol indicates asymptotic value as m, n (leading term) Easier to find just the leading term: Most work done in lines (7) and (8), with 4m flops per iteration Including the loops, the total becomes n n n n 4m = 4m (n i) 4m i = 2mn 2 i=1 j=i+1 i=1 i=1 Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 24 / 25

Figure: Jórgen Pedersen Gram (1850-1916) Figure: Erhart Schmidt (1876-1959) Radu Trîmbiţaş ( Babeş-Bolyai University) The QR Factorization March 11, 2009 25 / 25