Matrix Toolkit Java
- 3 min read
- 2 chapters
Related on Lably
Through Open-source software, Java (programming language) and Library (computing)
MTJ was originally developed by Bjørn-Ove Heimsund, who has taken a step back due to other commitments. The project webpage states that "(The new maintainers are) primarily concerned with keeping the library maintained, and fixing bugs as they are discovered. There is no road plan for future releases".
Several citations for MTJ can be found in scientific literature, including which uses its LU preconditioner. Performance of MTJ has been compared to other libraries, which can be found at Java Matrix Benchmark's site.
Capabilities
The following is an overview of MTJ's capabilities, as listed on the project's website:
- Datastructures for dense and structured sparse matrices in the following formats:
- Dense, column major.
- Banded matrices, which store only a few diagonals.
- Packed matrices, storing only half the matrices (for triangular or symmetric matrices).
- Tridiagonal and symmetric tridiagonal matrices.
- Transparent support for symmetric and triangular storage.
- Datastructures for unstructured sparse matrices in these formats:
- Compressed row or column storage (CRS/CCS).
- Flexible CRS/CCS, using growable sparse vectors.
- Compressed diagonal storage (CDS).
- The dense and structured sparse matrices are built on top of BLAS and LAPACK, and include the following intrinsic operations:
- Matrix/vector multiplication.
- Matrix/matrix multiplication.
- Rank updates by matrices or vectors.
- Direct matrix solvers.
- The unstructured sparse matrices supports the same operations as the structured ones, except they do not have direct solvers. However, their matrix/vector multiplication methods are optimised for use in iterative solvers.
- Matrix decompositions of dense and structured sparse matrices:
- LU and Cholesky.
- Eigenvalue decompositions for unsymmetrical dense matrices.
- Singular value decompositions for unsymmetrical dense matrices.
- Eigenvalue decompositions for symmetrical matrices (tridiagonal, banded, packed and dense).
- Orthogonal matrix decompositions for dense matrices (QR, RQ, LQ, and QL).
- Iterative solvers for unstructured sparse matrices from the Templates project:
- BiConjugate gradients.
- BiConjugate gradients stabilized.
- Conjugate gradients.
- Conjugate gradients squared.
- Chebyshev iteration.
- Generalized minimal residual (GMRES).
- Iterative refinement (Richardson's method).
- Quasi-minimal residual.
- A selection of algebraic preconditioners:
- Diagonal preconditioning.
- Symmetrical successive overrelaxation.
- Incomplete Cholesky.
- Incomplete LU.
- Incomplete LU with fill-in using thresholding.
- Algebraic multigrid by smoothed aggregation.
Sign in to keep reading
One more chapter is free with a Lably account.
Usage Examples
Example of Singular Value Decomposition (SVD):
<span id="mwTg"></span><span class="n" id="mwTw">SVD</span><span class="w" id="mwUA"> </span><span class="n" id="mwUQ">svd</span><span class="w" id="mwUg"> </span><span class="o" id="mwUw">=</span><span class="w" id="mwVA"> </span><span class="k" id="mwVQ">new</span><span class="w" id="mwVg"> </span><span class="n" id="mwVw">SVD</span><span class="p" id="mwWA">(</span><span class="n" id="mwWQ">matA</span><span class="p" id="mwWg">.</span><span class="na" id="mwWw">numRows</span><span class="p" id="mwXA">(),</span><span class="n" id="mwXQ">matA</span><span class="p" id="mwXg">.</span><span class="na" id="mwXw">numColumns</span><span class="p" id="mwYA">());</span> <span class="n" id="mwYQ">SVD</span><span class="w" id="mwYg"> </span><span class="n" id="mwYw">s</span><span class="w" id="mwZA"> </span><span class="o" id="mwZQ">=</span><span class="w" id="mwZg"> </span><span class="n" id="mwZw">svd</span><span class="p" id="mwaA">.</span><span class="na" id="mwaQ">factor</span><span class="p" id="mwag">(</span><span class="n" id="mwaw">matA</span><span class="p" id="mwbA">);</span> <span class="n" id="mwbQ">DenseMatrix</span><span class="w" id="mwbg"> </span><span class="n" id="mwbw">U</span><span class="w" id="mwcA"> </span><span class="o" id="mwcQ">=</span><span class="w" id="mwcg"> </span><span class="n" id="mwcw">s</span><span class="p" id="mwdA">.</span><span class="na" id="mwdQ">getU</span><span class="p" id="mwdg">();</span> <span class="n" id="mwdw">DenseMatrix</span><span class="w" id="mweA"> </span><span class="n" id="mweQ">S</span><span class="w" id="mweg"> </span><span class="o" id="mwew">=</span><span class="w" id="mwfA"> </span><span class="n" id="mwfQ">s</span><span class="p" id="mwfg">.</span><span class="na" id="mwfw">getS</span><span class="p" id="mwgA">();</span> <span class="n" id="mwgQ">DenseMatrix</span><span class="w" id="mwgg"> </span><span class="n" id="mwgw">Vt</span><span class="w" id="mwhA"> </span><span class="o" id="mwhQ">=</span><span class="w" id="mwhg"> </span><span class="n" id="mwhw">s</span><span class="p" id="mwiA">.</span><span class="na" id="mwiQ">getVt</span><span class="p" id="mwig">();</span>
Example of matrix multiplication:
<span id="mwjg"></span><span class="n" id="mwjw">DenseMatrix</span><span class="w" id="mwkA"> </span><span class="n" id="mwkQ">result</span><span class="w" id="mwkg"> </span><span class="o" id="mwkw">=</span><span class="w" id="mwlA"> </span><span class="k" id="mwlQ">new</span><span class="w" id="mwlg"> </span><span class="n" id="mwlw">DenseMatrix</span><span class="p" id="mwmA">(</span><span class="n" id="mwmQ">matA</span><span class="p" id="mwmg">.</span><span class="na" id="mwmw">numRows</span><span class="p" id="mwnA">(),</span><span class="n" id="mwnQ">matB</span><span class="p" id="mwng">.</span><span class="na" id="mwnw">numColumns</span><span class="p" id="mwoA">());</span> <span class="n" id="mwoQ">matA</span><span class="p" id="mwog">.</span><span class="na" id="mwow">mult</span><span class="p" id="mwpA">(</span><span class="n" id="mwpQ">matB</span><span class="p" id="mwpg">,</span><span class="n" id="mwpw">result</span><span class="p" id="mwqA">);</span>

