1
0
Fork 0
This repository has been archived on 2019-12-21. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
coursera-ml-007-exercises/ex7/recoverData.m

37 lines
1.1 KiB
Mathematica
Raw Normal View History

2014-11-17 21:58:10 +01:00
function X_rec = recoverData(Z, U, K)
2014-11-19 21:22:28 +01:00
%RECOVERDATA Recovers an approximation of the original data when using the
2014-11-17 21:58:10 +01:00
%projected data
2014-11-19 21:22:28 +01:00
% X_rec = RECOVERDATA(Z, U, K) recovers an approximation the
2014-11-17 21:58:10 +01:00
% original data that has been reduced to K dimensions. It returns the
% approximate reconstruction in X_rec.
%
% You need to return the following variables correctly.
X_rec = zeros(size(Z, 1), size(U, 1));
% ====================== YOUR CODE HERE ======================
% Instructions: Compute the approximation of the data by projecting back
% onto the original space using the top K eigenvectors in U.
%
% For the i-th example Z(i,:), the (approximate)
% recovered data for dimension j is given as follows:
% v = Z(i, :)';
% recovered_j = v' * U(j, 1:K)';
%
% Notice that U(j, 1:K) is a row vector.
2014-11-19 21:22:28 +01:00
%
U_reduce = U(:, 1:K);
2014-11-17 21:58:10 +01:00
2014-11-19 21:22:28 +01:00
for i = 1:size(Z, 1)
z = Z(i, :)';
2014-11-17 21:58:10 +01:00
2014-11-19 21:22:28 +01:00
x_rec = z' * U_reduce';
X_rec(i, :) = x_rec;
end
2014-11-17 21:58:10 +01:00
% =============================================================
end