Bindel, Fall 2012 Matrix Computations (CS 6210) Week 1: Wednesday, Aug 22



Similar documents
Matrix Multiplication

APPM4720/5720: Fast algorithms for big data. Gunnar Martinsson The University of Colorado at Boulder

Solution of Linear Systems

Lecture 2 Matrix Operations

DATA ANALYSIS II. Matrix Algorithms

2x + y = 3. Since the second equation is precisely the same as the first equation, it is enough to find x and y satisfying the system

CS3220 Lecture Notes: QR factorization and orthogonal transformations

Operation Count; Numerical Linear Algebra

[1] Diagonal factorization

Big-data Analytics: Challenges and Opportunities

3 Orthogonal Vectors and Matrices

Notes on Orthogonal and Symmetric Matrices MENU, Winter 2013

SOLVING LINEAR SYSTEMS

Optimizing matrix multiplication Amitabha Banerjee

Numerical Methods I Eigenvalue Problems

u = [ 2 4 5] has one row with three components (a 3 v = [2 4 5] has three rows separated by semicolons (a 3 w = 2:5 generates the row vector w = [ 2 3

Linear Programming. March 14, 2014

7 Gaussian Elimination and LU Factorization

14:440:127 Introduction to Computers for Engineers. Notes for Lecture 06

October 3rd, Linear Algebra & Properties of the Covariance Matrix

General Framework for an Iterative Solution of Ax b. Jacobi s Method

CUDAMat: a CUDA-based matrix class for Python

Lecture 3: Finding integer solutions to systems of linear equations

Practical Guide to the Simplex Method of Linear Programming

Linear Algebra Review. Vectors

Parallel and Distributed Computing Programming Assignment 1

Numerical Analysis. Professor Donna Calhoun. Fall 2013 Math 465/565. Office : MG241A Office Hours : Wednesday 10:00-12:00 and 1:00-3:00

Bindel, Spring 2012 Intro to Scientific Computing (CS 3220) Week 3: Wednesday, Feb 8

Similar matrices and Jordan form

Vector and Matrix Norms

LS.6 Solution Matrices

Recall that two vectors in are perpendicular or orthogonal provided that their dot

The PageRank Citation Ranking: Bring Order to the Web

Linear Algebra and TI 89

DERIVATIVES AS MATRICES; CHAIN RULE

Matrices 2. Solving Square Systems of Linear Equations; Inverse Matrices

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS

1 Review of Least Squares Solutions to Overdetermined Systems

5 Homogeneous systems

Modélisation et résolutions numérique et symbolique

8.2. Solution by Inverse Matrix Method. Introduction. Prerequisites. Learning Outcomes

Question 2: How do you solve a matrix equation using the matrix inverse?

Review Jeopardy. Blue vs. Orange. Review Jeopardy

A linear combination is a sum of scalars times quantities. Such expressions arise quite frequently and have the form

1 Solving LPs: The Simplex Algorithm of George Dantzig

Linear Programming. April 12, 2005

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 2. x n. a 11 a 12 a 1n b 1 a 21 a 22 a 2n b 2 a 31 a 32 a 3n b 3. a m1 a m2 a mn b m

We shall turn our attention to solving linear systems of equations. Ax = b

Solving simultaneous equations using the inverse matrix

10.2 ITERATIVE METHODS FOR SOLVING LINEAR SYSTEMS. The Jacobi Method

Typical Linear Equation Set and Corresponding Matrices

Linear Algebra Notes for Marsden and Tromba Vector Calculus

NOTES ON LINEAR TRANSFORMATIONS

Sudoku puzzles and how to solve them

Solving Systems of Linear Equations Using Matrices

1.2 Solving a System of Linear Equations

Systems of Linear Equations

5.5. Solving linear systems by the elimination method

1.5 SOLUTION SETS OF LINEAR SYSTEMS

Chapter 19. General Matrices. An n m matrix is an array. a 11 a 12 a 1m a 21 a 22 a 2m A = a n1 a n2 a nm. The matrix A has n row vectors

3.2 Matrix Multiplication

(!' ) "' # "*# "!(!' +,

Notes on Factoring. MA 206 Kurt Bryan

8 Square matrices continued: Determinants

Fault Tolerant Matrix-Matrix Multiplication: Correcting Soft Errors On-Line.

What is Linear Programming?

Eigenvalues and Eigenvectors

December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B. KITCHENS

K80TTQ1EP-??,VO.L,XU0H5BY,_71ZVPKOE678_X,N2Y-8HI4VS,,6Z28DDW5N7ADY013

13 MATH FACTS a = The elements of a vector have a graphical interpretation, which is particularly easy to see in two or three dimensions.

AMS526: Numerical Analysis I (Numerical Linear Algebra)

Solving Systems of Linear Equations

Inner Product Spaces

Data Mining: Algorithms and Applications Matrix Math Review

Matrix Differentiation

Lecture 5 Principal Minors and the Hessian

Manifold Learning Examples PCA, LLE and ISOMAP

ECE 842 Report Implementation of Elliptic Curve Cryptography

Lecture 5: Singular Value Decomposition SVD (1)

MATH APPLIED MATRIX THEORY

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

Similarity and Diagonalization. Similar Matrices

Solution to Homework 2

Math 312 Homework 1 Solutions

Lecture notes on linear algebra

Programming Exercise 3: Multi-class Classification and Neural Networks

APP INVENTOR. Test Review

A numerically adaptive implementation of the simplex method

DETERMINANTS TERRY A. LORING

ALGEBRA. sequence, term, nth term, consecutive, rule, relationship, generate, predict, continue increase, decrease finite, infinite

Mathematical finance and linear programming (optimization)

Adaptive Stable Additive Methods for Linear Algebraic Calculations

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes

MATH 304 Linear Algebra Lecture 18: Rank and nullity of a matrix.

Linear Algebra: Vectors

High Performance Matrix Inversion with Several GPUs

Matrix Indexing in MATLAB

Continued Fractions and the Euclidean Algorithm

Transcription:

Logistics Week 1: Wednesday, Aug 22 We will go over the syllabus in the first class, but in general you should look at the class web page at http://www.cs.cornell.edu/~bindel/class/cs6210-f12/ The web page is your source for the syllabus, homework, lecture notes, and course announcements. For materials that are private to the class (e.g. grades and solutions), we will use the Course Management System: http://cms.csuglab.cornell.edu/web/guest/ If you are taking the class for credit or even if you think you may take the class for credit please sign the list and include your Cornell netid. That way, I can add you to the Course Management System. Course Overview CS 6210 is a graduate-level introduction to numerical linear algebra. We will be studying how to solve linear systems, least squares problems, eigenvalue problems, and sinular value problems. Organized by topics, the course looks something like this: 1. Background: linear algebra, memory and performance, error analysis 2. Linear systems and Gaussian elimination; structured linear systems 3. Least squares problems 4. Unsymmetric eigenvalue problems 5. Symmetric eigenvalue problems 6. Iterative methods for linear systems and eigenvalue problems We could also organize the course by four over-arching themes (4A?): 1. Algebra: matrix factorizations and such

2. Analysis: perturbation theory, convergence, error analysis, etc. 3. Algorithms: efficient methods for modern machines. 4. Applications: coming from all over The interplay between these aspects of the subject is a big part of what makes the area so interesting! We could also organize around a few general techniques 1. Matrix factorizations 2. Perturbation theory and condition numbers 3. Floating point arithmetic 4. Complexity analysis 5. Software engineering The point of the next few lectures will be to introduce these themes (4A) and (some of) our techniques in the context of two very simple operations: multiplication of a matrix by a vector, and multiplication of two matrices I will assume that you have already had a course in linear algebra and that you know how to program. It will be helpful if you ve had a previous numerical methods course, though maybe not strictly necessary; talk to me if you feel nervous on this point. The course will involve MATLAB programming, so it will also be helpful but not strictly necessary for you to have prior exposure to MATLAB. If you don t know MATLAB already but you have prior programming experience, you can learn MATLAB quickly enough. There may be some optional or extra credit problems that involve programming in another language, but nothing required. Matrix algebra versus linear algebra 1. Matrices are extremely useful. So are linear transformations. But note that matrices and linear transformations are different things! Matrices represent finite-dimensional linear transformations with respect to particular bases. Change the bases, and you change the matrix, if not the underlying operator. Much of the class will be about finding the right

basis to make some property of the underlying transformation obvious, and about finding changes of basis that are nice for numerical work. 2. A linear transformation may correspond to different matrices deping on the choice of basis, but that doesn t mean the linear transformation is always the thing. For some applications, the matrix itself has meaning, and the associated linear operator is secondary. For example, if I look at an adjacency matrix for a graph, I probably really do care about the matrix not just the linear transformation. 3. Sometimes, we can apply a linear transformation even when we don t have an explicit matrix. For example, suppose F : R n R m, and I want to compute F/ v x0 = ( F (x 0 )) v. Even without an explicit matrix for F, I can compute F/ v x0 F (x 0 + hv) F (x 0 ))/h. There are many other linear transformations, too, for which it is more convenient to apply the transformations than to write down the matrix using the FFT for the Fourier transform operator, for example, or fast multipole methods for relating charges to potentials in an n-body electrostatic interaction. Matrix-vector multiply Let us start with a very simple Matlab program for matrix-vector multiplication: function y = matvec1(a,x) % Form y = A*x (version 1) [m,n] = size(a); y = zeros(m,1); y(i) = y(i) + A(i,j)*x(j); We could just as well have switched the order of the i and j loops to give us a column-oriented rather than row-oriented version of the algorithm. Let s consider these two variants, written more compactly:

function y = matvec2_row(a,x) % Form y = A*x (row-oriented) [m,n] = size(a); y = zeros(m,1); y(i) = A(i,:)*x; function y = matvec2_col(a,x) % Form y = A*x (column-oriented) [m,n] = size(a); y = zeros(m,1); y = y + A(:,j)*x(j); It s not too surprising that the builtin matrix-vector multiply routine in Matlab runs faster than either of our matvec2 variants, but there are some other surprises lurking. Try timing each of these matrix-vector multiply methods for random square matrices of size 4095, 4096, and 4097, and see what happens. Note that you will want to run each code many times so that you don t get lots of measurement noise from finite timer granularity; for example, try tic; % Start timer for i = 1:100 % Do enough trials that it takes some time %... Run experiment here toc % Stop timer Basic matrix-matrix multiply The classic algorithm to compute C := C + AB is

for k = 1:p C(i,j) = C(i,j) + A(i,k)*B(k,j); This is sometimes called an inner product variant of the algorithm, because the innermost loop is computing a dot product between a row of A and a column of B. We can express this concisely in MATLAB as C(i,j) = C(i,j) + A(i,:)*B(:,j); There are also outer product variants of the algorithm that put the loop over the index k on the outside, and thus computing C in terms of a sum of outer products: for k = 1:p C = C + A(:,k)*B(k,:); Blocking and performance The basic matrix multiply outlined in the previous section will usually be at least an order of magnitude slower than a well-tuned matrix multiplication routine. There are several reasons for this lack of performance, but one of the most important is that the basic algorithm makes poor use of the cache. Modern chips can perform floating point arithmetic operations much more quickly than they can fetch data from memory; and the way that the basic algorithm is organized, we sp most of our time reading from memory rather than actually doing useful computations. Caches are organized to take advantage of spatial locality, or use of adjacent memory locations in a short period of program execution; and temporal locality, or re-use of the same memory location in a short period of program execution. The basic matrix multiply organizations don t do well with either of these. A better

organization would let us move some data into the cache and then do a lot of arithmetic with that data. The key idea behind this better organization is blocking. When we looked at the inner product and outer product organizations in the previous sections, we really were thinking about partitioning A and B into rows and columns, respectively. For the inner product algorithm, we wrote A in terms of rows and B in terms of columns a 1,: a 2,:. a m,: [ ] b:,1 b :,2 b :,n, and for the outer product algorithm, we wrote A in terms of colums and B in terms of rows b 1,: b 2,: [ ] a:,1 a :,2 a :,p.. More generally, though, we can think of writing A and B as block matrices: A 11 A 12... A 1,pb A 21 A 22... A 2,pb A =... A mb,1 A mb,2... A mb,p b B 11 B 12... B 1,pb B 21 B 22... B 2,pb B =... B pb,1 B pb,2... B pb,n b where the matrices A ij and B jk are compatible for matrix multiplication. Then we we can write the submatrices of C in terms of the submatrices of A and B C ij = A ij B jk. k b p,: