lecture 2 and 3: algorithms for linear algebra

Similar documents
lecture 3 and 4: algorithms for linear algebra

Linear Algebra Section 2.6 : LU Decomposition Section 2.7 : Permutations and transposes Wednesday, February 13th Math 301 Week #4

Solution of Linear Equations

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

Numerical Methods I Solving Square Linear Systems: GEM and LU factorization

Matrix decompositions

Matrix decompositions

LINEAR ALGEBRA: NUMERICAL METHODS. Version: August 12,

Linear Algebraic Equations

Numerical Linear Algebra

Scientific Computing: Dense Linear Systems

Numerical Methods - Numerical Linear Algebra

Cheat Sheet for MATH461

Today s class. Linear Algebraic Equations LU Decomposition. Numerical Methods, Fall 2011 Lecture 8. Prof. Jinbo Bi CSE, UConn

3 QR factorization revisited

Linear Analysis Lecture 16

LU Factorization. LU factorization is the most common way of solving linear systems! Ax = b LUx = b

Scientific Computing

Matrix decompositions

Conceptual Questions for Review

Linear Equations and Matrix

Linear Algebra Linear Algebra : Matrix decompositions Monday, February 11th Math 365 Week #4

Introduction to Mathematical Programming

1 GSW Sets of Systems

COURSE Numerical methods for solving linear systems. Practical solving of many problems eventually leads to solving linear systems.

Numerical Linear Algebra

Program Lecture 2. Numerical Linear Algebra. Gaussian elimination (2) Gaussian elimination. Decompositions, numerical aspects

Linear Algebra in Actuarial Science: Slides to the lecture

Numerical Linear Algebra

Y = ax + b. Numerical Applications Least-squares. Start with Self-test 10-1/459. Linear equation. Error function: E = D 2 = (Y - (ax+b)) 2

AMS526: Numerical Analysis I (Numerical Linear Algebra)

forms Christopher Engström November 14, 2014 MAA704: Matrix factorization and canonical forms Matrix properties Matrix factorization Canonical forms

Linear Algebra, part 3 QR and SVD

Important Matrix Factorizations

Computational Methods. Systems of Linear Equations

Direct Methods for Solving Linear Systems. Simon Fraser University Surrey Campus MACM 316 Spring 2005 Instructor: Ha Le

Linear Algebra. Solving Linear Systems. Copyright 2005, W.R. Winfrey

Scientific Computing: Solving Linear Systems

Solving Ax = b w/ different b s: LU-Factorization

Orthogonal Transformations

Lecture 9. Errors in solving Linear Systems. J. Chaudhry (Zeb) Department of Mathematics and Statistics University of New Mexico

LU Factorization. Marco Chiarandini. DM559 Linear and Integer Programming. Department of Mathematics & Computer Science University of Southern Denmark

1.5 Gaussian Elimination With Partial Pivoting.

Elementary Linear Algebra

Matrix Algebra for Engineers Jeffrey R. Chasnov

Linear Algebra Review

STAT 309: MATHEMATICAL COMPUTATIONS I FALL 2018 LECTURE 13

MAA507, Power method, QR-method and sparse matrix representation.

Matrix notation. A nm : n m : size of the matrix. m : no of columns, n: no of rows. Row matrix n=1 [b 1, b 2, b 3,. b m ] Column matrix m=1

MIDTERM. b) [2 points] Compute the LU Decomposition A = LU or explain why one does not exist.

STAT 309: MATHEMATICAL COMPUTATIONS I FALL 2018 LECTURE 9

Applied Linear Algebra in Geoscience Using MATLAB

1.Chapter Objectives

1 Last time: least-squares problems

L2-7 Some very stylish matrix decompositions for solving Ax = b 10 Oct 2015

AMS 147 Computational Methods and Applications Lecture 17 Copyright by Hongyun Wang, UCSC

MODEL ANSWERS TO THE THIRD HOMEWORK

Main matrix factorizations

Review of matrices. Let m, n IN. A rectangle of numbers written like A =

Example Linear Algebra Competency Test

Computational Linear Algebra

A Review of Linear Algebra

Next topics: Solving systems of linear equations

Chapter 2. Solving Systems of Equations. 2.1 Gaussian elimination

Lecture 11. Linear systems: Cholesky method. Eigensystems: Terminology. Jacobi transformations QR transformation

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

MAT 343 Laboratory 3 The LU factorization

Applied Linear Algebra in Geoscience Using MATLAB

30.3. LU Decomposition. Introduction. Prerequisites. Learning Outcomes

Outline. Math Numerical Analysis. Errors. Lecture Notes Linear Algebra: Part B. Joseph M. Mahaffy,

COMP 558 lecture 18 Nov. 15, 2010

MATHEMATICS FOR COMPUTER VISION WEEK 2 LINEAR SYSTEMS. Dr Fabio Cuzzolin MSc in Computer Vision Oxford Brookes University Year

Math Computation Test 1 September 26 th, 2016 Debate: Computation vs. Theory Whatever wins, it ll be Huuuge!

MATH 304 Linear Algebra Lecture 20: The Gram-Schmidt process (continued). Eigenvalues and eigenvectors.

(Mathematical Operations with Arrays) Applied Linear Algebra in Geoscience Using MATLAB

MIT Final Exam Solutions, Spring 2017

Engineering Computation

Numerical methods, midterm test I (2018/19 autumn, group A) Solutions

CS227-Scientific Computing. Lecture 4: A Crash Course in Linear Algebra

Linear algebra for MATH2601 Numerical methods

Systems of Linear Equations

There are six more problems on the next two pages

SUMMARY OF MATH 1600

MATLAB Project: LU Factorization

GAUSSIAN ELIMINATION AND LU DECOMPOSITION (SUPPLEMENT FOR MA511)

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

Total 170. Name. Final Examination M340L-CS

1 Number Systems and Errors 1

Lecture 4: Applications of Orthogonality: QR Decompositions

LINEAR SYSTEMS (11) Intensive Computation

Algebra C Numerical Linear Algebra Sample Exam Problems

Linear Algebra Primer

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

EXAM. Exam 1. Math 5316, Fall December 2, 2012

22A-2 SUMMER 2014 LECTURE 5

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

Section 6.4. The Gram Schmidt Process

Roundoff Analysis of Gaussian Elimination

Since the determinant of a diagonal matrix is the product of its diagonal elements it is trivial to see that det(a) = α 2. = max. A 1 x.

y b where U. matrix inverse A 1 ( L. 1 U 1. L 1 U 13 U 23 U 33 U 13 2 U 12 1

Transcription:

lecture 2 and 3: algorithms for linear algebra STAT 545: Introduction to computational statistics Vinayak Rao Department of Statistics, Purdue University August 27, 2018

Solving a system of linear equations Preliminaries: cost of standard matrix algebra operations 1/23

Solving a system of linear equations Preliminaries: cost of standard matrix algebra operations Consider AX = b, where A is N N, and X and b are N k. Solve for X: X = A 1 b 1/23

Solving a system of linear equations Preliminaries: cost of standard matrix algebra operations Consider AX = b, where A is N N, and X and b are N k. Solve for X: X = A 1 b Calculate the inverse of A and multiply? No! 1/23

Solving a system of linear equations Preliminaries: cost of standard matrix algebra operations Consider AX = b, where A is N N, and X and b are N k. Solve for X: X = A 1 b Calculate the inverse of A and multiply? No! Directly solving for X is faster, and more stable numerically A 1 need not even exist 1/23

Gauss-Jordan elimination A X = b A [ X, A 1 ] = [ b, I ] 2/23

Gauss-Jordan elimination A X = b A [ X, A 1 ] = [ b, I ] 1 0 1 x 1 v 11 v 12 v 13 4 1 0 0 2 0 1 x 2 v 21 v 22 v 23 = 10 0 1 0 1 2 1 x 3 v 31 v 32 v 33 3 0 0 1 2/23

Gauss-Jordan elimination A X = b A [ X, A 1 ] = [ b, I ] 1 0 1 x 1 v 11 v 12 v 13 4 1 0 0 2 0 1 x 2 v 21 v 22 v 23 = 10 0 1 0 1 2 1 x 3 v 31 v 32 v 33 3 0 0 1 Manipulate to get: I [ X, A 1 ] = [ ĉ 1, Ĉ 2 ] 2/23

Gauss-Jordan elimination A X = b A [ X, A 1 ] = [ b, I ] 1 0 1 x 1 v 11 v 12 v 13 4 1 0 0 2 0 1 x 2 v 21 v 22 v 23 = 10 0 1 0 1 2 1 x 3 v 31 v 32 v 33 3 0 0 1 Manipulate to get: I [ X, A 1 ] = [ ĉ 1, Ĉ 2 ] At step i: Make element a ii = 1 (by scaling or pivoting) Set other elements in column i to 0 by multiplying and subtracting that row 2/23

Gauss-Jordan elimination 1 0 1 x 1 v 11 v 12 v 13 4 1 0 0 2 0 1 x 2 v 21 v 22 v 23 = 10 0 1 0 1 2 1 x 3 v 31 v 32 v 33 3 0 0 1 3/23

Gauss-Jordan elimination 1 0 1 x 1 v 11 v 12 v 13 4 1 0 0 2 0 1 x 2 v 21 v 22 v 23 = 10 0 1 0 1 2 1 x 3 v 31 v 32 v 33 3 0 0 1 Multiply row 1 by 2 and subtract 3/23

Gauss-Jordan elimination 1 0 1 x 1 v 11 v 12 v 13 4 1 0 0 0 0 1 x 2 v 21 v 22 v 23 = 2 2 1 0 1 2 1 x 3 v 31 v 32 v 33 3 0 0 1 3/23

Gauss-Jordan elimination 1 0 1 x 1 v 11 v 12 v 13 4 1 0 0 0 0 1 x 2 v 21 v 22 v 23 = 2 2 1 0 0 2 2 x 3 v 31 v 32 v 33 1 1 0 1 Subtract row 1 3/23

Gauss-Jordan elimination 1 0 1 x 1 v 11 v 12 v 13 4 1 0 0 0 2 2 x 2 v 21 v 22 v 23 = 1 1 0 1 0 0 1 x 3 v 31 v 32 v 33 2 2 1 0 Pivot 3/23

Gauss-Jordan elimination 1 0 0 x 1 v 11 v 12 v 13 6 1 1 0 0 1 0 x 2 v 21 v 22 v 23 = 2.5 1.5 1 0.5 0 0 1 x 3 v 31 v 32 v 33 2 2 1 0 Continue till we get an identity matrix 3/23

Gauss-Jordan elimination 1 0 0 x 1 v 11 v 12 v 13 6 1 1 0 0 1 0 x 2 v 21 v 22 v 23 = 2.5 1.5 1 0.5 0 0 1 x 3 v 31 v 32 v 33 2 2 1 0 What is the cost of this algorithm? 3/23

Gauss elimination with back-substitution A [ X, A 1 ] = [ b, I ] 4/23

Gauss elimination with back-substitution A [ X, A 1 ] = [ b, I ] O(N 3 ) manipulation to get: U [ X, A 1 ] = [ ĉ 1, Ĉ 2 ] Here, U is an upper-triangular matrix. 4/23

Gauss elimination with back-substitution A [ X, A 1 ] = [ b, I ] O(N 3 ) manipulation to get: U [ X, A 1 ] = [ ĉ 1, Ĉ 2 ] Here, U is an upper-triangular matrix. Cannot just read off solution. Need to backsolve. 4/23

LU decomposition What are we actually doing? A = LU Here L and U are lower and upper triangular matrices. 1 0 0 u 11 u 12 u 13 L = l 21 1 0, U = 0 u 22 u 23 l 31 l 32 1 0 0 u 33 5/23

LU decomposition What are we actually doing? A = LU Here L and U are lower and upper triangular matrices. Is this always possible? 1 0 0 u 11 u 12 u 13 L = l 21 1 0, U = 0 u 22 u 23 l 31 l 32 1 0 0 u 33 [ ] 0 1 A = 1 0 5/23

LU decomposition What are we actually doing? A = LU Here L and U are lower and upper triangular matrices. Is this always possible? 1 0 0 u 11 u 12 u 13 L = l 21 1 0, U = 0 u 22 u 23 l 31 l 32 1 0 0 u 33 [ ] 0 1 A = 1 0 PA = LU, P is a permutation matrix Crout s algorithm, O(N 3 ), stable, L, U can be computed in place. 5/23

Backsubstitution AX = b 6/23

Backsubstitution AX = b LUX = Pb First solve Y by forward substitution LY = Pb 6/23

Backsubstitution AX = b LUX = Pb First solve Y by forward substitution LY = Pb 1 0 0 l 21 1 0 l 31 l 32 1 y 1 y 2 y 3 ˆb 1 = ˆb 2 ˆb 3 6/23

Backsubstitution AX = b LUX = Pb First solve Y by forward substitution LY = Pb 1 0 0 l 21 1 0 l 31 l 32 1 y 1 y 2 y 3 ˆb 1 = ˆb 2 ˆb 3 Then solve X by back substitution UX = Y 6/23

Comments LU-decomposition can be reused for different b s. Calculating LU decomposition: O(N 3 ). Given LU decomposition, solving for X: O(N 2 ). A = P 1 LU = ( 1) S N i=1 u ii (S: num. of exchanges) LUA 1 = PI, can solve for A 1. (back to Gauss-Jordan) 7/23

Cholesky decomposition If A is symmetric positive-definite: A = LL T (but now L need not have a diagonal of ones) Square-root of A More stable. Twice as efficient. Related: A = LDL T (but now L has a unit diagonal). 8/23

Eigenvalue decomposition An N N matrix A: a map from R N R N. An eigenvector v undergoes no rotation: Av = λv λ is the corresponding eigenvalue, and gives the rescaling. 9/23

Eigenvalue decomposition An N N matrix A: a map from R N R N. An eigenvector v undergoes no rotation: Av = λv λ is the corresponding eigenvalue, and gives the rescaling. Let Λ = diag(λ 1,, λ N ) with λ 1 λ 2,..., λ N, and V = [v 1,, v N ] be the matrix of corresponding eigenvectors AV = VΛ 9/23

Eigenvalue decomposition An N N matrix A: a map from R N R N. An eigenvector v undergoes no rotation: Av = λv λ is the corresponding eigenvalue, and gives the rescaling. Let Λ = diag(λ 1,, λ N ) with λ 1 λ 2,..., λ N, and V = [v 1,, v N ] be the matrix of corresponding eigenvectors Real Symmetric matrices have real eigenvalues AV = VΛ different eigenvalues have orthogonal eigenvectors 9/23

Calculating eigenvalues and -vectors Let A be any real symmetric matrix. How to calculate the (absolute) largest eigenvalue and vector? 10/23

Calculating eigenvalues and -vectors Let A be any real symmetric matrix. How to calculate the (absolute) largest eigenvalue and vector? Start with a random vector u 0 Define u 1 = Au 0, and normalize length. Repeat: u i = Au i 1, u i = u i / u i 10/23

Calculating eigenvalues and -vectors Let A be any real symmetric matrix. How to calculate the (absolute) largest eigenvalue and vector? Start with a random vector u 0 Define u 1 = Au 0, and normalize length. Repeat: u i = Au i 1, u i = u i / u i u i v 1 (Why?) 10/23

Calculating eigenvalues and -vectors Let A be any real symmetric matrix. How to calculate the (absolute) largest eigenvalue and vector? Start with a random vector u 0 Define u 1 = Au 0, and normalize length. Repeat: u i = Au i 1, u i = u i / u i u i v 1 (Why?) This is the power method (Google s PageRank). 10/23

Calculating eigenvalues and -vectors Let A be any real symmetric matrix. How to calculate the (absolute) largest eigenvalue and vector? Start with a random vector u 0 Define u 1 = Au 0, and normalize length. Repeat: u i = Au i 1, u i = u i / u i u i v 1 (Why?) This is the power method (Google s PageRank). How would we calculate λ 1? 10/23

Calculating eigenvalues and -vectors Let A be any real symmetric matrix. How to calculate the (absolute) largest eigenvalue and vector? Start with a random vector u 0 Define u 1 = Au 0, and normalize length. Repeat: u i = Au i 1, u i = u i / u i u i v 1 (Why?) This is the power method (Google s PageRank). How would we calculate λ 1? What if we wanted the second eigenvector? 10/23

Calculating eigenvalues and -vectors Let A be any real symmetric matrix. How to calculate the (absolute) largest eigenvalue and vector? Start with a random vector u 0 Define u 1 = Au 0, and normalize length. Repeat: u i = Au i 1, u i = u i / u i u i v 1 (Why?) This is the power method (Google s PageRank). How would we calculate λ 1? What if we wanted the second eigenvector? Adjust A so eigenvalue corresponding to v 1 equals 0 10/23

Gauss-Jordan elimination 10 7 8 7 7 5 6 5 8 6 10 9 7 5 9 10 x 1 x 2 x 3 x 4 32 = 23 33 31 What is the solution? How about for b = [32.1, 22.9, 33.1, 30.9] T? 11/23

Gauss-Jordan elimination 10 7 8 7 7 5 6 5 8 6 10 9 7 5 9 10 x 1 x 2 x 3 x 4 32 = 23 33 31 What is the solution? How about for b = [32.1, 22.9, 33.1, 30.9] T? Why the difference? the determinant? the inverse? the condition number? An ill-conditioned problem can strongly amplify errors. 11/23

Gauss-Jordan elimination 10 7 8 7 7 5 6 5 8 6 10 9 7 5 9 10 x 1 x 2 x 3 x 4 32 = 23 33 31 What is the solution? How about for b = [32.1, 22.9, 33.1, 30.9] T? Why the difference? the determinant? the inverse? the condition number? An ill-conditioned problem can strongly amplify errors. Even without any rounding error 11/23

Stability analysis The operator norm of a matrix A is Av A 2 = A = max Av = max v =1 v v 12/23

Stability analysis The operator norm of a matrix A is Av A 2 = A = max Av = max v =1 v v For a symmetric, real matrix, A = λ max (A) (why?) For a general, real matrix, A = λ max (A T A) (why?) 12/23

Stability analysis The operator norm of a matrix A is Av A 2 = A = max Av = max v =1 v v For a symmetric, real matrix, A = λ max (A) (why?) For a general, real matrix, A = λ max (A T A) (why?) For A in R N N and any v R N, Av A v (why?) 12/23

Stability analysis The operator norm of a matrix A is Av A 2 = A = max Av = max v =1 v v For a symmetric, real matrix, A = λ max (A) (why?) For a general, real matrix, A = λ max (A T A) (why?) For A in R N N and any v R N, Av A v (why?) If A = BC, and all matrices are in R N N, A B C (why?) 12/23

Stability analysis For a perturbation, δb let δx be the change in solution to Ax = b δx x A(x + δx) = b + δb δb is the relative change in the solution from the change b 13/23

Stability analysis For a perturbation, δb let δx be the change in solution to Ax = b δx x A(x + δx) = b + δb δb is the relative change in the solution from the change b From b = Ax and δx = A 1 δb, we have b A x, and δx A 1 δb : 13/23

Stability analysis For a perturbation, δb let δx be the change in solution to Ax = b δx x A(x + δx) = b + δb δb is the relative change in the solution from the change b From b = Ax and δx = A 1 δb, we have b A x, and δx A 1 δb : δx x A A 1 δb b 13/23

Stability analysis For a perturbation, δb let δx be the change in solution to Ax = b δx x A(x + δx) = b + δb δb is the relative change in the solution from the change b From b = Ax and δx = A 1 δb, we have b A x, and δx A 1 δb : δx x A A 1 δb b Condition number of a matrix A is given by κ(a) = A A 1 Large condition number implies unstable solution 13/23

Stability analysis κ(a) 1 (why?) 14/23

Stability analysis κ(a) 1 (why?) For a real symmetric matrix, κ(a) = λ max(a) λ min (A) (why?) 14/23

Stability analysis κ(a) 1 (why?) For a real symmetric matrix, κ(a) = λ max(a) λ min (A) (why?) For a real matrix, κ(a) = λmax (A T A) λ min (A T A) (why?) 14/23

Stability analysis κ(a) 1 (why?) For a real symmetric matrix, κ(a) = λ max(a) λ min (A) (why?) For a real matrix, κ(a) = λmax (A T A) λ min (A T A) (why?) Condition number is a property of a problem Stability is a property of an algorithm A bad algorithm can mess up a simple problem 14/23

Gaussian elimination with partial pivoting Consider reducing to upper triangular v 11 v 12 v 13 v 21 v 22 v 23 v 31 v 32 v 33 Gaussian elimination: divide row 1 by v 11 15/23

Gaussian elimination with partial pivoting Consider reducing to upper triangular v 11 v 12 v 13 v 21 v 22 v 23 v 31 v 32 v 33 Gaussian elimination: divide row 1 by v 11 [ ] 1e 4 1 1 1 15/23

Gaussian elimination with partial pivoting Consider reducing to upper triangular v 11 v 12 v 13 v 21 v 22 v 23 v 31 v 32 v 33 Gaussian elimination: divide row 1 by v 11 [ ] 1e 4 1 1 1 Partial pivoting: Pivot rows to bring max r v r1 to top Can dramatically improve performance. E.g. 15/23

Gaussian elimination with partial pivoting Consider reducing to upper triangular v 11 v 12 v 13 v 21 v 22 v 23 v 31 v 32 v 33 Gaussian elimination: divide row 1 by v 11 [ ] 1e 4 1 1 1 Partial pivoting: Pivot rows to bring max r v r1 to top Can dramatically improve performance. E.g. Why does it work? 15/23

Gaussian elimination with partial pivoting Recall Gaussian elimination decomposes A = LU and solves two intermediate problems. What are the condition numbers of L and U? Try [ ] 1e 4 1 1 1 Note: does pivoting for you automatically! (see the function in package ) 16/23

QR decomposition In general, for A = BC, κ(a) κ(b)κ(c) (why?) 17/23

QR decomposition In general, for A = BC, κ(a) κ(b)κ(c) (why?) QR decomposition: A = QR Here, R is an upper (right) triangular matrix. Q is an orthonormal matrix: Q T Q = I 17/23

QR decomposition In general, for A = BC, κ(a) κ(b)κ(c) (why?) QR decomposition: A = QR Here, R is an upper (right) triangular matrix. Q is an orthonormal matrix: Q T Q = I κ(a) = κ(q)κ(r) (why?) 17/23

QR decomposition In general, for A = BC, κ(a) κ(b)κ(c) (why?) QR decomposition: A = QR Here, R is an upper (right) triangular matrix. Q is an orthonormal matrix: Q T Q = I κ(a) = κ(q)κ(r) (why?) Can use to solve Ax = b (How?) Most stable decomposition 17/23

QR decomposition In general, for A = BC, κ(a) κ(b)κ(c) (why?) QR decomposition: A = QR Here, R is an upper (right) triangular matrix. Q is an orthonormal matrix: Q T Q = I κ(a) = κ(q)κ(r) (why?) Can use to solve Ax = b (How?) Most stable decomposition Does this mean we should use QR decomposition? 17/23

Gram-Schmidt orthonormalization Given N vectors x 1,..., x N construct an orthonormal basis: 18/23

Gram-Schmidt orthonormalization Given N vectors x 1,..., x N construct an orthonormal basis: u 1 = x 1 / x 1 ũ i = x i i 1 j=1 (xt i u j)u i, u i = ũ i / ũ i i = 2..., N 18/23

QR decomposition A = Q R a 11 a 12 a 13 q 11 q 12 q 13 r 11 r 12 r 13 a 21 a 22 a 23 = q 21 q 22 q 23 0 r 22 r 23 a 31 a 32 a 33 q 31 q 32 q 33 0 0 r 33 19/23

QR decomposition A = Q R a 11 a 12 a 13 q 11 q 12 q 13 r 11 r 12 r 13 a 21 a 22 a 23 = q 21 q 22 q 23 0 r 22 r 23 a 31 a 32 a 33 q 31 q 32 q 33 0 0 r 33 QR decomposition: Gram-Schmidt on columns of A (can you see why?) 19/23

QR decomposition A = Q R a 11 a 12 a 13 q 11 q 12 q 13 r 11 r 12 r 13 a 21 a 22 a 23 = q 21 q 22 q 23 0 r 22 r 23 a 31 a 32 a 33 q 31 q 32 q 33 0 0 r 33 QR decomposition: Gram-Schmidt on columns of A (can you see why?) Of course, there are more stable/efficient ways of doing this (Householder rotation/givens rotation) O(N 3 ) algorithms (though about twice as slow as LU) 19/23

QR algorithm Algorithm to calculate all eigenvalues/eigenvectors of a (not too-large) matrix Start with A 0 = A. At iteration i: A i = Q i R i A i+1 = R i Q i Then A i and A i+1 have the same eigenvalues (why?), and the diagonal contains the eigenvalues. 20/23

QR algorithm Algorithm to calculate all eigenvalues/eigenvectors of a (not too-large) matrix Start with A 0 = A. At iteration i: A i = Q i R i A i+1 = R i Q i Then A i and A i+1 have the same eigenvalues (why?), and the diagonal contains the eigenvalues. Can be made more stable/efficient. One of Dongarra & Sullivan (2000) s list of top 10 algoirithms. See also number 4, decompositional approach to matrix computations 20/23

Multivariate normal log(p(x µ, Σ)) = 1 2 (X µ)t Σ 1 (X µ) N 2 log 2π 1 log Σ 2 21/23

Multivariate normal log(p(x µ, Σ)) = 1 2 (X µ)t Σ 1 (X µ) N 2 log 2π 1 log Σ 2 Σ = LL T Y = L 1 (X µ) (Forward solve) 21/23

Multivariate normal log(p(x µ, Σ)) = 1 2 (X µ)t Σ 1 (X µ) N 2 log 2π 1 log Σ 2 Σ = LL T Y = L 1 (X µ) (Forward solve) log(p(x µ, Σ)) = 1 2 YT Y N 2 log 2π log Σ 21/23

Multivariate normal log(p(x µ, Σ)) = 1 2 (X µ)t Σ 1 (X µ) N 2 log 2π 1 log Σ 2 Σ = LL T Y = L 1 (X µ) (Forward solve) log(p(x µ, Σ)) = 1 2 YT Y N 2 log 2π log Σ Can also just forward solve for L 1 : LL 1 = I (Inverted triangular matrix isn t too bad) 21/23

Sampling a multivariate normal Sampling a univariate normal: Inversion method (default for?). Box-Muller transform: (Z 1, Z 2 ) : independent standard normals. 22/23

Sampling a multivariate normal Sampling a univariate normal: Inversion method (default for?). Box-Muller transform: (Z 1, Z 2 ) : independent standard normals. Let Z N (0, I) X = µ + LZ Z = N (µ, L T L) 22/23

x 10 10 5 0 5 10 5 0 5 10 y [ ] 1 0 Σ = 0 1 23/23

x 10 10 5 0 5 10 5 0 5 10 y [ ] 4 0 Σ = 0 1 23/23

x 10 10 5 0 5 10 5 0 5 10 y [ ] 4 2 Σ = 2 4 23/23

x 10 10 5 0 5 10 5 0 5 10 y [ ] 4 3.8 Σ = 3.8 4 23/23