matlab - svds not working for some matrices? -


here testing function:

            function diff = svdtester()              y = rand(500,20);             [u,s,v] = svd(y);              %{             y = sprand(500,20,.1);             [u,s,v] = svds(y);             %}              diff_mat = y - u*s*v';             diff = mean(abs(diff_mat(:)));              end 

there 2 similar parts: 1 finds svd of random matrix, other finds svd of random sparse matrix. regardless of 1 choose comment (right second 1 commented-out), compute difference between original matrix , product of svd components , return average absolute difference.

when using rand/svd, typical return (mean error) value around 8.8e-16, zero. when using sprand/svds, typical return values around 0.07, terrible considering sparse matrix 90% 0's start with.

am misunderstanding how svd should work sparse matrices, or wrong these functions?

yes, behavior of svds little bit different svd. according matlab's documentation:

[u,s,v] = svds(a,...) returns 3 output arguments, , if a m-by-n:

u m-by-k orthonormal columns

s k-by-k diagonal

v n-by-k orthonormal columns

u*s*v' closest rank k approximation a

in fact, k somethings 6, rather "rude" approximation. more exact approximation specify k min(size(y)):

[u, s, v] = svds(y, min(size(y))) 

and error of same order of magnitude in case of svd.

p.s. also, matlab's documentations says:

note svds best used find few singular values of large, sparse matrix. find singular values of such matrix, svd(full(a)) perform better svds(a,min(size(a))).


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -