How can I increase the calculation speed in using eig()?
22 views (last 30 days)
Show older comments
Hi, here is a problem. I want to do a POD or PCA by matlab. But I don't want to use the inner function like princomp(), because it has some limitations. So I will try it by myself. In this process, I need to get the eigenvectors and eigenvalues of a covariance matrix which is a symmetric matrix. As this covariance matrix is huge(78505*78505), it takes me a long time to calculate it by eig(). Now 24 hours have passed away, it hasn't been finished. The use of cpu and memory can be seen in the figure. So I want to know whether there is another way to accelerate such calculation or change to another method to get the eigenvectors and eigenvalues quickly. Thank you very much!

4 Comments
Matt J
on 31 Dec 2015
Edited: Matt J
on 31 Dec 2015
It's not sparse or tridiagonal.
It strains credulity that you can't approximate some/many entries of the co-variance matrix as zero. Where do 78505 variables, all so tightly correlated with each other, come from?
In any case, it seems unwise to attack a problem in such a brute force manner. Even though you clearly have a powerful computer with above average RAM, you are consuming much of that memory just holding the covariance matrix, with too little memory left over to do any processing.
The only likely path to useful advice from us is explaining more how this specific covariance matrix was derived. Then we can all start thinking about how the particulars of that process can be exploited.
Accepted Answer
Matt J
on 2 Jan 2016
Edited: Matt J
on 2 Jan 2016
Then I use the matrix (120*78505) to get the covariance matrix (78505*78505) by multiplying the matrix (120*78505) with its transposition. So this is how the covariance matrix comes from.
If the 120 x 78505 matrix is A and the covariance matrix is C=A.'*A, then C only has 120 potentially non-zero eigenvalues. You can obtain the non-trivial eigenvalues and the corresponding eignvectors from the economy-SVD of A.' as follows,
[U,S]=svd(A.',0);
The eigenvalues are given by
eigenvalues= diag(S).^2;
and the corresponding eigenvectors are the columns of U. Naturally, this is a much simpler and faster computation than what you were attempting brute force.
6 Comments
Christine Tobler
on 5 Jan 2016
Try using
[u,s,v] = svd(A, 'econ')
This will only compute the first 120 singular vectors in u and v. Otherwise, v is of size 96455x96455 instead of the 96455x120 you actually need.
Matt J
on 5 Jan 2016
Edited: Matt J
on 5 Jan 2016
I need to conduct the row reduction not the column reduction. So it should be [u,s,v]=svd(A) not [u,s]=svd(A.').
There's no salient difference. If V,S,U is the decomposition of A, then the decomposition of A.' is U,S,V. In both cases, the eigenvectors of the covariance matrix are the columns of U (and V is not needed).
More Answers (3)
Walter Roberson
on 31 Dec 2015
I do not know the efficiency order, but in that particular case of symmetric positive definite then you can use Cholesky decomposition (or possibly QR)
Ah, apparently in theory the Cholesky decomposition can be done in order 2/3 * N^3; http://modis-atmos.gsfc.nasa.gov/new_reference/data/papers/Stamnes_et_al_A.1988.pdf
For your matrix that would still be over order 3*10^14 operations and that is Just Plain Going To Take Time.
Christine Tobler
on 1 Jan 2016
If you need all the eigenvalues and all the eigenvectors, there's not faster way than eig, I'm afraid. Here's an older thread about using the distributed computing toolbox for a large dense eigenvalue problem, if this is available to you:
By the way, do you need all eigenvectors, or would all eigenvalues, with the option to compute selected eigenvectors later, be sufficient?
2 Comments
Balu
on 4 Feb 2025
Use the parallel computation toolbox. This needs a processor with parallel cores.
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!