简体   繁体   English

Java中的稀疏矩阵实现和操作

[英]Sparse Matrix implemantation and operations in java

I have to implement sparse matrix and do some decompositions like Cholesky Decomposition, LU Decomposition, QR Decomposition on it. 我必须实现稀疏矩阵并做一些分解,如Cholesky分解,LU分解,QR分解就可以了。

Actually I found a library called JAMA which is capable of doing this for dense matrix. 实际上我找到了一个名为JAMA的库,它能够为密集矩阵做到这一点。

But I have to implement sparse matrix. 但我必须实现稀疏矩阵。

Can any one share their experience implementing sparse matrix or is there any library to implement it. 任何人都可以分享他们实现稀疏矩阵的经验,或者是否有任何库来实现它。

There is a la4j (Linear Algebra for Java) library that supports sparse matrices. 有一个支持稀疏矩阵的la4j (线性代数for Java)库。 The la4j uses the most common and effective sparse representaions sush as CRS (Compressed Row Storage) and CCS (Compressed Column Storage) . la4j使用最常见和有效的稀疏表示sush作为CRS(压缩行存储)CCS(压缩列存储) Here is the corresponding classes in la4j: CRSMatrix and CCSMatrix . 这是la4j中的相应类: CRSMatrixCCSMatrix So, you can look into sources or use la4j's sparse matrices directly with mentioned decompositions. 因此,您可以查看源代码或直接使用la4j的稀疏矩阵和所提到的分解。

Here is the brief example: 这是一个简短的例子:

Matrix a = new CRSMatrix(new double[][]{
    { 1.0, 0.0, 0.0 },
    { 0.0, 2.0, 0.0 },
    { 0.0, 0.0, 3.0 }
});

Matrix[] qr = a.decompose(Matrices.QR_DECOMPOSITOR); // qr[0] = Q, qr[1] = R

Matrix[] u = a.decompose(Matrices.CHOLESKY_DECOMPOSITOR); // u[0] = U

Have you had a look at Colt or Matrix-Toolkits-Java ? 您是否看过ColtMatrix-Toolkits-Java These may help you out. 这些可能会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM