Bindel, Fall 2016 Matrix Computations (CS 6210) Notes for

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

Scientific Computing

Numerical Methods I Non-Square and Sparse Linear Systems

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

B553 Lecture 5: Matrix Algebra Review

Scientific Computing with Case Studies SIAM Press, Lecture Notes for Unit VII Sparse Matrix

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

A Cholesky LR algorithm for the positive definite symmetric diagonal-plus-semiseparable eigenproblem

Linear Algebra (Review) Volker Tresp 2018

Simple sparse matrices we have seen so far include diagonal matrices and tridiagonal matrices, but these are not the only ones.

Fast Multipole Methods: Fundamentals & Applications. Ramani Duraiswami Nail A. Gumerov

Numerical Linear Algebra

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

Linear Algebra and Eigenproblems

Section 4.5 Eigenvalues of Symmetric Tridiagonal Matrices

Matrix Computations and Semiseparable Matrices

Linear Solvers. Andrew Hazel

Scientific Computing: Dense Linear Systems

Example Linear Algebra Competency Test

Applied Numerical Linear Algebra. Lecture 8

STAT 309: MATHEMATICAL COMPUTATIONS I FALL 2018 LECTURE 13

Solvability of Linear Matrix Equations in a Symmetric Matrix Variable

6. Iterative Methods for Linear Systems. The stepwise approach to the solution...

AMS526: Numerical Analysis I (Numerical Linear Algebra)

3 (Maths) Linear Algebra

STAT 309: MATHEMATICAL COMPUTATIONS I FALL 2018 LECTURE 9

GAUSSIAN ELIMINATION AND LU DECOMPOSITION (SUPPLEMENT FOR MA511)

Algebra C Numerical Linear Algebra Sample Exam Problems

Foundations of Matrix Analysis

Bindel, Fall 2016 Matrix Computations (CS 6210) Notes for

Numerical Methods in Matrix Computations

5.1 Banded Storage. u = temperature. The five-point difference operator. uh (x, y + h) 2u h (x, y)+u h (x, y h) uh (x + h, y) 2u h (x, y)+u h (x h, y)

Scientific Computing: Solving Linear Systems

Linear Algebra Methods for Data Mining

Math 671: Tensor Train decomposition methods

Math 515 Fall, 2008 Homework 2, due Friday, September 26.

Math 471 (Numerical methods) Chapter 3 (second half). System of equations

Sparse BLAS-3 Reduction

Multivariate Statistical Analysis

Linear Algebra Review. Fei-Fei Li

Review Questions REVIEW QUESTIONS 71

CS 542G: Conditioning, BLAS, LU Factorization

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

Numerical Linear Algebra

Last Time. Social Network Graphs Betweenness. Graph Laplacian. Girvan-Newman Algorithm. Spectral Bisection

Linear Algebra (Review) Volker Tresp 2017

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

Name: INSERT YOUR NAME HERE. Due to dropbox by 6pm PDT, Wednesday, December 14, 2011

L. Vandenberghe EE133A (Spring 2017) 3. Matrices. notation and terminology. matrix operations. linear and affine functions.

6.4 Krylov Subspaces and Conjugate Gradients

11.5 Reduction of a General Matrix to Hessenberg Form

EIGENVALUE PROBLEMS. EIGENVALUE PROBLEMS p. 1/4

Chapter 7. Tridiagonal linear systems. Solving tridiagonal systems of equations. and subdiagonal. E.g. a 21 a 22 a A =

Matrices. Chapter What is a Matrix? We review the basic matrix operations. An array of numbers a a 1n A = a m1...

Sparse Linear Systems. Iterative Methods for Sparse Linear Systems. Motivation for Studying Sparse Linear Systems. Partial Differential Equations

Image Registration Lecture 2: Vectors and Matrices

Lecture 12 (Tue, Mar 5) Gaussian elimination and LU factorization (II)

Lecture 15 Review of Matrix Theory III. Dr. Radhakant Padhi Asst. Professor Dept. of Aerospace Engineering Indian Institute of Science - Bangalore

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

Algebraic Equations. 2.0 Introduction. Nonsingular versus Singular Sets of Equations. A set of linear algebraic equations looks like this:

3.5 Finite Differences and Fast Poisson Solvers

Vector, Matrix, and Tensor Derivatives

Linear Programming The Simplex Algorithm: Part II Chapter 5

CS 246 Review of Linear Algebra 01/17/19

Consider the following example of a linear system:

Linear Systems of Equations. ChEn 2450

A Review of Matrix Analysis

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

Practical Linear Algebra: A Geometry Toolbox

Numerical Linear Algebra

Bindel, Fall 2016 Matrix Computations (CS 6210) Notes for

CS 598: Communication Cost Analysis of Algorithms Lecture 9: The Ideal Cache Model and the Discrete Fourier Transform

Linear Algebra Review

Math 671: Tensor Train decomposition methods II

arxiv: v1 [math.na] 5 May 2011

6 Linear Systems of Equations

Numerical Methods I: Numerical linear algebra

Course Notes: Week 1

Sparsity-Preserving Difference of Positive Semidefinite Matrix Representation of Indefinite Matrices

Lecture # 5 The Linear Least Squares Problem. r LS = b Xy LS. Our approach, compute the Q R decomposition, that is, n R X = Q, m n 0

Linear Algebra Review. Fei-Fei Li

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

1 Multiply Eq. E i by λ 0: (λe i ) (E i ) 2 Multiply Eq. E j by λ and add to Eq. E i : (E i + λe j ) (E i )

Krylov Subspaces. Lab 1. The Arnoldi Iteration

9. Iterative Methods for Large Linear Systems

Katholieke Universiteit Leuven Department of Computer Science

BLAS: Basic Linear Algebra Subroutines Analysis of the Matrix-Vector-Product Analysis of Matrix-Matrix Product

Using semiseparable matrices to compute the SVD of a general matrix product/quotient

. =. a i1 x 1 + a i2 x 2 + a in x n = b i. a 11 a 12 a 1n a 21 a 22 a 1n. i1 a i2 a in

Algebra Workshops 10 and 11

Iterative Methods for Solving A x = b

EECS 275 Matrix Computation

Chapter 9 Implicit integration, incompressible flows

An Introduction to Algebraic Multigrid (AMG) Algorithms Derrick Cerwinsky and Craig C. Douglas 1/84

Getting Started with Communications Engineering. Rows first, columns second. Remember that. R then C. 1

1 Determinants. 1.1 Determinant

Outline Introduction: Problem Description Diculties Algebraic Structure: Algebraic Varieties Rank Decient Toeplitz Matrices Constructing Lower Rank St

CS 219: Sparse matrix algorithms: Homework 3

Solving PDEs with CUDA Jonathan Cohen

The Singular Value Decomposition

Transcription:

1 Logistics Notes for 2016-08-26 1. Our enrollment is at 50, and there are still a few students who want to get in. We only have 50 seats in the room, and I cannot increase the cap further. So if you are not planning to stick with the class, please don t wait to formally drop! 2. I got off to a slow start, but I will typically try to post notes for each lecture before the lecture itself (though maybe only the morning of the lecture). The notes are on GitHub, so if you find errors, please feel free to help me correct them. 3. The notes for the first lecture include some material that I did not talk about explicitly: recommendations for reading in linear algebra and numerical linear algebra to supplement what I cover in class, and a long list of notational conventions that I plan to follow in class and in the notes. 2 Matrix shapes and structures In linear algebra, we talk about different matrix structures. For example: A R n n is nonsingular if the inverse exists; otherwise it is singular. Q R n n is orthogonal if Q T Q = I. A R n n is symmetric if A = A T. S R n n is skew-symmetric if S = S T. L R n m is low rank if L = UV T for U R n k and V R m k where k min(m, n). These are properties of an underlying linear map or quadratic form; if we write a different matrix associated with an (appropriately restricted) change of basis, it will also have the same properties. In matrix computations, we also talk about the shape (nonzero structure) of a matrix. For example:

D is diagonal if d ij = 0 for i j. T is tridiagonal if t ij = 0 for i {j 1, j, j + 1}. U is upper triangular if u ij = 0 for i > j and strictly upper triangular if u ij = 0 for i j (lower triangular and strictly lower triangular are similarly defined). H is upper Hessenberg if h ij = 0 for i > j + 1. B is banded if b ij = 0 for i j > β. S is sparse if most of the entries are zero. The position of the nonzero entries in the matrix is called the sparsity structure. We often represent the shape of a matrix by marking where the nonzero elements are (usually leaving empty space for the zero elements); for example: Diagonal Tridiagonal Triangular Hessenberg We also sometimes talk about the graph of a (square) matrix A R n n : if we assign a node to each index {1,..., n}, an edge (i, j) in the graph corresponds to a ij 0. There is a close connection between certain classes of graph algorithms and algorithms for factoring sparse matrices or working with different matrix shapes. For example, the matrix A can be permuted so that P AP T is upper triangular iff the associated directed graph is acyclic. The shape of a matrix (or graph of a matrix) is not intrinsically associated with a more abstract linear algebra concept; apart from permutations, sometimes, almost any change of basis will completely destroy the shape.

3 Sparse matrices We say a matrix is sparse if the vast majority of the entries are zero. Because we only need to explicitly keep track of the nonzero elements, sparse matrices require less than O(n 2 ) storage, and we can perform many operations more cheaply with sparse matrices than with dense matrices. In general, the cost to store a sparse matrix, and to multiply a sparse matrix by a vector, is O(nnz(A)), where nnz(a) is the number of nonzeros in A. Two specific classes of sparse matrices are such ubiquitous building blocks that it is worth pulling them out for special attention. These are diagonal matrices and permutation matrices. Many linear algebra libraries also have support for banded matrices (and sometimes for generalizations such as skyline matrices). Matlab also provides explicit support for general sparse matrices in which the nonzeros can appear in any position. 3.1 Diagonal matrices A diagonal matrix is zero except for the entries on the diagonal. We often associate a diagonal matrix with the vector of these entries, and we will adopt in class the notational convention used in Matlab: the operator diag maps a vector to the corresponding diagonal matrix, and maps a matrix to the vector of diagonal entries. For example, for the vector and matrix d 1 1 d = d 2 D = d d 2 d 3 we would write D = diag(d) and d = diag(d). The Matlab routine diag forms a dense representation of a diagonal matrix. Next to inv, it is one of the Matlab commands that is most commonly poorly used. The primary good use of diag is as the first term in a sum that builds a more complicated matrix. But multiplication by a diagonal matrix should never go through the diag routine. To multiple a diagonal matrix by a vector, the preferred idiom is to use the elementwise multiplication operation, i.e. 1 y = diag(d) * x; % Bad -- O(nˆ2) time and intermediate storage 2 y = d.* x; % Good -- equivalent, but O(n) time and space To multiply a diagonal matrix by a vector in Matlab, use the bsxfun command, e.g. d 3

1 B = diag(d) * A; % Bad -- left scaling in O(nˆ3) time 2 C = A * diag(d); % Bad -- right scaling in O(nˆ3) time 3 B = bsxfun(@times, d, A); % Good -- O(nˆ2) time 4 C = bsxfun(@times, A, d. ); % Ditto 3.2 Permutations A permutation matrix is a 0-1 matrix in which one appears exactly once in each row and column. We typically use P or Π to denote permutation matrices; if there are two permutations in a single expression, we might use P and Q. A permutation matrix is so named because it permutes the entries of a vector. As with diagonal matrices, it is usually best to work with permutations implicitly in computational practice. For any given permutation vector P, we can define an associated mapping vector p such that p(i) = j iff P ij = 1. We can then apply the permutation to a vector or matrix using Matlab s indexing operations: 1 B = P*A; % Straightforward, but slow if P is a dense rep n 2 C = A*P ; 3 B = A(p,:); % Better 4 C = A(:,p); To apply a transpose permutation, we would usually use the permuted indexing on the destination rather than the source: 1 y = P *x; % Implies that P*y = x 2 y(p) = x; % Apply the transposed permutation via indexing 3.3 Narrowly banded matrices If a matrix A has zero entries outside a narrow band near the diagonal, we say that A is a banded matrix. More precisely, if a ij = 0 for j < i k 1 or j > i + k 2, we say that A has lower bandwidth k 1 and upper bandwidth k 2. The most common narrowly-banded matrices in matrix computations (other than diagonal matrices) are tridiagonal matrices in which k 1 = k 2 = 1. In the conventional storage layout for band matrices (used by LAPACK) the nonzero entries for a band matrix A are stored in a packed storage matrix B such that each column of B corresponds to a column of A and each row

of B corresponds to a nonzero (off-)diagonal of A. For example, a 11 a 12 a 21 a 22 a 23 a 12 a 23 a 34 a 45 a 31 a 32 a 33 a 34 a 42 a 43 a 44 a 45 a 11 a 22 a 33 a 44 a 55 a 21 a 32 a 43 a 54 a a 53 a 54 a 31 a 42 a 53 55 Matlab does not provide easy specialized support for band matrices (though it is possible to access the band matrix routines if you are tricky). Instead, the simplest way to work with narrowly banded matrices in Matlab is to use a general sparse representation. 3.4 General sparse matrices For diagonal and band matrices, we are able to store nonzero matrix entries explicitly, but (as with the dense matrix format) the locations of those nonzero entries in the matrix are implicit. For permutation matrices, the values of the nonzero entries are implicit (they are always one), but we must store their positions explicitly. In a general sparse matrix format, we store both the positions and the values of nonzero entries explicitly. For input and output, Matlab uses a coordinate format for sparse matrices consisting of three parallel arrays (i, j, and aij). Each entry in the parallel arrays represents a nonzero in the matrix with value aij(k) at row i(k) and column j(k). For input, repeated entries with the same row and column are allowed; in this case, all the entries for a given location are summed together in the final matrix. For example, 1 i = [1, 2, 3, 4, 4]; % Row indices 2 j = [2, 3, 4, 5, 5]; % Col indices 3 v = [5, 8, 13, 21, 34]; % Entry values/contributions 4 A = sparse(i,j,v,5,5); % 5-by-5 sparse matrix 5 full(a) % Convert to dense format and display 6 7 % Output: 8 % ans = 9 % 10 % 0 5 0 0 0 11 % 0 0 8 0 0 12 % 0 0 0 13 0 13 % 0 0 0 0 55 14 % 0 0 0 0 0

This functionality is useful in some applications (e.g. for assembling finite element matrices). Internally, Matlab uses a compressed sparse column format for sparse matrices. In this format, the row position and value for each nonzero are stored in parallel arrays, in column-major order (i.e. all the elements of column k appear before elements of column k + 1). The column positions are not stored explicitly for every element; instead, a pointer array indicates the offset in the row and entry arrays of the start of the data for each column; a pointer array entry at position n + 1 indicates the total number of nonzeros in the data structure. The compressed sparse column format has some features that may not be obvious at first: For very sparse matrices, multiplying a sparse format matrix by a vector is much faster than multiplying a dense format matrix by a vector but this is not true if a significant fraction of the matrix is nonzeros. The tradeoff depends on the matrix size and machine details, but sparse matvecs will often have the same speed as or even be slower than dense matvecs when the sparsity is above a few percent. Adding contributions into a sparse matrix is relatively slow, as each sum requires recomputing the sparse indexing data structure and reallocating memory. To build up a sparse matrix as the sum of many components, it is usually best to use the coordinate form first. In general, though, the sparse matrix format has a great deal to recommend it for genuinely sparse matrices. Matlab uses the sparse matrix format not only for general sparse matrices, but also for the special case of banded matrices. 4 Data-sparse matrices A sparse matrix has mostly zero entries; this lets us design compact storage formats with space proportional to the number of nonzeros, and fast matrixvector multiplication with time proportional to the number of nonzeros. A data-sparse matrix can be described with far fewer than n 2 parameters, even if it is not sparse. Such matrices usually also admit compact storage schemes and fast matrix-vector products. This is significant because many of the

iterative algorithms we describe later in the semester do not require any particular representation of the matrix; they only require that we be able to multiply by a vector quickly. The study of various data sparse representations has blossomed into a major field of study within matrix computations; in this section we give a taste of a few of the most common types of data sparsity. We will see several of these structures in model problems used over the course of the class. 4.1 (Nearly) low-rank matrices The simplest and most common data-sparse matrices are low-rank matrices. If A R m n has rank k, it can be written in outer product form as A = UW T,, U R m k, W R n k. This factored form has a storage cost of (n + m)k, a significant savings over the mn cost of the dense representation in the case k max(m, n). To multiply a low-rank matrix by a vector fast, we need only to use associativity of matrix operations 1 y = (U*V )*x; % O(mn) storage, O(mnk) flops 2 y = U*(V *x); % O((m+n) k) storage and flops 4.2 Circulant, Toeplitz, and Hankel structure A Toeplitz matrix is a matrix in which each (off)-diagonal is constant, e.g. a 0 a 1 a 2 a 3 A = a 1 a 0 a 1 a 2 a 2 a 1 a 0 a 1. a 3 a 2 a 1 a 0 Toeplitz matrices play a central role in the theory of constant-coefficient finite difference equations and in many applications in signal processing. Multiplication of a Toeplitz matrix by a vector represents (part of) a convolution; and afficionados of Fourier analysis and signal processing may already know that this implies that matrix multiplication can be done in O(n log n) time using a discrete Fourier transforms. The trick to this is to

view the Toeplitz matrix as a block in a larger circulant matrix a 0 a 1 a 2 a 3 a 3 a 2 a 1 a 1 a 0 a 1 a 2 a 3 a 3 a 2 a 2 a 1 a 0 a 1 a 2 a 3 a 3 3 C = a 3 a 2 a 1 a 0 a 1 a 2 a 3 = a k P k, a 3 a 3 a 2 a 1 a 0 a 1 a 2 k= 3 a 2 a 3 a 3 a 2 a 1 a 0 a 1 a 1 a 2 a 3 a 3 a 2 a 1 a 0 where P is the cyclic permutation matrix 0 0... 0 1 1 0 P = 1 0..... 1 0 As we will see later in the course, the discrete Fourier transform matrix is the eigenvector matrix for this cyclic permutation, and this is a gateway to fast matrix-vector multiplication algorithms. Closely-related to Toeplitz matrices are Hankel matrices, which are constant on skew-diagonals (that is, they are Toeplitz matrices flipped upside down). Hankel matrices appear in numerous applications in control theory. 4.3 Separability and Kronecker product structure The Kronecker product A B R (mp) (nq) of matrices A R m n and B R p q is the (gigantic) matrix a 11 B a 12 B... a 1n B a 21 B a 22 B... a 2n B A B =.... a m1 B a m2 B... a mn B Multiplication of a vector by a Kronecker product represents a matrix triple product: (A B) vec(x) = vec(bxa T )

where vec(x) represents the vector formed by listing the elements of a matrix in column major order, e.g. [ ] 1 1 3 vec = 2 2 4 3. 4 Kronecker product structure appears often in control theory applications and in problems that arise from difference or differential equations posed on regular grids you should expect to see it for regular discretizations of differential equations where separation of variables works well. There is also a small industry of people working on tensor decompositions, which feature sums of Kronecker products. 4.4 Low-rank block structure In problems that come from certain areas of mathematical physics, integral equations, and PDE theory, one encounters matrices that are not low rank, but have low-rank submatrices. The fast multipole method computes a matrix-vector product for one such class of matrices; and again, there is a cottage industry of related methods, including the H matrices studied by Hackbush and colleagues, the sequentially semi-separable (SSS) and heirarchically semi-separable (HSS) matrices, quasi-separable matrices, and a horde of others. A good reference is the pair of books by Vandebril, Van Barel and Mastronardi [1, 2]. References [1] Raf Vandebril, Marc Van Barel, and Nicola Mastonardi. Matrix Computations and Semiseparable Matrices: Eigenvalue and Singular Value Methods. John Hopkins University Press, 2010. [2] Raf Vandebril, Marc Van Barel, and Nicola Mastonardi. Matrix Computations and Semiseparable Matrices: Linear Systems. John Hopkins University Press, 2010.