Introduction to SVD and Applications

Similar documents
MAT 343 Laboratory 6 The SVD decomposition and Image Compression

3D Computer Vision - WT 2004

14 Singular Value Decomposition

Assignment #10: Diagonalization of Symmetric Matrices, Quadratic Forms, Optimization, Singular Value Decomposition. Name:

15 Singular Value Decomposition

Linear Algebra Review. Fei-Fei Li

Linear Algebra Review. Fei-Fei Li

7. Symmetric Matrices and Quadratic Forms

Singular Value Decompsition

LEC 2: Principal Component Analysis (PCA) A First Dimensionality Reduction Approach

COMP 558 lecture 18 Nov. 15, 2010

7 Principal Component Analysis

Singular Value Decomposition: Compression of Color Images

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

Linear Least Squares. Using SVD Decomposition.

The Singular Value Decomposition

CS168: The Modern Algorithmic Toolbox Lecture #8: How PCA Works

Singular Value Decomposition. 1 Singular Value Decomposition and the Four Fundamental Subspaces

The Singular Value Decomposition (SVD) and Principal Component Analysis (PCA)

Introduction to Matlab

Image Compression Using Singular Value Decomposition

Linear Algebra and Matrices

MA201: Further Mathematical Methods (Linear Algebra) 2002

. = V c = V [x]v (5.1) c 1. c k

A Review of Linear Algebra

Properties of Matrices and Operations on Matrices

Lecture: Face Recognition and Feature Reduction

Singular Value Decomposition

Singular Value Decomposition

Singular value decomposition

1 Linearity and Linear Systems

(Linear equations) Applied Linear Algebra in Geoscience Using MATLAB

Chapter 7: Symmetric Matrices and Quadratic Forms

Matrices and Vectors. Definition of Matrix. An MxN matrix A is a two-dimensional array of numbers A =

EE731 Lecture Notes: Matrix Computations for Signal Processing

EE263 homework 3 solutions

Final Exam, Linear Algebra, Fall, 2003, W. Stephen Wilson

Lab 2 Worksheet. Problems. Problem 1: Geometry and Linear Equations

Least Squares Optimization

Singular Value Decomposition and Digital Image Compression

(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 =

Singular Value Decomposition

Linear Algebra Review. Vectors

Linear Algebra. Session 12

8 The SVD Applied to Signal and Image Deblurring

Notes on singular value decomposition for Math 54. Recall that if A is a symmetric n n matrix, then A has real eigenvalues A = P DP 1 A = P DP T.

Lecture Summaries for Linear Algebra M51A

UNIT 6: The singular value decomposition.

L3: Review of linear algebra and MATLAB

Dimensionality Reduction: PCA. Nicholas Ruozzi University of Texas at Dallas

Lecture 8. Principal Component Analysis. Luigi Freda. ALCOR Lab DIAG University of Rome La Sapienza. December 13, 2016

Lecture: Face Recognition and Feature Reduction

Problem # Max points possible Actual score Total 120

6 The SVD Applied to Signal and Image Deblurring

MATH36001 Generalized Inverses and the SVD 2015

Designing Information Devices and Systems II Fall 2018 Elad Alon and Miki Lustig Homework 9

MATH 122: Matrixology (Linear Algebra) Solutions to Level Tetris (1984), 10 of 10 University of Vermont, Fall 2016

Chapter 3 Transformations

8 The SVD Applied to Signal and Image Deblurring

x n -2.5 Definition A list is a list of objects, where multiplicity is allowed, and order matters. For example, as lists

SVD and Image Compression

IV. Matrix Approximation using Least-Squares

The Singular Value Decomposition and Least Squares Problems

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

1. The Polar Decomposition

Linear Algebra and Eigenproblems

Least squares and Eigenvalues

Lecture 1 Review: Linear models have the form (in matrix notation) Y = Xβ + ε,

TBP MATH33A Review Sheet. November 24, 2018

Least Squares Optimization

Principal Component Analysis

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

Exercise Sheet 1.

Math Assignment 3 - Linear Algebra

Announcements Wednesday, November 01

Lecture 2: Linear Algebra Review

Conceptual Questions for Review

Numerical Methods I Singular Value Decomposition

EE731 Lecture Notes: Matrix Computations for Signal Processing

Announce Statistical Motivation Properties Spectral Theorem Other ODE Theory Spectral Embedding. Eigenproblems I

Least Squares Optimization

LAB 2: Orthogonal Projections, the Four Fundamental Subspaces, QR Factorization, and Inconsistent Linear Systems

Lecture 13. Principal Component Analysis. Brett Bernstein. April 25, CDS at NYU. Brett Bernstein (CDS at NYU) Lecture 13 April 25, / 26

8. the singular value decomposition

Math 671: Tensor Train decomposition methods II

Introduction to Machine Learning. PCA and Spectral Clustering. Introduction to Machine Learning, Slides: Eran Halperin

Lecture 3: Review of Linear Algebra

MATH2071: LAB #7: Factorizations

Applied Linear Algebra in Geoscience Using MATLAB

Math 408 Advanced Linear Algebra

Lecture 3: Review of Linear Algebra

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

4 ORTHOGONALITY ORTHOGONALITY OF THE FOUR SUBSPACES 4.1

Large Scale Data Analysis Using Deep Learning

18.06 Problem Set 10 - Solutions Due Thursday, 29 November 2007 at 4 pm in

Summary of Week 9 B = then A A =

Review of Some Concepts from Linear Algebra: Part 2

Linear Algebra, part 3 QR and SVD

Eigenvalues and diagonalization

AM205: Assignment 2. i=1

Transcription:

Introduction to SVD and Applications Eric Kostelich and Dave Kuhl MSRI Climate Change Summer School July 18, 2008 Introduction The goal of this exercise is to familiarize you with the basics of the singular value decomposition (SVD). The SVD is known by many names, such as principal component analysis. It has many uses. In numerical analysis, the SVD provides a measure of the effective rank of a given matrix. In statistics and time series analysis, the SVD a particularly useful tool for finding least-squares solutions and approximations. Don t worry if you don t finish all the exercises today. However, I strongly encourage you to complete them over the weekend. Monday s lectures will be easier to understand once you have some geometric intuition about the SVD. Let A be an m n real matrix; m and n may be any positive integers. The SVD of A is the factorization A m n = U m n S n n V T n n, (1) where S = diag(s 1,...,s n ). The s i s are the singular values of A. By convention, they are ordered so that s 1 s 2 s n 0. The columns of U and V may be chosen so that they form an orthonormal basis of the column space and row space, respectively, of A. If A has full rank, then its singular values are all positive, and when they are ordered as indicated, then the SVD is unique up to the signs of the columns of U and V. Note. There are other essentially equivalent formulations of Eq. (1). For example, when m n and ranka = n, it is possible to extend U to be an m m matrix whose columns form an orthonormal basis for R m (and whose first n columns span 1

the column space of A). In this case, S may be taken to be an m n matrix such that S ii = s i, i = 1,...,n, and whose other entries are zero. All of this can be extended to a general m n complex matrix A. You can find more details in most any textbook on advanced linear algebra and on a variety of Web sites. We ll stick to real matrices for today. The decomposition in Eq. (1) implies that A T A = (USV T ) T (USV T ) = VSU T USV T = VS 2 V T since U is orthonormal and S is diagonal. Also, because V T = V 1, we have (A T A)V = VS 2, which shows that the columns of V are eigenvectors of A T A. The singular values of A are the square roots of the corresponding eigenvalues. Practice Problem 1. Show that the columns of U are eigenvectors of AA T. Practice Problem 2. Consider the linear least-squares problem, where we fit a p-parameter model of the form y i = b 1 + b 2 x + + b p x p 1 (2) to a collection of data points {(x i,y i )} n i=1. Equation (2) can be written in matrixvector form as y 1 1 x 1 x p 1 1 b 1 y 2 y = Xβ =. = 1 x 2 x p 1 2 b 2... y n 1 x n xn p 1 b p The least-squares solution is given by the solution to the normal equation Assuming that n p and rankx = p, show that (X T X)β = X T y. (3) β = VS 1 U T y where X = USV T is the SVD of X. Hence the SVD is an alternative to the QR decomposition for solving linear least-squares problems. 2

Matrix times circle equals ellipse Practice Problem 3. Generate a circle of points with 1 separation as follows (mind the semicolons!): circ = zeros(2, 360); a 2 360 zero array deg = [ 1 : 1 : 360 ]; circ(1, :) = cos(deg pi / 180); pi is a built-in constant circ(2, :) = sin(deg pi / 180); Now define A to be your favorite nonsingular 2 2 matrix (choose A I to keep things interesting). The syntax A = [ a b ; c d ] ( ) a b defines A =. Compute the SVD of A: c d [ U S V ] = svd(a) Now plot A circle as follows: hold on concatenate all subsequent plots on the same graph axis equal plot(circ(1, :), circ(2, :), o ) no semicolon Acirc = A circ; plot(acirc(1, :), Acirc(2, :), o ) no semicolon The major and minor axes of the ellipse are given by the eigenvectors of AA T, that is, the columns of U. Add them to your plot as follows: Uline = [ U(:,1) S(1,1) [ 0 0 ] U(:,2) S(2,2) ]; note the prime plot(uline(1, :), Uline(2, :), r ) hold off Rank-r approximations Often it is convenient to approximate a given full-rank matrix A by a matrix  of less than full rank. The approximation  is obtained by Eq. (1) where the smallest n r singular values in S are replaced with 0. Equivalently, we may write  = Û m r Ŝ r r ˆV T r n (4) 3

that is, the product of the first r columns of U, the upper r r block of S, and the first r columns of V. (In other words, for every x, we project Ax onto the subspace spanned by the first r columns of U.) The notion of a rank-r approximation is a key idea in the data assimilation algorithm that we ll discuss next week. One goal today is to illustrate that r need not be very large to get a good approximation. The example that we ll consider gives an image compression algorithm. Step 1. Download the file dog.jpg from the Web page to the your working MATLAB directory. Then load it into Matlab with the command A = imread(./dog.jpg ); The semincolon is necessary so that MATLAB does not print out many screenfuls of data. The result is a 310 338 matrix of grayscale values corresponding to a black and white picture of a dog. (The matrix has 104,780 entries.) Step 2. We need to do some initial processing. Type B = double(a(:, :, 1)) + 1; which converts A into the double-precision format that is needed for the singular value decomposition. Now say B = B / 256; [ U S V ] = svd(b); The gray scale goes from 0 to 256 in a black-and-white JPEG image. We divide B by 256 to obtain values between 0 and 1, which is required for the MAT- LAB imaging routines that we ll use later. Practice Problem 4. What are the dimensions of U, S, and V? Here S has more columns than rows; in fact, columns 311 to 338 are all zeros. (When m < n, we pad S on the right with zero columns to turn S into an m n matrix rather than an n n matrix.) Practice Problem 5. Compute the best rank-1 approximation to B and store it in the matrix rank1. (See Eq. (4). The matrix slice consisting of the first r columns of U is denoted U(:, 1:r) in MATLAB. The upper r r portion of S is S(1:r, 1:r), and so on.) Step 3. Let s visualize rank1. To do that, first create C = zeros(size(a)); 4

This creates an array of zeroes, C, of the same dimensions as the original image matrix A. Now A is actually 310 338 3. To create an image from the matrix C, MATLAB uses C(i, j,1 : 3) as the RGB values that color the i jth pixel. We have a black-and-white photo, so we ll set all the RGB values to be the same, namely 1/2: C(:, :, :) = 0.5; Step 4. Copy the rank-1 image into C as follows: C(:, :, 1) = rank1; C(:, :, 2) = rank1; C(:, :, 3) = rank1; semicolons on all of these Step 5. We re almost done, except for one hitch. MATLAB does all its scaling using values from 0 to 1 (and maps them to values between 0 and 256 for the graphics hardware). Lower-rank approximations to the actual image can have values that are slightly less than 0 and greater than 1. So we ll truncate them to fit, as follows: C(:, :, :) = min(1, C(:, :, :)); C(:, :, :) = max(0, C(:, :, :)); Step 6. View the resulting image: image(c) no semicolon Practice Problem 6. Create and view a rank-10 approximation to the original picture. (Use Steps 4 6 but with rank10 instead of rank1. If you mess up for example, you get an all-black picture then start over from Step 3.) Practice Problem 7. Repeat with approximations of rank 20, 30, and 40 (and any others that you d like to experiment with). What is the smallest rank that, in your opinion, gives an acceptable approximation to the original picture? Practice Problem 8. What rank-r approximation exactly reproduces the original picture? 5