简体   繁体   中英

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 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. 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

Have you had a look at Colt or Matrix-Toolkits-Java ? These may help you out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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