Path: blob/master/Week 8/Programming Assignment - 7/ex7/recoverData.m
863 views
function X_rec = recoverData(Z, U, K)1%RECOVERDATA Recovers an approximation of the original data when using the2%projected data3% X_rec = RECOVERDATA(Z, U, K) recovers an approximation the4% original data that has been reduced to K dimensions. It returns the5% approximate reconstruction in X_rec.6%78% You need to return the following variables correctly.9X_rec = zeros(size(Z, 1), size(U, 1));1011% ====================== YOUR CODE HERE ======================12% Instructions: Compute the approximation of the data by projecting back13% onto the original space using the top K eigenvectors in U.14%15% For the i-th example Z(i,:), the (approximate)16% recovered data for dimension j is given as follows:17% v = Z(i, :)';18% recovered_j = v' * U(j, 1:K)';19%20% Notice that U(j, 1:K) is a row vector.21%22U_reduce = U(:,[1:K])23X_rec = Z * U_reduce';2425% =============================================================2627end282930