Posted Saturday, May 08, 2010 11:05 AM
|
|
|
|
| I'm trying to create a 26000x26000 matrix (admittedly very big), which is giving me an out of memory error and I'd like to know if there's anything I can do about this. I tried creating all of my matricies as SparseMatrix (most of the tables' contents are zeros), but when I try to SVD it (which is all I want to do with the matrix apart from multiplication), it gives me an out-of-memory error message:SparseMatrix matq = new SparseMatrix(ncols, ncols);SparseMatrix matw = new SparseMatrix(nrows, nrows); SparseMatrix mathc = new SparseMatrix(nrows, ncols); //...tables are populated... SparseMatrix mat = matw * mathc * matq;Matrix bar = mat.ToDense();SVD svdtable = new SVD(bar);Are there plans to make a sparsematrix SVD function? Thanks!
Jeffrey Baron
jbaron@mediamark.com
|
|
Posted Sunday, May 09, 2010 3:56 AM
|
|
|
|
| Hello, Currently NML does not have a direct method for computing the Singular Value Decomposition of a SparseMatrix object. In your code you attempt to convert a SparseMatrix to a dense matrix, but a dense matrix requires more memory and that causes the out of memory error. A dense matrix of that size would require 26000 X 26000 X 8 = 5,408,000,000 bytes, about 5Gb or RAM. The SVD method uses internally a work area which is 6-8 times larger than the size of the original matrix, this means you would need about 40Gb. Even if you had and could use that large amount of memory, it would take ages to compute the singular value decomposition of a matrix because the SVD computation is an O(n^3) process, meaning that when the matrix size is doubled the operation count is multiplied by a factor of 8. It is possible that there is an alternative way to solve the problem. Do you need to compute all the singular values and vectors or just a few of them?
Trifon Triantafillidis | Lead Developer |
|
|
|
Posted Sunday, May 09, 2010 9:19 AM
|
|
|
|
| Thanks for getting back to me over the weekend. The situation isn't quite as dire as I described. I've been doing some investigating and the matrix that I'm densing and trying to pass into SVD is, in fact, only 26203x11 cells (2.3 meg), but this too seems to blow the stack on SVD. With this new info, any thoughts? Thanks!
Jeffrey Baron
jbaron@mediamark.com
|
|
Posted Sunday, May 09, 2010 11:58 AM
|
|
|
|
|
|
Posted Thursday, May 13, 2010 10:17 AM
|
|
|
|
| Trifon, What are these alternatives that you have mentioned? Are they destinated to generate just a few singular values and vector instead of all the three matrices? For example: From a matrix 26.000 X 40.000 And generate: 26.000 X 150 , 150 X 150 & 40.000 X 150 Instead of all
|
|
Posted Friday, May 14, 2010 2:49 AM
|
|
|
|
| Hello guile, See the uploaded document in this post. An algorithm that would converge to the dominant singular vectors would be as follows: Let A be a m x n matrix. Define u(0) as an m-sized non zero vector and v(0) as an n-sized non zero vector. Start iterating: Loop until convergence ( e.g ( u(t) - u(t-1) )^2 < epsilon ) u(t) = A * v(t-1) / Sqrt( v(t-1) * v(t-1) ) v(t) = u(t) * A / Sqrt( u(t-1) * u(t-1) ) Repeat Then u(t) t->oo will converge to the dominant left singular vector, v(t) to the dominant right singular vector and the normalization factor Sqrt( v(t)*v(t)  will converge to the larger singular value. After finding u1, s1, v1 then we may subtract their product from matrix A and get A(2). Repeating the process we find u2, s2, v2 and so on.
Trifon Triantafillidis | Lead Developer |
|
|
|
Posted Monday, May 17, 2010 10:43 AM
|
|
|
|
| Thanks a lot, Trifon I will check it.
|
|
Posted Monday, May 17, 2010 12:52 PM
|
|
|
|
| guille, I am working on some sparse SVD routines now, do you want to mail me your matrix (in sparse format) so that I will run some tests with it?
Trifon Triantafillidis | Lead Developer |
|
|
|
Posted Thursday, May 20, 2010 4:29 AM
|
|
|
|
Yes, I do.But I´m afraid that it is not posible for me at this moment to send it in sparse format. I work with BML 2.5. I will pursache later a version with sparse matrices but before, I have to organize all. If you want, I can send you by ftp or something like that, the dense matrix in a binay format. Do you want me to send it? G
|
|
|
|