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, , ifam-by-n:
um-by-korthonormal columns
sk-by-kdiagonal
vn-by-korthonormal columns
u*s*v'closest rankkapproximationa
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
svdsbest used find few singular values of large, sparse matrix. find singular values of such matrix,svd(full(a))perform bettersvds(a,min(size(a))).
Comments
Post a Comment