0

I have a source and target matrix which I'm creating an adjacency matrix using sparse function.

W = sparse(w1(:,1),w1(:,2),1,n,n);

my n is approximately equal to 540,000 (this is a subset of the data I have). Creating the matrix itself is pretty computationally easy. However, I need to obtain eigenvalues of said matrix. More precisely

rho = max(abs(eigs(W)));

That one line of code takes forever. Looking a bit into this, I was led to believe that obtaining eigenvalues of a sparse matrix is computationally costly. I can not use a full command, say uint8(full(W)), since I end up exceeding maximum matrix size/ram capacity (130GB of memory). However, it appears that if format was uint8, I would be able to create said full adjacency matrix.

Any help is appreciated. What I think I need is one of the following

  • An alternative way of constructing the adjacency matrix directly as a full uint8;
  • A way to convert the adjacency matrix that I created to a full uint8; or
  • An alternative way to calculate these eigenvalues
Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • When writing my answer I assumed w1 to be unsorted and to large to be sorted quickly. If this is not true, building up the matrix column by column is possible, which needs less memory than the answer I wrote. – Daniel Jan 12 '16 at 18:44
  • A `uint8` matrix of size n*n won't fit your memory. It requires `540000.^2/1024^3` GB memory, which is 271GB. With such large matrices, using `sparse` is probably the best choice. – Daniel Jan 12 '16 at 18:47
  • Please correct me if I am wrong, but I just realized that `eig` and `eigs` functions only operates in double type matrices. It seems that I have no alternative way of calculating these eigenvalues on matlab. – Paulo Quinderé Saraiva Jan 12 '16 at 21:07
  • It's not stated in the documentation, but double is probably the only class both functions support. `eig` is also available for `sym` – Daniel Jan 12 '16 at 21:21

2 Answers2

0

With W = sparse(w1(:,1),w1(:,2),1,n,n); you are creating a matrix which holds only 0 or 1. While the datatype uint8 is not possible, you can choose to create a sparse logical matrix instead. This way you avoid using 64bit data types

W = sparse(w1(:,1),w1(:,2),true,n,n);
W = uint8(full(W));
Daniel
  • 36,610
  • 3
  • 36
  • 69
0

Knowing that your plan to use integers is not the solution, I read your question again and realized you are wasting a lot of performance not properly using eigs. If you are only interested in the by magnitude largest eigenvalue, calculate only this eigenvalue.

rho = abs(eigs(W,1));
Daniel
  • 36,610
  • 3
  • 36
  • 69
  • This approach is definitely better. I have tested on submatricies of `W`, however, if I go beyond 10,000 things start to get messy again. Since, `rho=max(abs(eigs(W)))` is the spectral radius of `W`, I was planning on using an approximation to Gelfand's Formula, say `normest(W^50)^(1/50)`. – Paulo Quinderé Saraiva Jan 13 '16 at 00:36