recoverData.m 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. function X_rec = recoverData(Z, U, K)
  2. %RECOVERDATA Recovers an approximation of the original data when using the
  3. %projected data
  4. % X_rec = RECOVERDATA(Z, U, K) recovers an approximation the
  5. % original data that has been reduced to K dimensions. It returns the
  6. % approximate reconstruction in X_rec.
  7. %
  8. % You need to return the following variables correctly.
  9. X_rec = zeros(size(Z, 1), size(U, 1));
  10. % ====================== YOUR CODE HERE ======================
  11. % Instructions: Compute the approximation of the data by projecting back
  12. % onto the original space using the top K eigenvectors in U.
  13. %
  14. % For the i-th example Z(i,:), the (approximate)
  15. % recovered data for dimension j is given as follows:
  16. % v = Z(i, :)';
  17. % recovered_j = v' * U(j, 1:K)';
  18. %
  19. % Notice that U(j, 1:K) is a row vector.
  20. %
  21. U_reduce = U(:, 1: K);
  22. % U_reduce (nxk), Z(mxk)
  23. %
  24. X_rec= (U_reduce * Z')';
  25. % =============================================================
  26. end