|
FAQ
Frequently Asked Questions
Featured How can I compute the eigenvalues and/or singularvalues of a general sparse matrix?MTJ uses LAPACK for computing eigen- and singularvalues. LAPACK will only do this for dense or structured sparse matrices, and not for general sparse matrices (such as the compressed row matrices). Its singular value computer only operates on dense matrices, and if eigenvectors or singular vectors are to be computed, they will be stored as the columns in dense matrices. The power method and its derivatives is a simple way to get portions of the matrix spectrum, and it is easy to implement on top of MTJ. More sophisticated methods are described in the Eigenvalue Templates book. Lastly, outside of Java there is the Fortran package ARPACK which is a well regarded library for sparse spectral analysis. MTJ fails with UnsupportedClassVersionErrorYou must use Java 5 or newer. The older versions of Java are not supported. How does MTJ compare to other Java matrix packages?The two primary alternatives are JAMA and Colt. JAMA is a small and easy to use package for dense matrix computations. It can compute all common decompositions and solve linear and least squares systems. It is based on the same algorithms as found in LINPACK and EISPACK. MTJ is a much larger package which includes more matrix types, is based on the more modern LAPACK library, and it supports general sparse computations. Colt is a collection of libraries for high performance computations. It includes much more than just matrix algorithms, such as its own collection types, statistical methods, random number generators, and multidimensional arrays. Its linear algebra part can be divided into two parts: one which is largely Jama, but with some performance enhancements; and a second which consists of 1D, 2D, and 3D matrices storing doubles and Objects, holding them in either dense or sparse arrays. The sparse arrays are implemented as either hashmaps, or using compressed rows. MTJ does not supply 3D matrices, as they are not actually linear operators (more like 3D arrays). However, MTJs sparse matrices are highly optimized and it supplies a large set of iterative solvers and preconditioners. The capability of its dense matrices to use a native BLAS ensures that they will always attain optimal performance on a given machine. Does MTJ support matrices containing entries other than double (i.e. Object or complex)?No. This is partly because MTJ is built on top of BLAS, which limits the numerical types to reals and complex numbers, and partly because the Java translation of BLAS and LAPACK, JLAPACK, is only available in double precision. Also, CBLAS and CLAPACK differ somewhat in how complex numbers are to be treated. Must I compile a native BLAS library to use MTJ?No. In the absence of a native BLAS MTJ automatically uses JLAPACK, the Java translation. It is only for larger problems that you should expect performance differences, and even then it may not be large. Earlier versions included additional functionalityPrevious incarnations of MTJ included some support for parallelisation and some simple sparse eigenvalue solvers. These were removed, and the interfaces of the package were simplified in the current version. The reason was to make it simpler to use, remove sources for bugs and other problems, and to ensure a higher overall quality of each release. Also, this functionality was seldom used by target applications. How do I invert a matrix?DenseMatrix A = ... DenseMatrix I = Matrices.identity(n); DenseMatrix AI = I.copy(); A.solve(I, AI); If you just need to solve the linear system AX=B, it is faster to do just solve it directly, like this: DenseMatrix A = ... DenseMatrix B = ... DenseMatrix X = B.copy(); A.solve(B, X); After performing a QR, EVD, SVD, etc decomposition, my matrix changedThis is intentionally. The factor methods overwrite the passed matrix to save memory, a design inherited from the use of LAPACK. However, the factorize methods operate on a copy, and can be used instead. Another option is to pass a copy of the matrix to the factor method. |
Proposed question: How do I tell if MTJ is using Atlas or not?
How do I enter a symmetric block diagonal matrix as a distributed matrix, so that each block can get a thread of it's own?
Hi, I have a problem: after this statement:
I get the : Exception in thread "AWT-EventQueue?-0" java.lang.NoClassDefFoundError?: org/netlib/lapack/Dgeev Exception. I cant get this working and i would appreciate if you give me a hint on this.. here is the code snippet where the error occurs: // Find the needed workspace /this line =>/ LAPACK.getInstance().dgeev(jobLeft.netlib(), jobRight.netlib(), n, new double0?,How is it possible to calculate the second smallest eigenvalue and eigenvector of a big (100k 100k) symmetric matrix?
I tried to run an application with matrix-toolkits-java and I got an exception:
Exception in thread "main" java.lang.NoClassDefFoundError??: org/netlib/blas/BLAS
(I was using jlapack from http://www.netlib.org/java/f2j/ but there seems to be no such class in any of the jar files I found in jlapack). After a while, I figured out that in fact I had to use netlib-java (also hosted on google code) in addition to jlapack. Maybe this information could be added to the FAQ ?
@bottyan
Try this code: http://www.cs.princeton.edu/introcs/95linear/Eigenvalues.java.html
It is not superly fast, because it's not parallelized or anything but it will do the job in measurable time :)
How can I solve a big matrix system (ex.: 106 x 106) with MTJ?
@edivaldofontes
Is that a dense matrix? If so, how are you storing the roughly 8,000 GB of data?
If it is suitably dense, then MTJ can definitely help?
@bottyan
Consider using Lanczos' algorithm. It should work very well for getting the top two eigenvectors and values. See http://en.wikipedia.org/wiki/Lanczos_algorithm
How are the Eigenvectors sorted? I created and instance of SymmDenseEVD (no.uib.cipr.matrix.SymmDenseEVD) to find the eigenvalues and eigenvectors with getEigenvalues() and getEigenvectors(), respectively. I'm not sure how the eigenvectors are sorted. Each column of the eigenvector matrix corresponds to the eigenvalue array that is in ascending order? Thanks in advance!
@bottyan, @ted.dunning
Re: finding some eigenvalues/eigenvectors of very large sparse matrices.
The FAQ references the ARPACK library, which implements various suitable Arnoldi/Lanczos methods. MTJ includes the netlib-java library, which happens to wrap ARPACK. Unfortunately, the wrappers aren't documented, but if they work, they are the way to go.
How can I invert an sparse matrix? The thing is that I don't see a solve method Ax=B where x is a matrix (identity matrix for calculating the inverse).
Hi,
I have a problem after a block of code nearly like that :
SparseVector? X= new SparseVector?(dico.getTaille()); int j=0; String mot; for (int i = 0; i < file.getTaille();i++){
}
I don't understand why (X.getIndex().length!=X.getData().length)==true for nearly all the SparseVector? i've created that way.
Hello,
for whatever reason returns Matrices.identity() a DenseMatrix instead of a BandMatrix?
Thanks for your help!
best regards Micha
At one point you were talking about combining with Commons Math. What happened to that? http://mail-archives.apache.org/mod_mbox/incubator-hama-dev/200905.mbox/%3Ceb4706e0905221017n75bbf14bwe3ef6aec42adb7e2@mail.gmail.com%3E
how to calculate the eigen vector for n*n matrix?pls help me