用Java处理大型矩阵
我现在需要用48K x 50K的矩阵进行奇异值分解
我试过JAMA,但它只适用于行>;柱。 我尝试过PCOLT和JBLAS,但当rows*columns>;最大值
有什么建议我该怎么做
对不起,如果我在上面几行中犯了错误
提前多谢
你可以在下面搜索框中键入要查询的问题!
我现在需要用48K x 50K的矩阵进行奇异值分解
我试过JAMA,但它只适用于行>;柱。 我尝试过PCOLT和JBLAS,但当rows*columns>;最大值
有什么建议我该怎么做
对不起,如果我在上面几行中犯了错误
提前多谢
# 1 楼答案
我在执行SVD计算时遇到了类似的问题,我的经验是:不要在Java中这样做。有一些工具可以更有效地实现这一点。如果你真的需要java,你可以考虑建立一个接口,从代码内部调用这个工具。我最终使用了R。我手动使用它,将矩阵存储在一个文件中,R可以将其作为矩阵读取
顺便说一句,如果矩阵是sparse,则可能会有各种优化,这些优化将减少内存使用和输出文件的大小(如果您选择使用)
否则,请检查此线程以查看这是否有帮助:Handle large data structure in Java
# 2 楼答案
对于非常大的内存块,我倾向于建议使用内存映射文件(也许这就是R为您所做的),您可以在Java中使用一些锅炉板代码来实现这一点。不幸的是,Java不直接支持每次超过2GB的映射,所以您必须将其划分为多个部分
具有设置对角线值的测试
打印(与
-XX:-UseTLAB
一起运行时)只创建实际使用的页面。文件看起来非常大,但分配的空间取决于使用情况
# 3 楼答案
第一步。使用数据库保存它
第二步。使用多正面/并行算法
This paper调查大型SVD的SOTA方法。3个处理器上的Lanzcos算法在32k X 32k矩阵上只需10分钟,但仅用于最小奇异值。也许可以进行deflate,然后重新提取连续的奇异值,我一直认为使用deflate的幂次迭代很好
简而言之,将M X M_T和M_T X M取特征向量和特征值来重构奇异值分解矩阵
如果您准备接受近似,那么this other paper只是处理近似算法的众多方法之一。很多都是基于某种列的下采样,或者基于最有代表性的子矩阵,在这种情况下,您可以利用立方体更小的块的优点,再加上并行性
显然,这些都有一些失真,但也许你可以平滑它为你的结果
最后,您确实需要使用Strassen的方法进行乘法