R 中稀疏矩阵的 SVD
我在 R 中有一个稀疏矩阵,它显然太大了,无法在其上运行 as.matrix()(尽管它也不是超级大)。有问题的 as.matrix()
调用位于 svd()
函数内部,所以我想知道是否有人知道 SVD 的不同实现,不需要首先转换为稠密矩阵。
I've got a sparse Matrix
in R that's apparently too big for me to run as.matrix()
on (though it's not super-huge either). The as.matrix()
call in question is inside the svd()
function, so I'm wondering if anyone knows a different implementation of SVD that doesn't require first converting to a dense matrix.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这就是我最终所做的。编写一个例程相对简单,将稀疏矩阵(类
dgCMatrix
)转储到 SVDLIBC 的“稀疏文本”格式的文本文件,然后调用svd
可执行文件,并读取 。问题是它的效率非常低——我需要大约 10 秒的时间来读取和读取结果 写入文件,但实际SVD计算只需要大约0.2秒左右。不过,这当然比根本无法执行计算要好得多,所以我很高兴。 =)
So here's what I ended up doing. It's relatively straightforward to write a routine that dumps a sparse matrix (class
dgCMatrix
) to a text file in SVDLIBC's "sparse text" format, then call thesvd
executable, and read the three resultant text files back into R.The catch is that it's pretty inefficient - it takes me about 10 seconds to read & write the files, but the actual SVD calculation takes only about 0.2 seconds or so. Still, this is of course way better than not being able to perform the calculation at all, so I'm happy. =)
rARPACK 是您需要的包。工作起来非常神奇,而且速度超快,因为它通过 C 和 C++ 进行并行化。
rARPACK is the package you need. Works like a charm and is Superfast because it parallelizes via C and C++.
irlba 包具有非常快速的稀疏矩阵 SVD 实现。
The irlba package has a very fast SVD implementation for sparse matrices.
您可以使用随机投影在 R 中进行非常令人印象深刻的稀疏 SVD,如 http://arxiv.org/abs 中所述/0909.4061
这是一些示例代码:
You can do a very impressive bit of sparse SVD in R using random projection as described in http://arxiv.org/abs/0909.4061
Here is some sample code: