如果要计算矩阵的完整SVD,你可以使用包bigstatsr块来进行计算。 A FBM
表示Filebacked Big Matrix,并且是类似于文件包big.matrix
包的对象bigmemory的对象。
library(bigstatsr)
options(bigstatsr.block.sizeGB = 0.5)
# Initialize FBM with random numbers
a <- FBM(1e6, 1e3)
big_apply(a, a.FUN = function(X, ind) {
X[, ind] <- rnorm(nrow(X) * length(ind))
NULL
}, a.combine = 'c')
# Compute t(a) * a
K <- big_crossprodSelf(a, big_scale(center = FALSE, scale = FALSE))
# Get v and d where a = u * d * t(v) the SVD of a
eig <- eigen(K[])
v <- eig$vectors
d <- sqrt(eig$values)
# Get u if you need it. It will be of the same size of u
# so that I store it as a FBM.
u <- FBM(nrow(a), ncol(a))
big_apply(u, a.FUN = function(X, ind, a, v, d) {
X[ind, ] <- sweep(a[ind, ] %*% v, 2, d, "/")
NULL
}, a.combine = 'c', block.size = 50e3, ind = rows_along(u),
a = a, v = v, d = d)
# Verification
ind <- sample(nrow(a), 1000)
all.equal(a[ind, ], tcrossprod(sweep(u[ind, ], 2, d, "*"), v))
这需要大约10分钟在我的电脑上。
做任何这些工作'?qr'或'?Matrix :: qr'或'?MASS :: Null' – user20650
是的。我这样做,但这些函数不适用于bigmatrix(S4类),或者我不能将它们用于大矩阵。我只能将这些函数用于常规矩阵,而不能用于大矩阵。 – Mahin
好吧,我不确定你是否有一个大的矩阵或bigmatrix;)。目前,您的问题是[偏离主题](https://stackoverflow.com/help/on-topic),因为它直接要求提供套餐推荐,并且在目前的状态下可能会关闭。但它很有趣。你可以编辑你的问题,请进一步的细节。例如,您可以添加一个bigmatrix的小示例(包括使用的任何软件包),说明标准工具不工作的方式,也可能要求替代方案。谢谢 –
user20650