Principle:Haifengl Smile Matrix Decomposition
Overview
Matrix Decomposition (also called matrix factorization) is the process of expressing a matrix as a product of simpler, structured matrices. Each decomposition reveals different structural properties of the original matrix and enables different computational applications. The five principal decompositions in Smile are LU, QR, SVD, Eigenvalue (EVD), and Cholesky.
Matrix decomposition is the central stage of the Matrix_Decomposition_Pipeline workflow. It transforms a constructed matrix into a factored form that can then be used for solving linear systems, computing determinants, finding eigenvalues, performing dimensionality reduction, and more.
Theoretical Basis
LU Decomposition
The LU decomposition factors a matrix into a lower triangular matrix and an upper triangular matrix with row pivoting:
where is a permutation matrix, is unit lower triangular (ones on diagonal), and is upper triangular.
Properties:
- Exists for any square matrix (with pivoting)
- Computational cost: flops for an matrix
- The determinant is
- If for some , the matrix is singular (the factorization still completes, but the matrix cannot be used for solving)
Applications: Solving , computing determinants, matrix inversion.
QR Decomposition
The QR decomposition factors a matrix into an orthogonal matrix and an upper triangular matrix:
where has orthonormal columns () and is upper triangular.
Properties:
- Always exists for any matrix with
- Computed via Householder reflections (LAPACK
dgeqrf): flops - is stored implicitly as a product of Householder reflectors where
- The explicit can be reconstructed via
dorgqr
Applications: Least squares problems , eigenvalue algorithms (QR algorithm), orthogonalization.
Singular Value Decomposition (SVD)
The SVD factors any matrix into three matrices:
where and have orthonormal columns, is diagonal with nonnegative entries , and .
Properties:
- Always exists for any matrix
- Compact SVD: for , only the first columns of are computed
- The singular values measure the "importance" of each component
- The matrix rank equals the number of nonzero singular values
- Condition number:
The Eckart-Young Theorem: The best rank- approximation to in the Frobenius or operator norm is:
Applications: Dimensionality reduction (PCA), pseudoinverse computation, matrix rank determination, data compression, latent semantic analysis.
Eigenvalue Decomposition (EVD)
For a square matrix :
where is an eigenvalue and is the corresponding eigenvector.
Symmetric case: If , then:
where is orthogonal and with all real eigenvalues.
General case: Eigenvalues may be complex. LAPACK computes the real and imaginary parts separately: . Left eigenvectors satisfy .
Properties:
- Symmetric matrices have real eigenvalues and orthogonal eigenvectors
- Smile uses LAPACK
dsyevdfor symmetric anddgeevfor general matrices dsyevduses divide-and-conquer, which is faster thandsyevfor large matrices
Applications: PCA (eigendecomposition of covariance matrix), spectral clustering, stability analysis, Markov chain analysis.
Cholesky Decomposition
For a symmetric positive definite (SPD) matrix:
where is lower triangular with positive diagonal elements.
Properties:
- Exists if and only if is SPD
- Computational cost: flops -- half the cost of LU
- If
dpotrfreturns a nonzero info code, the matrix is not positive definite - The determinant is
Applications: Efficient solving of SPD systems, Monte Carlo simulation with correlated variables, Kalman filters (unscented transform).
Choosing the Right Decomposition
| Decomposition | Matrix Requirements | Best For | Cost |
|---|---|---|---|
| LU | Square | Solving , determinants | |
| Cholesky | Symmetric positive definite | Solving SPD systems (2x faster than LU) | |
| QR | (overdetermined) | Least squares, numerical stability | |
| SVD | Any | Rank, pseudoinverse, dimensionality reduction | |
| EVD | Square (symmetric preferred) | Spectral analysis, PCA |
Destructive Nature of Decompositions
An important implementation detail: all decompositions in Smile overwrite the input matrix. The caller must make a copy before decomposing if the original matrix is still needed:
// The matrix A will be overwritten by lu() DenseMatrix A_copy = A.copy(); LU lu = A_copy.lu(); // A_copy now contains the LU factors, not the original data
This design avoids unnecessary memory allocation when the original matrix is no longer needed.
Relationship to the Pipeline
Construction --> Arithmetic --> Decomposition --> Solving --> Result Extraction
^
|
(this principle)
Related
Implementation:Haifengl_Smile_DenseMatrix_DecompositionPrinciple:Haifengl_Smile_Matrix_ArithmeticPrinciple:Haifengl_Smile_Linear_System_SolvingPrinciple:Haifengl_Smile_Decomposition_Result_Extraction
Knowledge Sources
Domains
Linear_Algebra, Numerical_Computing, Matrix_Theory