Calculating large number of generalized eigenvalues with Matlab on GPU - matlab

I have a lot of small matrices already stored on GPU card and now I want to calculate their generalized eigenvalues with another matrix.
Current code:
cov=gpuArray(cov) %7x7 matrix;
p=1:numel(ix1); %numel(ix1)... number of stored matrices
p=gpuArray(p);
%covs... 7x7xn matrix already on GPU, n is large (>100000)
g = arrayfun(#(x) eig(covs(:,:,x)/cov), p);
If I tried to run code I get error that function eig is unsupported, but I read that eig is supported on GPU.
So my question is what I did wrong (my first attempt with arrayfun) and if there is better way to calculate generalized eigenvalues.

Related

MATLAB: Eig algorithm and alternatives

I am simulating a physical system, where I need to calculate the eigenvalues and vectors of a very large (~10000x10000) matrix.
So far I have used the in-built Eig algorithm in MATLAB but it is very slow for large matrices. Is there other algorithms in MATLAB that would do a better job or can I somehow improve the performance of Eig? Specifically it turns out that I only need the first ~100 eigenvectors of the matrix starting from the smallest numerical eigenvalue. Is there a way to get the algorithm to calculate only the first N eigenvectors and eigenvalues to save computation time? Of course this would only work if the eigenvectors come out sorted but they seem to do so, because of the symmetry of the Matrix I am using.
Your matrix has mostly zeros, so you should make it a sparse matrix. You'll then be able to use EIGS to calculate a smaller number of eigenvalues and eigenvectors.
http://www.mathworks.com/help/matlab/ref/eigs.html

Very small numerical issues with hessian symmetry and sparse command

I am using IPOPT in MATLAB to run an optimization and I am running into some issues where it says:
Hessian must be an n x n sparse, symmetric and lower triangular matrix
with row indices in increasing order, where n is the number of variables.
After looking at my Hessian Matrix, I found that the non-symmetric elements it is complaining about are very close, here is an example:
H(k,j) = 2.956404205984938
H(j,k) = 2.956404205984939
Obviously these elements are close enough and there are some numerical round-off issues or something of the like. Also, when I call MATLABs issymmetric function with H as an input, I get false. Is there a way to forget about these very small differences in symmetry?
A little more info:
I am using an optimized matlabFunction to actually calculate the entire hessian (H), then I did some postprocessing before passing it to IPOPT:
H = tril(H);
H = sparse(H);
The tril command generates a lower triangular matrix, so these numeral differences should not come into play. So, the issue might be that it is complaining that the sparse command passes back increasing column indices and not increasing row indices. Is there a way to change this so that it passes back the sparse matrix in increasing row indices?
If H is very close to symmetric but not quite, and you need to force it to be exactly symmetric, a standard way to do this would be to say H = (H+H')./2.

Fast Computation of Eigenvectors of a Sparse Matrix

I am working on a project that involves the computation of the eigenvectors of a very large sparse matrix.
To be more specific I have a Matrix that is the laplacian of a big graph and I am interested in finding the eigenvector associated to the second smallest eigenvalue.
Of course Matlab takes ages to compute the eigenvectors, even because it computes all of them.
Any suggestions?
Thank you very much
Andrea
Have you tried this usage of eigs:
[v,c]=eigs(A,2,'sm');
for example:
A = delsq(numgrid('C',256));
[v,c]=eigs(A,2,'sm');
generates a ~50K x 50K sparse matrix and find its 2 smallerst eigenvalues and eigenvectors in about 1 second in my old laptop...

Octave/Matlab: PCA on sparse matrix: how to get only the most important eigenvectors?

I am using Octave and have a huge sparse matrix that I have to get the eigenvalues of. However, if I just use a function to get all eigenvalues and eigenvectors, the result will take up way too much space, since the input matrix is sparse for a reason.
How can I get only a limited number of the most important eigenvectors?
Use eigs instead of eig:
D = eigs(A,k);
This returns the k largest eigenvalues of the matrix A. According to this page, Octave does support eigs for sparse matrices. eigs uses different techniques than eig, is slower overall, and shouldn't generally be used except in the cases such as the one you describe.
Be sure to check out the options for the sigma argument in case you want the largest eigenvalues with respect to their real parts only, for example.
The Matlab documentation for eigs is here.

Matlab - calculating max eigenvalue of a big sparse (A'*A) matrix

I have a big (400K*400K) sparse matrix and I need to calculate the largest eigenvalue of A'*A.
The problem is that Matlab can't even calculate A' due to memory problems.
I also tried [a,b,c] = find(A) and then transpose by creating a transpose sparse matrix, but although the find() works, the sprase creation doesn't.
Is there a nice solution for this? it can be either in a matlab function or in another technique to calculate the largest eigenvalue for this kind of multiplication.
Thanks.
If A is sparse, see this thread and some discussion in this documentation (basically do it part by part) for a way to transpose it etc.
But now you need to calculate B=A'*A. The question is, is it still sparse? assuming it is, there shouldn't be a problem to proceed using the previous technique mentioned in the link.
Then after you've obtained B=A'*A, use eigs
eigs(B,1)
to obtain the largest magnitude eigenvalue.