我有一个正方形矩阵,有几万行和列,只有几个
我的问题是我需要这些矩阵的逆和Moore-Penrose广义逆,但我目前无法计算。
我尝试过以下方法:
1
和许多0
,因此我使用Matrix
包以高效的方式在R中存储。由于我用完了内存,所以base::matrix
对象无法处理这么多的单元格。我的问题是我需要这些矩阵的逆和Moore-Penrose广义逆,但我目前无法计算。
我尝试过以下方法:
solve
yields anError in LU.dgC(a) : cs_lu(A) failed: near-singular A (or out of memory)
errorMASS::ginv
is not compatible with theMatrix
class- there is no direct way to convert a sparse
Matrix
to e.g.bigmemory::big.matrix
, and that latter neither does work withMASS::ginv
anyway if I try to compute the Choleski factorization of the matrix to later call
Matrix::chol2inv
on that, I get the following error message:Error in .local(x, ...) : internal_chm_factor: Cholesky factorization failed In addition: Warning message: In .local(x, ...) : Cholmod warning 'not positive definite' at file ../Cholesky/t_cholmod_rowfac.c, line 431
based on a related question, I also gave a try to the
pbdDMAT
package on a single node, butpbdDMAT::chol
yielded anCholmod error 'out of memory' at file ../Core/cholmod_memory.c, line 147
error message
问题简述:除了使用内存充足的计算机上的matrix
类,还有没有其他方法计算这种稀疏矩阵的逆和Moore-Penrose广义逆?
快速可重现示例:
library(Matrix)
n <- 1e5
m <- sparseMatrix(1:n, 1:n, x = 1)
m <- do.call(rBind, lapply(1:10, function(i) {
set.seed(i)
m[-sample(1:n, n/3), ]
}))
m <- t(m) %*% m
以下是一些描述性词语(感谢Gabor Grothendieck):
> dim(m)
[1] 100000 100000
> sum(m) / prod(dim(m))
[1] 6.6667e-05
> table(rowSums(m))
0 1 2 3 4 5 6 7 8 9 10
5 28 320 1622 5721 13563 22779 26011 19574 8676 1701
> table(colSums(m))
0 1 2 3 4 5 6 7 8 9 10
5 28 320 1622 5721 13563 22779 26011 19574 8676 1701
还有一些错误信息:
> Matrix::solve(m)
Error in LU.dgC(a) : cs_lu(A) failed: near-singular A (or out of memory)
> base::solve(m)
Error in asMethod(object) :
Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 105
> MASS::ginv(m)
Error in MASS::ginv(m) : 'X' must be a numeric or complex matrix
的目标是找到一种在不到8Gb的RAM情况下计算 m
的Moore-Penrose广义逆的方法(速度和性能并不重要)。
m
没有创建正方形矩阵。 - James