Singular-Value Decomposition(SVD)

Singular-Value Decomposition(SVD) is a matrix decomposition/factorization method for reducing a given matrix into its constituent elements.

Note: All matrices have an SVD, which makes it more stable than other methods, such as the eigendecomposition.

A=U.Σ.VTA = U . \Sigma.V^T

AA:The real m x n matrix that we wish to decompose UU: m x m matrix where matrix U is also known as left-singlular vectors of A Σ\Sigma: m x n diagonal matrix where the diagonal values are known as singular values VTV^T: Transpose of an n x n matrix where matrix V is also right-singular vectors of A

Calculate Singular-Value Decomposition using NumPy

# Calculate Singular-Value Decomposition Using SciPy
from numpy import array
from numpy.linalg import svd

A = array([[1, 2], [3, 4], [5, 6]])
print('-------------------')
print('Original Matrix to be decomposed')
print(A)

U, d, VT = svd(A)
print('-------------------')
print('U Matrix')
print(U)

print('-------------------')
print('2 element Sigma vector')
print(d)

print('-------------------')
print('VT Matrix')
print(VT)

Reconstruct Matrix from SVD

Note: svd() returns a sigma vector which needs to be transformed into a m x n matrix for multiplication. - Convert sigma vector into diagonal matrix n x n using diag() - Create a m x n empty/zero Sigma matrix - Populate the Sigma matrix with n x n diagonal matrix

Link: Gentle Introduction to Singular-Value Decomposition for Machine Learning

Last updated

Was this helpful?