Singular Value Decomposition (SVD) System

From GM-RKB
(Redirected from SVD Decomposition System)
Jump to navigation Jump to search

A Singular Value Decomposition (SVD) System is a matrix decomposition system that implements an SVD algorithm to solve an SVD task.

     >>> A = np.random.randn(9, 6) + 1.j*np.random.randn(9, 6)
     >>> A = numpy.array([
               [2.0, 0.0, 8.0, 6.0, 0.0], 
               [1.0, 6.0, 0.0, 1.0, 7.0], 
               [5.0, 0.0, 7.0, 4.0, 0.0], 
               [7.0, 0.0, 8.0, 5.0, 0.0],
               [0.0, 10.0, 0.0, 0.0, 7.0]])
     >>> U,sigma,Vh = numpy.linalg.svd(A, full_matrices=True)
     >>> U.shape, Vh.shape, sigma.shape
     >>> for i in xrange(1, 51, 5):
     >>>     dA = np.matrix(U[:, :i]) * np.diag(sigma[:i]) * np.matrix(Vh[:i, :])
  >>> from sklearn.decomposition import TruncatedSVD
  >>> from sklearn.random_projection import sparse_random_matrix
  >>> X = sparse_random_matrix(100, 100, density=0.01, random_state=42)
  >>> svd = TruncatedSVD(n_components=5, random_state=42)
  >>> svd.fit(X) 
  TruncatedSVD(algorithm='randomized', n_components=5, n_iter=5,
          random_state=42, tol=0.0)
  >>> print(svd.explained_variance_ratio_) 
  [ 0.0782... 0.0552... 0.0544... 0.0499... 0.0413...]
  >>> print(svd.explained_variance_ratio_.sum()) 
  0.279...


References