numerical linear algebra - mgnetmgnet.org/~douglas/classes/cs521/nla/linearalgebra2006.pdf ·...

51
By: David McQuilling; Jesus Caban Deng Li Jan.,31,2006 CS521 Numerical Linear Algebra

Upload: others

Post on 16-Oct-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

By: David McQuilling;Jesus Caban

Deng Li

Jan.,31,2006CS521

Numerical Linear Algebra

Page 2: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Solving Linear Equations

!"

#$%

&=!

"

#$%

&!"

#$%

&

21

8

94

22

v

u

xA b

2194

822

=+

=+

vu

vu

Page 3: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Gaussian Elimination

!"

#$%

&

2194

822

Start with the matrix representation of Ax = b by adding the solution vector bto the matrix A

Now perform Gaussian elimination by row reductions to transform the matrix Ab into an upper triangular matrix that contains the simplified equations.

Find the first multiplier by dividing the first entry in the second row by the firstentry in the first row. This will allow you to transform the first entry in thesecond row to a zero by a row reduction, thus reducing the system ofequations.

Page 4: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Gaussian Elimination (cont.)

2194

!"

#$%

&'!

"

#$%

&

550

822

2194

822

)822(2!

550

Multiply the first row by the multiplier (4 / 2 = 2) and then subtract that fromthe second row to obtain the new reduced equation.

Page 5: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

A = LU

!"

#$%

&=!

"

#$%

&!"

#$%

&!"

#$%

&

21

8

50

22

12

01

v

u

xL cU

The matrix resulting from the Gaussian elimination steps is actually Uconcatenated with the new right hand side c.

L is obtained from the multipliers used in the Gaussian elimination steps.

Page 6: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Solving Ux=c by back substitution

!"

#$%

&=!

"

#$%

&!"

#$%

&

5

8

50

22

v

u

822 =+ vu

822 =+ vu

3=u

62 =u!"

#$%

&=!

"

#$%

&=

1

3

v

ux

U x c

55 =v

1=v

Page 7: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Solution to Ax=b

The solution vector to Ux=c is actually thesolution to the original problem Ax=b.

!"

#$%

&=!

"

#$%

&!"

#$%

&

21

8

94

22

v

u

!"

#$%

&=!

"

#$%

&!"

#$%

&

21

8

1

3

94

22

A x b

Page 8: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Gaussian algorithm to find LU

After this algorithm completes, the diagonal and upper triangle partof A contains U while the lower triangle contains L. This algorithmruns in O(n3) time.

Page 9: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Gram-Schmidt Factorization

Yields the factorization A=QR Starts with n linearly independent vectors in A Constructs n orthonormal vectors

A vector x is orthonormal if xTx = 1 and ||x|| = 1 Any vector is made orthonormal by making it a unit vector in the same

direction, i.e. the length is 1. Dividing a vector x by its length (||x||) creates a unit vector in the direction of x

!!!

"

#

$$$

%

&

=

2

1

2

a 3212|||| 222=++=a

!!!

"

#

$$$

%

&

=

3/2

3/1

3/2

||||/ aa

Page 10: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Composition of Q and R

Q is the matrix with n orthonormal column vectors, which wereobtained from the n linearly independent vectors of A.

Orthonormal columns implies that QTQ = I

R is obtained by multiplying QT on both sides of A = QR

This equation becomes QTA = QTQR = I R = R

R becomes an upper triangular matrix because later q’s are orthogonal toearlier a’s, i.e. their dot product is zero. This creates zeroes in the entriesbelow the main diagonal.

Page 11: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Obtaining Q from A

Start with the first column vector from A and use that as your firstvector q1 for Q (have to make it a unit vector before adding it to Q)

To obtain the second vector q2, subtract from the second vector inA, a2, its projection along the previous qi vectors. The projection of one vector onto another is defined as (xTy / xTx ) x

where the vector y is being projected onto the vector x.

Once all qi have been found this way, divide them by their lengthsso that they are unit vectors. Now those are the orthonormalvectors which make up the columns of Q

Page 12: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Obtaining R from QTA

Once Q has been found, simply multiply A by thetranspose of Q to find R

Overall, the Gram-Schimdt algorithm is O(mn2)for an mxn matrix A.

Page 13: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Eigenvalues and Eigenvectors

Eigenvectors are unique vectors such that whenmultiplied by a matrix A, they do not change theirdirection only their magnitude, i.e. Ax=λx

Eigenvalues are the scalar multiples of the eigenvectors,i.e. the λ’s

Page 14: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Solving for eigenvalues of A

Solving for the eigenvalues involves solving det(A–λI)=0where det(A) is the determinant of the matrix A

For a 2x2 matrix the determinant is a quadratic equation,for larger matrices the equation increases in complexityso lets solve a 2x2

Some interesting properties of eigenvalues are that theproduct of them is equal to the det(A) and the sum ofthem is equal to the trace of A which is the sum of theentries on the main diagonal of A

Page 15: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Solving det(A-λI)=0

!"

#$%

&=

21

23A !

"

#$%

&

'

'='

(

((

21

23IA

451*2)2)(3()det( 2+!=!!!=! """""IA

0452

=+! ""

0)1)(4( =!! ""

41=! 1

2=!

Page 16: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Solving for the eigenvectors

Once you have the eigenvalues, λ’s, you can solve forthe eigenvectors by solving (A-λI)x=0 for each λi

In our example we have two λ’s, so we need to solve fortwo eigenvectors.

Page 17: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Now solve (A-λI)x = 0 for λ=4

0)4( =! xIA

021

21

2

1=!

"

#$%

&!"

#$%

&

'

'

x

x

0221=+! xx

0221=! xx

!"

#$%

&='=2

12

21xxx

Page 18: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Solve (A-λI)x=0 for λ=1

0)( =! xIA

011

22

2

1=!

"

#$%

&!"

#$%

&

x

x

02221=+ xx

021=+ xx

!"

#$%

&

'=('=

1

1

21xxx

Page 19: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Positive definite matrices Positive definite:

all eigenvalues are positive All pivots are positive xTAx > 0 is positive except

at x=0

Applications Ellipse: find the axes of the

a tilted ellipse

122

=++ cybxyax

Page 20: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Cholesky Factorization•Cholesky factorization factors an N*N , symmetric, positive-definitematrix into the product of a lower triangular matrix and its transpose.

•A = LLT

Page 21: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Least Square•It often happens that Ax = b has no solution

•Too many equations (more equations than unknowns)

•When the length of e is as small as possible, x is a least square solution

•Example: Find the closest straight line to three points (0,6), (1,0), and (2,0)•Line: b = C + Dt•We are asking for two numbers C and D that satisfy three equations•No straight line goes through those points•Choose the one that minimize the error

Axbe !=

Page 22: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Matrix Multiplication

Page 23: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Matrix Multiplication Matrix multiplication is commonly used in

graph theory numerical algorithms computer graphics signal processing

Multiplication of large matrices requires a lot ofcomputation time as its complexity is O(n3), where n isthe dimension of the matrix

Most parallel matrix multiplication algorithms use matrixdecomposition based on the number of processorsavailable

Page 24: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Matrix Multiplication

!"

#$%

&=

!!!!

"

#

$$$$

%

&

!"

#$%

&

210184158

908070

121110

987

654

321

8765

4321

Example (a11):

( ) 7010*47*34*21*1

10

7

4

1

432111

=+++=

!!!!!

"

#

$$$$$

%

&

=a

Page 25: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Sequential Matrix Multiplication

The product C of the two matrices A and B isdefined by

kj

n

k

ikij bac !="#

=

1

0

aij, bij, and cij is the element in ith row and jth column ofthe matrix A, B, and C respectively.

Page 26: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Practice:

Make a example for A=LU(2x2), show meL and U.

Page 27: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Strassen’s Algorithm

The Strassen’s algorithm is a sequentialalgorithm reduced the complexity of matrixmultiplication algorithm to O(n2.81).

In this algorithm, n × n matrix is divided into 4n/2 × n/2 sub-matrices and multiplication is donerecursively by multiplying n/2 × n/2 matrices.

Page 28: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Parallel Matrix Partitioning

Parallel computers can be used to process largematrices.

In order to process a matrix in parallel, it is necessary topartition the matrix so that the different partitions can bemapped to different processors.

Partitions: Block row-wise/column-wise striping Cyclic row-wise/colum-wise striping Block checkerboard striping Cyclic checkerboard

Page 29: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Striped Partitioning

Matrix is divided into groups of complete rows orcolumns, and each processor is assigned one suchgroup.

Striped Partitioning Block-Striped: each processor is assigned

contiguous rows or columns Cyclic-Striped: is when rows or columns are

sequentially assigned to processors in awraparound manner.

Page 30: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Block Stripping(Application examples: (a) is in the case of car front crash,(b) is in the case of car side crash simulation.)

From: http://www.iitk.ac.in/cc/param/tpday21.html

Page 31: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Checkerboard Partition The matrix is divided into smaller square or

rectangular blocks or sub-matrices that aredistributed among processors

Checkerboard Partitioning Block-Checkerboard: partitioning splits both the

rows and the columns of the matrix, so no processoris assigned any complete row or column .

Cyclic-Checkerboard: when it wraparound.

Page 32: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Checkerboard Partitioning

From: http://www.iitk.ac.in/cc/param/tpday21.html

Page 33: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Parallel Matrix-Vector Product Algorithm:

For each processor I Broadcast X(i) Compute A(i)*x

A(i) refers to the n by n/p block row that processor i owns Algorithm uses the formula

Y(i) = Y(i) + A(i)*X = Y(i) + Σj A(i)*X(j)

Page 34: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Parallel Matrix Multiplication

Algorithms: systolic algorithm Cannon's algorithm Fox and Otto's algorithm PUMMA (Parallel Universal Matrix Multiplication) SUMMA (Scalable Universal Matrix Multiplication) DIMMA (Distribution Independent Matrix

Multiplication)

Page 35: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Systolic Communication

Communication designwhere the data exchangeand communicationoccurs between thenearest-neighbors.

From: http://www-unix.mcs.anl.gov

Page 36: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Matrix Decomposition

To implement the matrix multiplication, the A andB matrices are decomposed into several sub-matrices.

Four methods of matrix decomposition anddistribution: one-dimensional decomposition two-dimensional

square decomposition general decomposition scattered decomposition.

Page 37: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

One-dimensional Decomposition

The matrix is horizontallydecomposed. The ith processorholds ith Asub and Bsub andcommunicates them to two neighborprocessors, i.e., to the (i-1)th and(i+1)th processors.

The first and last processorcommunicate with each other as in aring topology.

p0 p1 p2 p3 p5p4 p6 p7

Page 38: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Two-Dimensional Decomposition

Square decomposition: The two-dimensional square decompositionMatrix is decomposed into squareprocessor template.

General decomposition: GeneralTwo-Dimensional Decompositionallow having 2*3, 4*3, etc.configurations.

Page 39: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Two-Dimensional Decomposition

Scattered decomposition: thematrix is divided into several setsof blocks. Each set of blockscontains as many elements asthe number of processors, andevery element in a set of blocks isscattered according to the two-dimensional processor templates.

Page 40: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Applications

Page 41: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Computer Graphics In computer graphics all the transformation are

represented as matrices and a set of transformations asa matrix multiplication.

Transformations: Rotation Translation Scaling Shearing

X Rotation

© Pixar

Page 42: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

2D/3D Mesh

•Laplacian matrix L(G) of the graph G

•If you take the eigenvalues andeigenvectors of L(G), you can getinteresting properties as vibration ofthe graph.

From: http://www.cc.gatech.edu/

Page 43: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Computer VisionIn computer vision we can calibrate a camera to determine the relationshipbetween what appears on the image (or retinal) plane and where it islocated in the 3D world by using and representing the parameters asmatrices and vectors.

Page 44: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Software for NumericalLinear Algebra

Page 45: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

LAPACK

LAPACK: Routines for solving systems ofsimultaneous linear equations, least-squaressolutions of linear systems of equations,eigenvalue problems, and singular valueproblems.

Link:http://www.netlib.org/lapack/

Page 46: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

LINPACK

LINPACK is a collection of Fortran subroutinesthat analyze and solve linear equations andlinear least-squares problems. The packagesolves linear systems whose matrices aregeneral, banded, symmetric indefinite,symmetric positive definite, triangular, and tri-diagonal square.

Link:http://www.netlib.org/linpack/

Page 47: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

ATLAS ATLAS (Automatically Tuned Linear Algebra

Software) provides portable performance andhighly optimized Linear Algebra kernels forarbitrary cache-based architectures.

Link:https://sourceforge.net/projects/math-atlas/

Page 48: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

MathWorks

MATLAB: provideengineers, scientists,mathematicians, andeducators with anenvironment for technicalcomputing applications

Page 49: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

NAG

NAG Numerical Library:solve complex problems inareas such as research,engineering, life and earthsciences, financial analysisand data mining .

Page 50: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

NMath Matrix

NMath Matrix is an advanced matrix manipulationlibrary. Full-featured structured sparse matrixclasses, including triangular, symmetric, Hermitian,banded, tridiagonal, symmetric banded, andHermitian banded.

Page 51: Numerical Linear Algebra - MGNetmgnet.org/~douglas/Classes/cs521/nla/LinearAlgebra2006.pdf · Strassen’s Algorithm The Strassen’s algorithm is a sequential algorithm reduced the

Nastran

program participates in NASA-sponsored projectto develop a unified approach to computerizedstructural analysis. The program became knownas NASTRAN (NASA Structural AnalysisProgram).

NX Nastran, http://www.ugs.com/index.shtml MSC Nastran http://www.mscsoftware.com/