SVD with numpy - 结果解释

SVD with numpy - intepretation of results

我正在尝试学习奇异值分解 (SVD)。我发现这个 YouTube Lecture 包含一个示例。但是,当我在 numpy 中尝试这个示例时,我得到了 "kind of" 不同的结果。在这个例子中输入矩阵是

A = [ [1,1,1,0,0], [3,3,3,0,0], [4,4,4,0,0], [5,5,5,0,0], [0,2,0,4,4], [0,0,0,5,5], [0,1,0,2,2] ]
A = np.asarray(A)
print(A)

[[1 1 1 0 0]
 [3 3 3 0 0]
 [4 4 4 0 0]
 [5 5 5 0 0]
 [0 2 0 4 4]
 [0 0 0 5 5]
 [0 1 0 2 2]]

这个矩阵的秩为 3 (np.linalg.matrix_rank(A))。讲座指出奇异值的数量是矩阵的秩,在示例中,Sigma 矩阵 S 的大小确实为 3=3。然而,当我执行

U, S, V = np.linalg.svd(A)

矩阵S 包含 5 个值。另一方面,前 3 个值与示例中的值匹配,而其他 2 个值基本上为 0。我可以假设由于 SVD 背后的数值算法和实数的有限表示而获得比等级更多的奇异值在计算机上 - 或者类似的东西?

this page, numpy internally uses LAPACK routine _gesdd to get the SVD decomposition. Now, if you see _gesdd documentation 所述,它提到,

To find the SVD of a general matrix A, call the LAPACK routine ?gebrd or ?gbbrd for reducing A to a bidiagonal matrix B by a unitary (orthogonal) transformation: A = QBPH. Then call ?bdsqr, which forms the SVD of a bidiagonal matrix: B = U1ΣV1H.

所以,这里涉及 2 个步骤:

  • 双对角化正交 t运行sformation(Householder t运行sformations)
  • 获取双对角矩阵的 SVD,使用隐式零位移 QR 算法。

QR 算法是一种迭代算法,这意味着您不会得到 "exact" 答案,但每次迭代都会获得越来越好的近似值,如果值的变化低于阈值则停止,因此它是"approximate" 在这个意义上。

因此,随着实数的有限机器表示导致的数值精度问题,即使我们有无限的表示能力,我们也会得到 "approximate" 结果(如果我们 运行 算法有限时间)由于算法的迭代性质。