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.
Actually I found a library called JAMA which is capable of doing this for dense matrix.
But I 开发者_如何学Gohave to implement sparse matrix.
Can any one share their experience implementing sparse matrix or is there any library to implement it.
Have you had a look at Colt or Matrix-Toolkits-Java? These may help you out.
There is a la4j (Linear Algebra for Java) library that supports sparse matrices. The la4j uses the most common and effective sparse representaions sush as CRS (Compressed Row Storage) and CCS (Compressed Column Storage). Here is the corresponding classes in la4j: CRSMatrix and CCSMatrix. So, you can look into sources or use la4j's sparse matrices directly with mentioned decompositions.
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
精彩评论