27
Lecture 8: Fast Linear Solvers (Part 3) 1

Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

Lecture 8: Fast Linear Solvers (Part 3)

1

Page 2: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

Cholesky Factorization

• Matrix 𝐴 is symmetric if 𝐴 = 𝐴𝑇.

• Matrix 𝐴 is positive definite if for all 𝒙 ≠ 𝟎, 𝒙𝑇𝑨𝒙 > 0.

• A symmetric positive definite matrix 𝐴 has Cholesky factorization 𝐴 = 𝐿𝐿𝑇, where 𝐿 is a lower triangular matrix with positive diagonal entries.

• Example.

– 𝐴 = 𝐴𝑇 with 𝑎𝑖𝑖 > 0 and 𝑎𝑖𝑖 > |𝑎𝑖𝑗|𝑗≠𝑖 is positive definite.

2

Page 3: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

𝐴 =

𝑎11 𝑎12 … 𝑎1𝑛𝑎12 𝑎22 … 𝑎2𝑛⋮

𝑎1𝑛

⋮𝑎2𝑛

⋱…

⋮𝑎𝑛𝑛

=

𝑙11 0 … 0𝑙21 𝑙22 … 0⋮𝑙𝑛1

⋮𝑙𝑛2

⋱…

⋮𝑙𝑛𝑛

𝑙11 𝑙21 … 𝑙𝑛10 𝑙22 … 𝑙𝑛2⋮0

⋮0

⋱…

⋮𝑙𝑛𝑛

3

Page 4: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

In 2 × 2 matrix size case 𝑎11 𝑎21𝑎21 𝑎22

=𝑙11 0𝑙21 𝑙22

𝑙11 𝑙210 𝑙22

𝑙11 = 𝑎11; 𝑙21 = 𝑎21/𝑙11; 𝑙22 = 𝑎22 − 𝑙212

4

Page 5: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

Submatrix Cholesky Factorization Algorithm

5

for 𝑘 = 1 to 𝑛 𝑎𝑘𝑘 = 𝑎𝑘𝑘 for 𝑖 = 𝑘 + 1 to 𝑛 𝑎𝑖𝑘 = 𝑎𝑖𝑘/𝑎𝑘𝑘 end for 𝑗 = 𝑘 + 1 to 𝑛 // reduce submatrix for 𝑖 = 𝑗 to 𝑛 𝑎𝑖𝑗 = 𝑎𝑖𝑗 − 𝑎𝑖𝑘𝑎𝑗𝑘

end end end

Equivalent to 𝑎𝑖𝑘𝑎𝑘𝑗 due

to symmetry

Page 6: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

6

Remark:

1. This is a variation of Gaussian Elimination algorithm.

2. Storage of matrix 𝐴 is used to hold matrix 𝐿 .

3. Only lower triangle of 𝐴 is used (See 𝑎𝑖𝑗 = 𝑎𝑖𝑗 − 𝑎𝑖𝑘𝑎𝑗𝑘).

4. Pivoting is not needed for stability.

5. About 𝑛3/6 multiplications and about 𝑛3/6 additions are required.

Data Access Pattern

Read only

Read and write

Page 7: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

Column Cholesky Factorization Algorithm

7

for 𝑗 = 1 to 𝑛 for 𝑘 = 1 to 𝑗 − 1 for 𝑖 = 𝑗 to 𝑛 𝑎𝑖𝑗 = 𝑎𝑖𝑗 − 𝑎𝑖𝑘𝑎𝑗𝑘

end end 𝑎𝑗𝑗 = 𝑎𝑗𝑗

for 𝑖 = 𝑗 + 1 to 𝑛 𝑎𝑖𝑗 = 𝑎𝑖𝑗/𝑎𝑗𝑗

end end

Page 8: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

Data Access Pattern

8

Read only

Read and write

Page 9: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

Parallel Algorithm

• Parallel algorithms are similar to those for LU factorization.

9

References • X. S. Li and J. W. Demmel, SuperLU_Dist: A scalable

distributed-memory sparse direct solver for unsymmetric linear systems, ACM Trans. Math. Software 29:110-140, 2003

• P. Hénon, P. Ramet, and J. Roman, PaStiX: A high-performance parallel direct solver for sparse symmetric positive definite systems, Parallel Computing 28:301-321, 2002

Page 10: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

QR Factorization and HouseHolder Transformation

Theorem Suppose that matrix 𝐴 is an 𝑚 × 𝑛 matrix with linearly independent columns, then 𝐴 can be factored as 𝐴 = 𝑄𝑅

where 𝑄 is an 𝑚 × 𝑛 matrix with orthonormal columns and 𝑅 is an invertible 𝑛 × 𝑛 upper triangular matrix.

10

Page 11: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

QR Factorization by Gram-Schmidt Process

Consider matrix 𝐴 = [𝒂1 𝒂2 … |𝒂𝑛]

Then,

𝒖1 = 𝒂1, 𝒒1 =𝒖1

||𝒖1||

𝒖2 = 𝒂2 − (𝒂2 ∙ 𝒒1)𝒒1, 𝒒2 =𝒖2

||𝒖2||

𝒖𝑘 = 𝒂𝑘 − 𝒂𝑘 ∙ 𝒒1 𝒒1 −⋯− 𝒂𝑘 ∙ 𝒒𝑘−1 𝒒𝑘−1, 𝒒𝑘 =𝒖𝑘

||𝒖𝑘||

𝐴 = 𝒂1 𝒂2 … 𝒂𝑛

= 𝒒1 𝒒2 … 𝒒𝑛

𝒂1 ∙ 𝒒1 𝒂2 ∙ 𝒒1 … 𝒂𝑛 ∙ 𝒒1

0 𝒂2 ∙ 𝒒2 … 𝒂𝑛 ∙ 𝒒2

⋮ ⋮ ⋱ ⋮0 0 … 𝒂𝑛 ∙ 𝒒𝑛

= 𝑄𝑅

11

Page 12: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

Classical/Modified Gram-Schmidt Process

for j=1 to n

𝒖𝑗 = 𝒂𝑗

for i = 1 to j-1

𝑟𝑖𝑗 = 𝒒𝑖

∗𝒂𝑗 (𝐶𝑙𝑎𝑠𝑠𝑖𝑐𝑎𝑙)

𝑟𝑖𝑗 = 𝒒𝑖∗𝒖𝑗 (𝑀𝑜𝑑𝑖𝑓𝑖𝑒𝑑)

𝒖𝑗 = 𝒖𝑗 − 𝑟𝑖𝑗𝒒𝑖

endfor

𝑟𝑗𝑗 = ||𝒖𝑗||2

𝒒𝑗 = 𝒖𝑗/𝑟𝑗𝑗

endfor 12

Page 13: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

Householder Transformation

Let 𝑣 ∈ 𝑅𝑛 be a nonzero vector, the 𝑛 × 𝑛 matrix

𝐻 = 𝐼 − 2𝒗𝒗𝑇

𝒗𝑇𝒗

is called a Householder transformation (or reflector).

• Alternatively, let 𝒖 = 𝒗/||𝒗||, 𝐻 can be rewritten as

𝐻 = 𝐼 − 2𝒖𝒖𝑇.

Theorem. A Householder transformation 𝐻 is symmetric and orthogonal, so 𝐻 = 𝐻𝑇 = 𝐻−1.

13

Page 14: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

1. Let vector 𝒛 be perpendicular to 𝒗.

𝐼 − 2𝒗𝒗𝑇

𝒗𝑇𝒗𝒛 = 𝒛 − 2

𝒗(𝒗𝑇𝒛)

𝒗𝑇𝒗= 𝒛

2. Let 𝒖 =𝒗

| 𝒗 |. Any vector 𝒙 can be written as

𝒙 = 𝒛 + 𝒖𝑇𝒙 𝒖. 𝐼 − 2𝒖𝒖𝑇 𝒙 = 𝐼 − 2𝒖𝒖𝑇 𝒛 + 𝒖𝑇𝒙 𝒖 = 𝒛 − 𝒖𝑇𝒙 𝒖

14

Page 15: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

• Householder transformation is used to selectively zero out blocks of entries in vectors or columns of matrices.

• Householder is stable with respect to round-off error.

15

Page 16: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

For a given a vector 𝒙, find a Householder

transformation, 𝐻, such that 𝐻𝒙 = 𝑎

10⋮0

= 𝑎𝒆1

– Previous vector reflection (case 2) implies that vector 𝒖 is in parallel with 𝒙 − 𝐻𝒙.

– Let 𝒗 = 𝒙 − 𝐻𝒙 = 𝒙 − 𝑎𝒆1, where 𝑎 = ±| 𝒙 | (when the arithmetic is exact, sign does not matter).

– 𝒖 = 𝒗/|| 𝒗||

– In the presence of round-off error, use

𝒗 = 𝒙 + 𝑠𝑖𝑔𝑛 𝑥1 | 𝒙 |𝒆1

to avoid catastrophic cancellation. Here 𝑥1 is the first entry in the vector 𝒙.

Thus in practice, 𝑎 = −𝑠𝑖𝑔𝑛 𝑥1 | 𝒙 | 16

Page 17: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

Algorithm for Computing the Householder Transformation

17

𝑥𝑚 = max { 𝑥1 , 𝑥2 , … , 𝑥𝑛 } for 𝑘 = 1 to 𝑛 𝑣𝑘 = 𝑥𝑘/𝑥𝑚 end

𝛼 = 𝑠𝑖𝑔𝑛(𝑣1)[𝑣12 + 𝑣2

2 +⋯+ 𝑣𝑛2]1/2

𝑣1 = 𝑣1 + 𝛼 𝛼 = −𝛼𝑥𝑚 𝒖 = 𝒗/| 𝒗 |

Remark: 1. The computational complexity is 𝑂(𝑛). 2. 𝐻𝒙 is an 𝑂 𝑛 operation compared to 𝑂(𝑛2) for a general matrix-vector product. 𝐻𝒙 = 𝒙 − 𝟐𝒖(𝒖𝑻𝒙).

Page 18: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

QR Factorization by HouseHolder Transformation

Key idea:

Apply Householder transformation successively to columns of matrix to zero out sub-diagonal entries of each column.

18

Page 19: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

• Stage 1 – Consider the first column of matrix 𝐴 and determine a

HouseHolder matrix 𝐻1 so that 𝐻1

𝑎11𝑎21⋮

𝑎𝑛1

=

𝛼10⋮0

– Overwrite 𝐴 by 𝐴1, where

𝐴1 =

𝛼1 𝑎12∗ ⋯ 𝑎1𝑛

0 𝑎22∗ ⋮ 𝑎2𝑛

⋮ ⋮ ⋮ ⋮0 𝑎𝑛2

∗ ⋯ 𝑎𝑛𝑛∗

= 𝐻1𝐴

Denote vector which defines 𝐻1 vector 𝒗1. 𝒖1 = 𝒗1/| 𝒗1 |

Remark: Column vectors

𝑎12∗

𝑎22∗

⋮𝑎𝑛2∗

𝑎1𝑛∗

𝑎2𝑛∗

⋮𝑎𝑛𝑛∗

should be computed by

𝐻𝒙 = 𝒙 − 𝟐𝒖(𝒖𝑻𝒙). 19

Page 20: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

• Stage 2 – Consider the second column of the updated matrix

𝐴 ≡ 𝐴1 = 𝐻1𝐴 and take the part below the diagonal to determine a Householder matrix 𝐻2

∗ so that

𝐻2∗

𝑎22∗

𝑎32∗

⋮𝑎𝑛2∗

=

𝛼2

0⋮0

Remark: size of 𝐻2∗ is (𝑛 − 1) × (𝑛 − 1).

Denote vector which defines 𝐻2∗ vector 𝒗2. 𝒖2 = 𝒗2/| 𝒗2 |

– Inflate 𝐻2∗ to 𝐻2 where

𝐻2 =1 00 𝐻2

Overwrite 𝐴 by 𝐴2 ≡ 𝐻2𝐴1

20

Page 21: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

• Stage k

– Consider the 𝑘𝑡ℎ column of the updated matrix 𝐴 and take the part below the diagonal to determine a Householder matrix 𝐻𝑘

∗ so that

𝐻𝑘∗

𝑎𝑘𝑘∗

𝑎𝑘+1,𝑘∗

⋮𝑎𝑛,𝑛∗

=

𝛼𝑘

0⋮0

Remark: size of 𝐻𝑘∗ is (𝑛 − 𝑘 + 1) × (𝑛 − 𝑘 + 1).

Denote vector which defines 𝐻𝑘∗ vector 𝒗𝑘. 𝒖𝑘 = 𝒗𝑘/| 𝒗𝑘 |

– Inflate 𝐻𝑘∗ to 𝐻𝑘 where

𝐻𝑘 =𝐼𝑘−1 0

0 𝐻𝑘∗ , 𝐼𝑘−1 is (𝑘 − 1) × (𝑘 − 1) identity matrix.

Overwrite 𝐴 by 𝐴𝑘 ≡ 𝐻𝑘𝐴𝑘−1

21

Page 22: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

• After (𝑛 − 1) stages, matrix 𝐴 is transformed into an upper triangular matrix 𝑅.

• 𝑅 = 𝐴𝑛−1 = 𝐻𝑛−1𝐴𝑛−2 = ⋯ =𝐻𝑛−1𝐻𝑛−2…𝐻1𝐴

• Set 𝑄𝑇 = 𝐻𝑛−1𝐻𝑛−2…𝐻1. Then 𝑄−1 = 𝑄𝑇. Thus 𝑄 = 𝐻1

𝑇𝐻2𝑇 …𝐻𝑛−1

𝑇

• 𝐴 = 𝑄𝑅

22

Page 23: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

Example. 𝐴 =1 11 21 3

.

Find 𝐻1 such that 𝐻1

111

=𝛼100

.

By 𝑎 = −𝑠𝑖𝑔𝑛 𝑥1 | 𝒙 |,

𝛼1 = − 3 = −1.721.

𝑢1 = 0.8881, 𝑢2 = 𝑢3 = 0.3250.

By 𝐻𝒙 = 𝒙 − 𝟐𝒖 𝒖𝑻𝒙 , 𝐻1

123

=−3.46410.36611.3661

𝐻1𝐴 =−1.721 −3.4641

0 0.36610 1.3661

23

Page 24: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

Find 𝐻2∗ and 𝐻2, where

𝐻2∗ 0.36611.3661

=𝛼2

0

So 𝛼2 = −1.4143, 𝒖2 =0.79220.6096

So 𝑅 = 𝐻2𝐻1𝐴 =−1.7321 −3.4641

0 −1.41430 0

𝑄 = (𝐻2𝐻1)𝑇= 𝐻1

𝑇𝐻2𝑇

=−0.5774 0.7071 −0.4082−0.5774 0 0.8165−0.5774 −0.7071 −0.4082

24

Page 25: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

𝐴𝒙 = 𝒃 ⇒ 𝑄𝑅𝒙 = 𝒃

⇒ 𝑄𝑇𝑄𝑅𝒙 = 𝑄𝑇𝒃 ⇒ 𝑅𝒙 = 𝑄𝑇𝒃

Remark: Q rarely needs explicit construction

25

Page 26: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

Parallel Householder QR

• Householder QR factorization is similar to Gaussian elimination for LU factorization.

– Additions + multiplications: 𝑂4

3𝑛3 for QR versus

𝑂2

3𝑛3 for LU

• Forming Householder vector 𝒗𝑘is similar to computing multipliers in Gaussian elimination.

• Subsequent updating of remaining unreduced portion of matrix is similar to Gaussian elimination.

• Parallel Householder QR is similar to parallel LU. Householder vectors need to broadcast among columns of matrix.

26

Page 27: Lecture 8: Fast Linear Solvers (Part 3)zxu2/acms60212-40212/Lec-09-3.pdfCholesky Factorization •Matrix 𝐴 is symmetric if 𝐴=𝐴𝑇. •Matrix 𝐴 is positive definite if

References

• M. Cosnard, J. M. Muller, and Y. Robert. Parallel QR decomposition of a rectangular matrix, Numer. Math. 48:239-249, 1986

• A. Pothen and P. Raghavan. Distributed orthogonal factorization: Givens and Householder algorithms, SIAM J. Sci. Stat. Comput. 10:1113-1134, 1989

27