I am trying to compute the m
first eigenvectors of a large sparse matrix in R. Using eigen()
is not realistic because large means N > 106 here.
到目前为止我发现我应该使用 ARPACKigraph
包,可以处理稀疏矩阵。但是我无法让它在一个非常简单的(3x3)矩阵上工作:
library(Matrix)
library(igraph)
TestDiag <- Diagonal(3, 3:1)
TestMatrix <- t(sparseMatrix(i = c(1, 1, 2, 2, 3), j = c(1, 2, 1, 2, 3), x = c(3/5, 4/5, -4/5, 3/5, 1)))
TestMultipliedMatrix <- t(TestMatrix) %*% TestDiag %*% TestMatrix
然后使用帮助示例中给出的代码arpack()
提取 2 个第一个特征向量的函数:
func <- function(x, extra=NULL) { as.vector(TestMultipliedMatrix %*% x) }
arpack(func, options=list(n = 3, nev = 2, ncv = 3, sym=TRUE, which="LM", maxiter=200), complex = FALSE)
我收到一条错误消息:
Error in arpack(func, options = list(n = 3, nev = 2, ncv = 3, sym = TRUE, :
At arpack.c:1156 : ARPACK error, NCV must be greater than NEV and less than or equal to N
我不明白这个错误,因为这里 ncv (3) 大于 nev (2),并且等于 N (3)。
我是否犯了一些愚蠢的错误,或者是否有更好的方法来计算 R 中稀疏矩阵的特征向量?
Update
这个错误显然是由于错误arpack()
具有大写/小写 NCV 和 NEV 的功能。
欢迎任何解决该错误的建议(我试图查看包代码,但它对我来说太复杂而无法理解)或以其他方式计算特征向量。