Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 8/Programming Assignment - 7/ex7/recoverData.m
863 views
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
9
% You need to return the following variables correctly.
10
X_rec = zeros(size(Z, 1), size(U, 1));
11
12
% ====================== YOUR CODE HERE ======================
13
% Instructions: Compute the approximation of the data by projecting back
14
% onto the original space using the top K eigenvectors in U.
15
%
16
% For the i-th example Z(i,:), the (approximate)
17
% recovered data for dimension j is given as follows:
18
% v = Z(i, :)';
19
% recovered_j = v' * U(j, 1:K)';
20
%
21
% Notice that U(j, 1:K) is a row vector.
22
%
23
U_reduce = U(:,[1:K])
24
X_rec = Z * U_reduce';
25
26
% =============================================================
27
28
end
29
30