Solving Linear System of Equations The Undo button for Linear - - PowerPoint PPT Presentation

โ–ถ
solving linear system of equations the undo button for
SMART_READER_LITE
LIVE PREVIEW

Solving Linear System of Equations The Undo button for Linear - - PowerPoint PPT Presentation

Solving Linear System of Equations The Undo button for Linear Operations Matrix-vector multiplication: given the data and the operator , we can find such that = transformation What if we know


slide-1
SLIDE 1

Solving Linear System of Equations

slide-2
SLIDE 2

The โ€œUndoโ€ button for Linear Operations

Matrix-vector multiplication: given the data ๐’š and the operator ๐‘ฉ, we can find ๐’› such that ๐’› = ๐‘ฉ ๐’š What if we know ๐’› but not ๐’š? How can we โ€œundoโ€ the transformation?

๐’š ๐’› ๐‘ฉ

transformation

๐’› ๐’š ๐‘ฉ!๐Ÿ ?

Solve ๐‘ฉ ๐’š = ๐’› for ๐’š

slide-3
SLIDE 3

Image Blurring Example

  • Image is stored as a 2D array of real numbers between 0 and 1

(0 represents a white pixel, 1 represents a black pixel)

  • ๐’š๐’๐’ƒ๐’– has 40 rows of pixels and 100 columns of pixels
  • Flatten the 2D array as a 1D array
  • ๐’š contains the 1D data with dimension 4000,
  • Apply blurring operation to data ๐’š, i.e.

๐’„ = ๐‘ฉ ๐’š where ๐‘ฉ is the blur operator and ๐’„ is the blurred image

slide-4
SLIDE 4

Blur operator

๐’„ = ๐‘ฉ ๐’š

"originalโ€ image (4000,) blurred image (4000,) Blur operator (4000,4000) Blur operator

๐’š ๐’„

๐‘ฉ

slide-5
SLIDE 5

โ€Undoโ€ Blur to recover original image

Solve ๐‘ฉ ๐’š = ๐’„ for ๐’š Assumptions:

  • 1. we know the blur
  • perator ๐‘ฉ
  • 2. the data set ๐’„ does not

have any noise (โ€œclean dataโ€ What happens if we add some noise to ๐’„? ๐’š ๐’„

slide-6
SLIDE 6

โ€Undoโ€ Blur to recover original image

Solve ๐‘ฉ ๐’š = ๐’› for ๐’š

๐’› + ๐‘ โˆ— 10!" (๐‘ โˆˆ 0,1 ) How much noise can we add and still be able to recover meaningful information from the original image? At which point this inverse transformation fails? We will talk about sensitivity of the โ€œundoโ€ operation later. ๐’› + ๐‘ โˆ— 10!# (๐‘ โˆˆ 0,1 )

slide-7
SLIDE 7

Linear System of Equations

We can start with an โ€œeasierโ€ system of equationsโ€ฆ How do we actually solve ๐‘ฉ ๐’š = ๐’„ ? Letโ€™s consider triangular matrices (lower and upper):

๐‘€!! ๐‘€"! ๐‘€"" โ€ฆ โ€ฆ โ‹ฎ โ‹ฎ ๐‘€#! ๐‘€#" โ‹ฑ โ‹ฎ โ€ฆ ๐‘€## ๐‘ฆ! ๐‘ฆ" โ‹ฎ ๐‘ฆ# = ๐‘ ๐‘" โ‹ฎ ๐‘# ๐‘‰!! ๐‘‰!" ๐‘‰"" โ€ฆ ๐‘‰!# โ€ฆ ๐‘‰"# โ‹ฎ โ‹ฎ โ‹ฑ โ‹ฎ โ€ฆ ๐‘‰## ๐‘ฆ! ๐‘ฆ" โ‹ฎ ๐‘ฆ# = ๐‘ ๐‘" โ‹ฎ ๐‘#

slide-8
SLIDE 8

2 3 2 1 2 1 3 6 4 2 ๐‘ฆ! ๐‘ฆ" ๐‘ฆ# ๐‘ฆ$ = 2 2 6 4

Example: Forward-substitution for lower triangular systems

2 ๐‘ฆ$ = 2 โ†’ ๐‘ฆ$= 1 3 ๐‘ฆ$ + 2 ๐‘ฆ% = 2 โ†’ ๐‘ฆ%= 2 โˆ’ 3 2 = โˆ’0.5 1 ๐‘ฆ$ + 2 ๐‘ฆ% + 6 ๐‘ฆ& = 6 โ†’ ๐‘ฆ&= 6 โˆ’ 1 + 1 6 = 1.0 1 ๐‘ฆ$ + 3 ๐‘ฆ% + 4 ๐‘ฆ& + 2 ๐‘ฆ# = 4 โ†’ ๐‘ฆ&= 4 โˆ’ 1 + 1.5 โˆ’ 4 2 = 0.25

๐‘ฆ! ๐‘ฆ" ๐‘ฆ# ๐‘ฆ$ = 1 โˆ’0.5 1.0 0.25

slide-9
SLIDE 9

Example: Backward-substitution for upper

triangular systems

2 8 4 4 2 4 3 6 2 2 ๐‘ฆ! ๐‘ฆ" ๐‘ฆ$ ๐‘ฆ% = 2 4 4 1

๐‘ฆ# = 1 2 ๐‘ฆ& = 4 โˆ’ 2 1 2 6 = 1 2 ๐‘ฆ% = 4 โˆ’ 4 1 2 โˆ’ 3 1 2 4 = 1/2 4 = 1 8 ๐‘ฆ$ = 2 โˆ’ 8 1 8 โˆ’ 4 1 2 โˆ’ 2 1 2 2 = โˆ’2 2 = โˆ’1

slide-10
SLIDE 10

LU Factorization

How do we solve ๐‘ฉ ๐’š = ๐’„ when ๐‘ฉ is a non-triangular matrix? We can perform LU factorization: given a ๐‘œร—๐‘œ matrix ๐‘ฉ,

  • btain lower triangular matrix ๐‘ด and upper triangular matrix

๐‘ฝ such that where we set the diagonal entries of ๐‘ด to be equal to 1.

๐‘ฉ = ๐‘ด๐‘ฝ

1 ๐‘€"! 1 โ€ฆ โ€ฆ โ‹ฎ โ‹ฎ ๐‘€#! ๐‘€#" โ‹ฑ โ‹ฎ โ€ฆ 1 ๐‘‰!! ๐‘‰!" ๐‘‰"" โ€ฆ ๐‘‰!# โ€ฆ ๐‘‰"# โ‹ฎ โ‹ฎ โ‹ฑ โ‹ฎ โ€ฆ ๐‘‰## = ๐ต!! ๐ต!" ๐ต"! ๐ต"" โ€ฆ ๐ต!# โ€ฆ ๐ต"# โ‹ฎ โ‹ฎ ๐ต#! ๐ต#" โ‹ฑ โ‹ฎ โ€ฆ ๐ต##

slide-11
SLIDE 11

LU Factorization

1 ๐‘€"! 1 โ€ฆ โ€ฆ โ‹ฎ โ‹ฎ ๐‘€#! ๐‘€#" โ‹ฑ โ‹ฎ โ€ฆ 1 ๐‘‰!! ๐‘‰!" ๐‘‰"" โ€ฆ ๐‘‰!# โ€ฆ ๐‘‰"# โ‹ฎ โ‹ฎ โ‹ฑ โ‹ฎ โ€ฆ ๐‘‰## = ๐ต!! ๐ต!" ๐ต"! ๐ต"" โ€ฆ ๐ต!# โ€ฆ ๐ต"# โ‹ฎ โ‹ฎ ๐ต#! ๐ต#" โ‹ฑ โ‹ฎ โ€ฆ ๐ต## Assuming the LU factorization is know, we can solve the general system

slide-12
SLIDE 12

LU Factorization (with pivoting)

๐‘ธ๐‘ด๐‘ฝ ๐’š = ๐’„ ๐‘ด ๐’› = ๐‘ธ๐‘ผ๐’„

Forward-substitution

๐‘ฝ ๐’š = ๐’›

(Solve for ๐’›) Backward-substitution (Solve for ๐’š)

๐‘ฉ = ๐‘ธ๐‘ด๐‘ฝ

Factorize:

๐’›

slide-13
SLIDE 13

Example

๐‘ฝ = 2 8 โˆ’2 4 1 1 2.5 3 โˆ’1 0.75 ๐‘ด = 1 0.5 1 0.5 1 0.5 0.5 1 0.5 1

Assume the ๐‘ฉ = ๐‘ด๐‘ฝ factorization is known, yielding: Determine the solution ๐’š that satisfies ๐‘ฉ๐’š = ๐’„, when ๐’„ = 2 2 1 4 First, solve the lower-triangular system ๐‘ด ๐’› = ๐’„ for the variable ๐’› ๐‘ด ๐‘ฝ๐’š = ๐’„

๐’›

Then, solve the upper-triangular system ๐‘ฝ ๐’š = ๐’› for the variable ๐’š

1 0.5 1 0.5 1 0.5 0.5 1 0.5 1 ๐’› = 2 2 1 4 2 8 โˆ’2 4 1 1 2.5 3 โˆ’1 0.75 ๐’š = 2 1 โˆ’1 3

slide-14
SLIDE 14

Methods to solve linear system of equations

๐‘ฉ ๐’š = ๐’„

  • LU
  • Cholesky
  • Sparse
slide-15
SLIDE 15

LU Factorization - Algorithm

slide-16
SLIDE 16

2x2 LU Factorization (simple example)

๐ต!! ๐ต!" ๐ต"! ๐ต"" = 1 ๐‘€"! 1 ๐‘‰!! ๐‘‰!" ๐‘‰""

๐ต!! ๐ต!" ๐ต"! ๐ต"" = ๐‘‰!! ๐‘‰!" ๐‘€"!๐‘‰!! ๐‘€"!๐‘‰!" + ๐‘‰""

slide-17
SLIDE 17

LU Factorization

๐ต!! ๐ต!" ๐ต"! ๐ต"" โ€ฆ ๐ต!# โ€ฆ ๐ต"# โ‹ฎ โ‹ฎ ๐ต#! ๐ต#" โ‹ฑ โ‹ฎ โ€ฆ ๐ต## = ๐‘!! ๐’ƒ!" ๐’ƒ"! ๐‘ฉ"" = 1 ๐Ÿ ๐’Ž"! ๐‘ด"" ๐‘ฃ!! ๐’—!" ๐Ÿ ๐‘ฝ""

๐‘$$ ๐’ƒ$% ๐’ƒ%$ ๐‘ฉ%% ๐‘$$: scalar ๐’ƒ$%: row vector (1ร—(๐‘œ โˆ’ 1)) ๐’ƒ%$: column vector (๐‘œ โˆ’ 1)ร—1 ๐‘ฉ%%: matrix (๐‘œ โˆ’ 1)ร—(๐‘œ โˆ’ 1)

๐‘!! ๐’ƒ!" ๐’ƒ"! ๐‘ฉ"" = ๐‘ฃ!! ๐’—!" ๐‘ฃ!! ๐’Ž"! ๐’Ž"!๐’—!" + ๐‘ด""๐‘ฝ""

slide-18
SLIDE 18

LU Factorization

๐ต!! ๐ต!" ๐ต"! ๐ต"" โ€ฆ ๐ต!# โ€ฆ ๐ต"# โ‹ฎ โ‹ฎ ๐ต#! ๐ต#" โ‹ฑ โ‹ฎ โ€ฆ ๐ต## = ๐‘!! ๐’ƒ!" ๐’ƒ"! ๐‘ฉ"" = 1 ๐Ÿ ๐’Ž"! ๐‘ด"" ๐‘ฃ!! ๐’—!" ๐Ÿ ๐‘ฝ""

๐‘$$ ๐’ƒ$% ๐’ƒ%$ ๐‘ฉ%% ๐‘$$: scalar ๐’ƒ$%: row vector (1ร—(๐‘œ โˆ’ 1)) ๐’ƒ%$: column vector (๐‘œ โˆ’ 1)ร—1 ๐‘ฉ%%: matrix (๐‘œ โˆ’ 1)ร—(๐‘œ โˆ’ 1)

๐‘!! ๐’ƒ!" ๐’ƒ"! ๐‘ฉ"" = ๐‘ฃ!! ๐’—!" ๐‘ฃ!! ๐’Ž"! ๐’Ž"!๐’—!" + ๐‘ด""๐‘ฝ""

1) First row of ๐‘ฝ is the first row of ๐‘ฉ 2) ๐’Ž<= = =

%!! ๐’ƒ<=

3) ๐‘ต = ๐‘ด""๐‘ฝ"" = ๐‘ฉ"" โˆ’ ๐’Ž"!๐’—!" Need another factorization!

Known!

First column of ๐‘ด is the first column of ๐‘ฉ/ ๐‘ฃ==

slide-19
SLIDE 19

Example

๐‘ต = 2 8 1 2 4 1 3 3 1 2 1 3 6 2 4 2 ๐‘ฝ = 2 8 4 1 ๐‘ด = 1 0.5 0.5 0.5

1) First row of ๐‘ฝ is the first row of ๐‘ฉ 2) First column of ๐‘ด is the first column of ๐‘ฉ/ ๐‘ฃ==

3) ๐‘ด""๐‘ฝ"" = ๐‘ฉ"" โˆ’ ๐’Ž"!๐’—!"

๐‘ด%%๐‘ฝ%% = ๐‘ฉ%% โˆ’ ๐’Ž%$๐’—$% = 2 3 3 2 3 6 2 4 2 โˆ’ 4 2 0.5 4 4 2 0.5 2 0.5

๐‘ต = 2 8 1 โˆ’2 4 1 1 2.5 1 โˆ’2 1 โˆ’1 4 1.5 2 1.5

slide-20
SLIDE 20

๐‘ต = 2 8 1 โˆ’2 4 1 1 2.5 1 โˆ’2 1 โˆ’1 4 1.5 2 1.5 ๐‘ฝ = 2 8 โˆ’2 4 1 1 2.5 ๐‘ด = 1 0.5 1 0.5 1 0.5 0.5

๐‘ด%%๐‘ฝ%% = ๐‘ฉ%% โˆ’ ๐’Ž%$๐’—$% = 4 1.5 2 1.5 โˆ’ 1 2.5 0.5 1.25

๐‘ต = 2 8 1 โˆ’2 4 1 1 2.5 1 โˆ’2 1 โˆ’1 3 โˆ’1 1.5 0.25

slide-21
SLIDE 21

๐‘ต = 2 8 1 โˆ’2 4 1 1 2.5 1 โˆ’2 1 โˆ’1 3 โˆ’1 1.5 0.25 ๐‘ฝ = 2 8 โˆ’2 4 1 1 2.5 3 โˆ’1 ๐‘ด = 1 0.5 1 0.5 1 0.5 0.5 1 0.5

๐‘ด%%๐‘ฝ%% = ๐‘ฉ%% โˆ’ ๐’Ž%$๐’—$% = 0.25 โˆ’ โˆ’0.5 = 0.75

๐‘ฝ = 2 8 โˆ’2 4 1 1 2.5 3 โˆ’1 0.75 ๐‘ด = 1 0.5 1 0.5 1 0.5 0.5 1 0.5 1

slide-22
SLIDE 22

LU Factorization

๐ต!! ๐ต!" ๐ต"! ๐ต"" โ€ฆ ๐ต!# โ€ฆ ๐ต"# โ‹ฎ โ‹ฎ ๐ต#! ๐ต#" โ‹ฑ โ‹ฎ โ€ฆ ๐ต## = ๐‘!! ๐’ƒ!" ๐’ƒ"! ๐‘ฉ"" = 1 ๐Ÿ ๐’Ž"! ๐‘ด"" ๐‘ฃ!! ๐’—!" ๐Ÿ ๐‘ฝ""

๐‘$$ ๐’ƒ$% ๐’ƒ%$ ๐‘ฉ%% ๐‘$$: scalar ๐’ƒ$%: row vector (1ร—(๐‘œ โˆ’ 1)) ๐’ƒ%$: column vector (๐‘œ โˆ’ 1)ร—1 ๐‘ฉ%%: matrix (๐‘œ โˆ’ 1)ร—(๐‘œ โˆ’ 1)

๐‘!! ๐’ƒ!" ๐’ƒ"! ๐‘ฉ"" = ๐‘ฃ!! ๐’—!" ๐‘ฃ!! ๐’Ž"! ๐’Ž"!๐’—!" + ๐‘ด""๐‘ฝ""

1) First row of ๐‘ฝ is the first row of ๐‘ฉ 2) ๐’Ž<= = =

%!! ๐’ƒ<=

3) ๐‘ต = ๐‘ด""๐‘ฝ"" = ๐‘ฉ"" โˆ’ ๐’Ž"!๐’—!" Need another factorization!

Known!

First column of ๐‘ด is the first column of ๐‘ฉ/ ๐‘ฃ==

slide-23
SLIDE 23

Cost of solving linear system of equations

slide-24
SLIDE 24

Cost of solving triangular systems

๐‘ฆ&= ๐‘& โˆ’ โˆ‘'(&)!

*

๐‘‰&'๐‘ฆ' ๐‘‰&& , ๐‘— = ๐‘œ โˆ’ 1, ๐‘œ โˆ’ 2, โ€ฆ , 1 ๐‘ฆ* = ๐‘*/๐‘‰**

slide-25
SLIDE 25

Cost of solving triangular systems

๐‘ฆ&= ๐‘& โˆ’ โˆ‘'(&)!

*

๐‘‰&'๐‘ฆ' ๐‘‰&& , ๐‘— = ๐‘œ โˆ’ 1, ๐‘œ โˆ’ 2, โ€ฆ , 1 ๐‘ฆ* = ๐‘*/๐‘‰**

๐‘œ divisions ๐‘œ ๐‘œ โˆ’ 1 /2 subtractions/additions ๐‘œ ๐‘œ โˆ’ 1 /2 multiplications

Computational complexity is ๐‘ƒ(๐‘œ")

๐‘œ divisions ๐‘œ ๐‘œ โˆ’ 1 /2 subtractions/additions ๐‘œ ๐‘œ โˆ’ 1 /2 multiplications

Computational complexity is ๐‘ƒ(๐‘œ")

๐‘ฆ&= ๐‘& โˆ’ โˆ‘'(!

&+! ๐‘€&'๐‘ฆ'

๐‘€&& , ๐‘— = 2,3, โ€ฆ , ๐‘œ ๐‘ฆ! = ๐‘!/๐‘€!!

slide-26
SLIDE 26

Cost of LU factorization

&

"#$ %

๐‘— = 1 2 ๐‘› ๐‘› + 1 &

"#$ %

๐‘—& = 1 6 ๐‘› ๐‘› + 1 2๐‘› + 1

Side note:

slide-27
SLIDE 27

Solving linear systems

In general, we can solve a linear system of equations following the steps: 1) Factorize the matrix ๐‘ฉ : ๐‘ฉ = ๐‘ด๐‘ฝ (complexity ๐‘ƒ(๐‘œC))

2) Solve ๐‘ด ๐’› = ๐’„ (complexity ๐‘ƒ(๐‘œ<))

3) Solve ๐‘ฝ ๐’š = ๐’› (complexity ๐‘ƒ(๐‘œ<))

But why should we decouple the factorization from the actual solve? (Remember from Linear Algebra, Gaussian Elimination does not decouple these two stepsโ€ฆ)

slide-28
SLIDE 28

Example

Letโ€™s assume that when solving the system of equations ๐‘ณ ๐‘ฝ = ๐‘ฎ, we observe the following:

  • When the matrix ๐‘ณ has dimensions (100,100), computing the LU factorization takes

about 1 second and each solve (forward + backward substitution) takes about 0.01 seconds. Estimate the total time it will take to find the response ๐‘ฝ corresponding to 10 different vectors ๐‘ฎ when the matrix ๐‘ณ has dimensions (1000,1000)? ๐ต) ~10 ๐‘ก๐‘“๐‘‘๐‘๐‘œ๐‘’๐‘ก ๐ถ) ~10" ๐‘ก๐‘“๐‘‘๐‘๐‘œ๐‘’๐‘ก ๐ท) ~10# ๐‘ก๐‘“๐‘‘๐‘๐‘œ๐‘’๐‘ก ๐ธ) ~10$ ๐‘ก๐‘“๐‘‘๐‘๐‘œ๐‘’๐‘ก ๐น) ~10, ๐‘ก๐‘“๐‘‘๐‘๐‘œ๐‘’๐‘ก

slide-29
SLIDE 29

LU Factorization with pivoting

slide-30
SLIDE 30

What can go wrong with the previous algorithm for LU factorization?

๐‘ต = 2 8 1 ๐Ÿ“ 4 1 3 3 1 2 1 3 6 2 4 2 ๐‘ฝ = 2 8 4 1 ๐‘ด = 1 0.5 0.5 0.5 ๐‘ต โˆ’ ๐’Ž"!๐’—!" = 2 8 1 ๐Ÿ 4 1 1 2.5 1 โˆ’2 1 โˆ’1 4 1.5 2 1.5 ๐’Ž"!๐’—!" = 4 2 0.5 4 2 0.5 4 2 0.5

The next update for the lower triangular matrix will result in a division by zero! LU factorization fails. What can we do to get something like an LU factorization?

slide-31
SLIDE 31

Pivoting

Approach:

  • 1. Swap rows if there is a zero entry in the diagonal
  • 2. Even better idea: Find the largest entry (by absolute value) and

swap it to the top row. The entry we divide by is called the pivot. Swapping rows to get a bigger pivot is called (partial) pivoting.

๐‘!! ๐’ƒ!" ๐’ƒ"! ๐‘ฉ"" = ๐‘ฃ!! ๐’—!" ๐‘ฃ!! ๐’Ž"! ๐’Ž"!๐’—!" + ๐‘ด""๐‘ฝ"" Find the largest entry (in magnitude)