Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 834fd69e authored by DIB Elian's avatar DIB Elian
Browse files

Added factorization

parent 96a01dff
No related branches found
No related tags found
No related merge requests found
function [B,C,U,S,V] = factorize(M,k)
%FACTORIZE Summary of this function goes here
% Detailed explanation goes here
Mask = isnan(M);
M(Mask) = 0;
[U,S,V] = utils.svd_nsq(M);
B = U(:,1:k)*S(1:k,1:k);
C = V(:,1:k)';
B(any(Mask,2),:) = nan;
end
\ No newline at end of file
function [U,S,V] = svd_nsq(Z)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SVD accelerated for non-square matrices
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[m, n] = size(Z);
if 2*m < n
ZZT = Z*Z';
[U, S2, Ua] = svd(ZZT);
S = sqrt(S2);
Sinv = diag(1./diag(S));
V = Z' * U * Sinv;
return;
end
if m > 2*n
ZTZ = Z'*Z;
[Va, S2, V] = svd(ZTZ);
S = sqrt(S2);
Sinv = diag(1./diag(S));
U = Z * V * Sinv;
return;
end
if(m==n)
[U,S,V] = svd(Z);
else
[U,S,V] = svd(Z,'econ');
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment