SVD 的部分美妙之处在于,您无需取 的叉积x
即可获得叉积的 SVD。
相反,您可以直接从 的 SVD 的元素中获取x%*%t(x)
(aka )的 SVD。具体来说(直到 U 列的符号)SVD(x %*% t(x)) = UD^2 t(U),其中 U 和 D 取自 的 SVD 。(有关参考,请参见此处。)tcrossprod(x)
x
x
要查看它的实际效果,请尝试一个较小的示例:
set.seed(1)
x <- matrix(rnorm(15), ncol=5)
svd(x)$d
# [1] 3.046842 1.837539 1.411585
sqrt(svd(tcrossprod(x))$d)
# [1] 3.046842 1.837539 1.411585
svd(x)$u
# [,1] [,2] [,3]
# [1,] -0.3424029 0.7635281 0.5475264
# [2,] -0.8746155 -0.4719093 0.1111273
# [3,] 0.3432316 -0.4408248 0.8293766
svd(tcrossprod(x))$u
# [,1] [,2] [,3]
# [1,] -0.3424029 0.7635281 0.5475264
# [2,] -0.8746155 -0.4719093 0.1111273
# [3,] 0.3432316 -0.4408248 0.8293766
svd(tcrossprod(x))$v
# [,1] [,2] [,3]
# [1,] -0.3424029 0.7635281 0.5475264
# [2,] -0.8746155 -0.4719093 0.1111273
# [3,] 0.3432316 -0.4408248 0.8293766
另一种查看方式:
sss <- svd(x)
with(sss, u %*% diag(d)^2 %*% t(u))
# [,1] [,2] [,3]
# [1,] 3.654154 1.684675 -1.322649
# [2,] 1.684675 7.877802 -1.900721
# [3,] -1.322649 -1.900721 3.120415
tcrossprod(x)
# [,1] [,2] [,3]
# [1,] 3.654154 1.684675 -1.322649
# [2,] 1.684675 7.877802 -1.900721
# [3,] -1.322649 -1.900721 3.120415