[Numerical calculation methods (Huang Mingyou)] Calculation of matrix eigenvalues and eigenvectors (5): Householder method [theory to procedure]

  eigenvalues ​​of the matrix (eigenvalue) and eigenvectors (eigenvector) has important mathematical and physical significance in many applications. Householder matrices and transformations provide an efficient way to map a vector to a standard direction through reflection transformation, which is of great significance for some numerical computing problems.

  This article will introduce the basic principles and steps of the Householder method in detail, and give its Python implementation.

1. Jacobi rotation method

  In each iteration of the Jacobi rotation method, you need to select a position where the non-diagonal element is the largest, and then construct the corresponding rotation matrix, Perform a similarity transformation to gradually diagonalize the matrix.

2. Jacobi clearance method

  Jacobi’s threshold method is an improved version of Jacobi rotation method. Its main purpose is to reduce calculation work and increase running speed. This method dynamically adjusts the threshold and selectively rotates the non-diagonal elements according to the threshold to gradually diagonalize the symmetric matrix.

3. Householder method

  If for any vector z z z, we can decompose it into u u u parallel quantity a u au au Wayo u u u orthogonal quantity b v bv bv,即 z = a u + b v z = au + bv With=au+bv,nan么 Householder 变换会将 z z z 变换为 − a u + b v -au + bv au+bv. This transformation can be understood as specular reflection, which does not change the vector between u u u Projection on orthogonal planes, but with vectors along u u Reflection in the direction of u. The mathematical expression is:

H z = a u + b v → − a u + b v Hz = au + bv \rightarrow -au + bv Hz=au+bvau+bv

  This property makes the Householder transform very useful in some numerical calculation applications, such as QR decomposition.

1. Rotation transformation

  In the Householder method, through a series of orthogonal similarity transformations, the real symmetric matrix (A) can be transformed intotridiagonal matrix a i j = a j i = 0 a_{ij}= a_{ji}=0 aij=aji=0), the rotation matrix of the Householder method selects an angle such that c i k = c k j = 0 c_{ik}= c_{kj}= 0 cik=ckj=0

a. Selection of rotation transformation

  For a real symmetric matrix A A aik , choose the appropriate rotation angle θ \theta θ ,Can be used a i k a_{ik} aik becomes zero. Specifically, choose θ \theta θ 使得:
c i k = c k j = a i k cos ⁡ ( θ ) + a j k sin ⁡ ( θ ) = 0 c_{ik}= c_{kj}=a_{ik} \cos(\theta) + a_{jk} \sin(\theta) = 0 cik=ckj=aikcos(θ)+ajksin(θ)=0

  Through this choice, we can construct a rotation matrix P i , j , k P_{i,j,k} Pi,j,k, the orthogonal similarity transformation corresponding to this matrix can convert c i k c_{ik} cikbecomes zero. This process realizes the orthogonal similarity transformation of the real symmetric matrix, causing some elements to become zero, and gradually realizes the transformation of the matrix into a tridiagonal form.

Insert image description here

b. The order of rotation transformation

  When performing Householder transformation, the order of rotation is important. Typically, you can choose to transform by column. For example, for i = 2 , … , n − 1 i = 2, \ldots, n-1 i=2,,n1, j = i + 1 , i + 2 , … , n j = i+1, i+2, \ldots, n j=i+1,i+2,,n,Naturally ( i , j ) (i, j) (i,j) perform orthogonal similarity transformation, transform a i k a_{ik} aik becomes zero. The iteration of the entire process will gradually transform the real symmetric matrix A A A is transformed into a tridiagonal matrix C C C

2. Householder Matrix

a. Definition of H matrix

  设 u u uamount of direction, immediately ∥ u ∥ = 1 \|u\| = 1 u=1. set义 Householder 矩阵 H = I − 2 u u T H = I - 2uu^T H=I2uuT, inside I I I is the identity matrix. This matrix has the following properties:

  • 对称性: H T = H H^T = H HT=H, that is, the Householder matrix is ​​symmetric.
  • 正交性: H T H = I H^T H = I HTH=I, that is, the Householder matrix is ​​an orthogonal matrix.
  • Conservation: for any non-zero vector x x x sum y y y, result ∥ x ∥ 2 = ∥ y ∥ 2 \|x\|^2 = \|y\|^2 x2=y2,则existing Householder 矩阵 H H H, use H x = y Hx = y Hx=y
    • Consider Householder matrix versus vector u u u action: H u = ( I − 2 u u T ) u = − u Hu = (I - 2uu^T) u = -u Hu=(I2uuT)u=u. Description Householder squareforward direction amount u u u Reflection on the direction of the loss.
    • What do you think? u u u Orthogonal direction v v v,Yes H v = ( I − 2 u u T ) v = v Hv = (I - 2uu^T)v = v Hv=(I2uuT)v=v,Immediately Householder u u u Orthogonal direction/quantity change.
    • So for any vector z z z,设 z = a u + b v z = au + bv With=au+bv,nan么 Householder 变换会将 z z z 变换为 − a u + b v -au + bv au+bv, Mathematical expression:
      H z = a ( H u ) + b ( H v ) → − a u + b v Hz = a(Hu) + b(Hv) \rightarrow -au + bv Hz=a(Hu)+b(Hv)au+bv

b. Geometric interpretation of H transformation

  The Householder transformation can be thought of as specular reflection . Consider u u u is the unit normal vector on the reflecting surface. For any z z z,Householder 变换将 z z z projection reflection reaches − u -u u direction while maintaining the projection on the reflective surface.

c. Application scenarios of H transformation

  1. Matrix tridiagonalization: In computational linear algebra, Householder transformation is often used to convert matrices into tridiagonal form, making it easier to perform operations such as eigenvalue calculations.
  2. QR decomposition: The Householder transform is a basic tool for computing QR decomposition, which is used to decompose a matrix into the product of an orthogonal matrix and an upper triangular matrix.

3. Detailed explanation of H transformation process

a. Process introduction

  对于矩阵 A A A A certain one-column direction quantity a = ( a 1 , a 2 , … , a n ) T \mathbf{a} = (a_1 , a_2, \ldots, a_n)^T a=(a1,a2,,an)T, if we want to convert the back end of the vector n − ( r + 1 ) n - (r+1) n(r+1)Partialization is zero, immediate general a \mathbf{a} a 变为 c = ( a 1 , a 2 , … , a r , − sign ( a r + 1 ) s , 0 , … , 0 ) T \mathbf{c} = (a_1, a_2, \ldots, a_r, -\text{sign}(a_{r+1})s, 0, \ldots, 0)^T c=(a1,a2,,ar,sign(ar+1)s,0,,0)T, inside s = ∥ a ∥ 2 s = \|a\|_2 s=a2 (从 r + 1 r+1 r+1calculation reached n n n) except a r + 1 ≠ 0 a_{r+1} \neq 0 ar+1=0, then the Householder matrix H H H,Use H a = c Ha=c Ha=c. The Householder matrix is ​​calculated as follows:
w = a − sign ( a r + 1 ) s e r + 1 \mathbf{w} = \mathbf{a} - \text{sign}(a_{r +1})s\mathbf{e}_{r+1} In=asign(ar+1)ser+1
  Among them, e r + 1 \mathbf{e}_{r+1} It isr+1 is a unit vector ( 0 , 0 , … , 0 , 1 , 0 , … , 0 ) T (0, 0, \ldots, 0, 1, 0, \ ldots, 0)^T (0,0,,0,1,0,,0)T, concrete location r + 1 r+1 r+1 个.

Insert image description here

b. Detailed analysis

  • Construction of Householder matrix:
    • Construct the Householder matrix through Householder transformation H H H,Sho certain line a j a_j aj r + 1 r+1 r+1 to n n n components are reduced to zero.

  • Calculation process stability:

    • General a a a r + 1 r+1 r+1 to n n The signs of the n components are set to − sign ( a r + 1 ) -\text{sign}(a_{r+1 }) sign(ar+1) to enhance the stability of calculations.
  • Compute similar tridiagonal matrices:

    • General A A A Perform orthogonal similarity transformation column by column to obtain A 1 , A 2 , … , A n − 1 A_1, A_2, \ ldots, A_{n-1} A1,A2,,An1
    • Finally get a similar tridiagonal matrix G = A n = H n − 2 ⋅ … ⋅ H 2 ⋅ H 1 ⋅ A G = A_n = H_{n-2} \ cdot \ldots \cdot H_2 \cdot H_1 \cdot A G=An=Hn2H2H1A
  • Optimization in actual calculations:

    • In actual calculations, there is no need to form all Householder matrices or perform matrix multiplication operations, and calculations can be performed directly on the original matrices.
      Insert image description here

4. Analysis of H transformation examples

  integer:
A = [ 1 2 1 2 2 2 − 1 1 1 − 1 1 1 2 1 1 1 ] A = \begin{bmatrix} 1 & 2 & 1 & 2 \\ 2 & 2 & -1 & 1 \\ 1 & -1 & 1 & 1 \\ 2 & 1 & 1 & 1 \end{bmatrix}A= 1212221111112111
Insert image description here
Insert image description here

Final tridiagonal matrix A 2 A_2 A2

  • A 2 A_2 A2Integers
    A 2 = [ 1 − 3 0 0 − 3 2.3333 − 0.4714 0 0 − 0.4714 1.1667 − 1.5003 0 0 − 1.5003 0.5002 ] A_2 = \begin{bmatrix } 1 & -3 & 0 & 0 \\ -3 & 2.3333 & -0.4714 & 0 \\ 0 & -0.4714 & 1.1667 & -1.5003 \\ 0 & 0 & -1.5003 & 0.5002 \end{bmatrix}A2= 130032.33330.4714000.47141.16671.5003001.50030.5002

  Thus, by selecting r = 1 r=1 r=1 sum r = 2 r=2 r=2 Perform two Householder transformations, matrix A A A Successful place conversion 为三对angled form A 2 A_2 A2

4. Python implementation

import numpy as np


def householder_matrix(v):
    """
    给定向量 v,返回 Householder 变换矩阵 H
    """
    v = np.array(v, dtype=float)
    if np.linalg.norm(v) == 0:
        raise ValueError("无效的输入向量,它应该是非零的。")

    v = v / np.linalg.norm(v)
    H = np.eye(len(v)) - 2 * np.outer(v, v)
    return H


def householder_reduction(A):
    """
    对矩阵 A 执行 Householder 变换,将其化为三对角形式。
    """
    m, n = A.shape
    if m != n:
        raise ValueError("输入矩阵 A 必须是方阵。")

    Q = np.eye(m)  # 初始化正交矩阵 Q

    for k in range(n - 2):
        x = A[k + 1:, k]
        e1 = np.zeros_like(x)
        e1[0] = 1.0
        v = np.sign(x[0]) * np.linalg.norm(x) * e1 + x
        v = v / np.linalg.norm(v)

        H = np.eye(m)
        H[k + 1:, k + 1:] -= 2.0 * np.outer(v, v)
        Q = np.dot(Q, H)
        A = np.dot(H, np.dot(A, H))

    return Q, A


# 示例矩阵
A = np.array([[1, 2, 1, 2],
              [2, 2, -1, 1],
              [1, -1, 1, 1],
              [2, 1, 1, 1]], dtype=float)

# Householder 变换
Q, tridiagonal_A = householder_reduction(A)
np.set_printoptions(precision=4, suppress=True)
print("正交矩阵 Q:")
print(Q)
print("\n三对角矩阵:")
print(tridiagonal_A)


Insert image description here

Debugging process

  • first:
    Insert image description here

  • the second time:
    Insert image description here

  • final:
    Insert image description here

Guess you like

Origin blog.csdn.net/m0_63834988/article/details/134678731