How do I perform a truncated SVD on a matrix?

Title says it all. I have an input matrix that I need to generate a truncated SVD for, so that I can calculate the SVD's reconstruction error. I know that svd is a function, but I can't find any functions anywhere that work specifically for a truncated SVD.

 Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 14 de Ag. de 2020
Simply use the standard svd-function, then you can simply calculate the reconstruction-error at different truncation-levels by setting the eigenvalues outside of your trunkation to zero (that is what you do when trunkating, well close enough. If you want you can simply trunkate the U, S and V matrices too, but this way you cut out all thinking). Something like this:
Im = imread('cameraman.tif');
[U,S,V] = svd(double(Im));
subplot(1,3,1),imagesc(Im)
lambda = diag(S);
l50 = lambda;
l50(51:end) = 0;
subplot(1,3,2)
imagesc(U*diag(l50)*V')
subplot(1,3,3)
imagesc(double(Im)-U*diag(l50)*V')
HTH

5 comentarios

David Haydock
David Haydock el 14 de Ag. de 2020
I think I understand. The issue is I am not applying this to an image, its a dataset. The dataset is a 17x200 double, so I can't perform some of these calculations, because the dimensions of each don't agree.
S = 17x200
lambda = 17x1
U = 17x17
V = 200x200
In this case, would truncation mean i need to truncate V, so that the U*S*V calculatiuon is possible?
If you try my example and do:
imagesc(diag(l50))
You should be able to zoom in on the non-zero part of the eigenvalue-matrix in the diagonal, and after some pondering realize that all the zero-parts of the diagonal doesn't contribute to the final product. You can go about this in a couple of ways to make your case work:
D = randn(17,200);
[U,S,V] = svd(D);
lambda = diag(S);
lambda(11:end) = 0;
Sf = diag(lambda);
Sf(17,200) = 0; % Make Sf same size as S
S10 = diag(lambda(1:10)); % Minimum size
S17 = diag(lambda); % slightly larger than S10
subplot(1,3,1)
imagesc(U*Sf*V') % Truncation by multiplication with many zeros
subplot(1,3,2)
imagesc(U(:,1:17)*S17*V(:,1:17)') % Truncation by multiplication of few zeros
imagesc(U(:,1:10)*S10*V(:,1:10)') % Snug truncation
HTH
David Haydock
David Haydock el 14 de Ag. de 2020
Thank you for this, it is helpful.
It was recommended that I use a truncated SVD for this dataset because I am running the same dataset through a more complex model, and this truncated SVD would be used as a conditional average to compare the error in the more complex model to.
I asked my initial question about SVD to get the ball rolling, since I am not so familiar with SVD, and hoped it would help it make more sense.
You have answered my proposed question regardless, thank you.
If you could assist me in shining light on why SVD would be used as a conditional average I would appreciate it, but if not, again, thank you.
Bjorn Gustavsson
Bjorn Gustavsson el 16 de Ag. de 2020
For initial overview-reading I typically recommend wikipedia (SVD low-rank approximation) for getting the very first overview. Then you can branch out in your desired directions - I mainly use SVD for inverse-problems, your needs might take you in other directions.
Then, the truncated SVD is the "best lower-rank approximation" (minimum Frobenius-norm) of your original matrix. As for how that relates to conditional average is not clear to me. I've only ever encountered conditional averaging in the context of averaging time-serieses syncronized relative to some triggering event (that might occur at "random" instanses in time). To me that seems to be something completely different than a truncated SVD-approximation. I suggest going back to whomever told you this and ask for a more detailed explanation...
David Haydock
David Haydock el 16 de Ag. de 2020
Thank you Bjorn!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 14 de Ag. de 2020

Comentada:

el 16 de Ag. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by