-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecoverData.m
36 lines (29 loc) · 1.26 KB
/
recoverData.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function X_rec = recoverData(Z, U, K)
%RECOVERDATA Recovers an approximation of the original data when using the
%projected data
% X_rec = RECOVERDATA(Z, U, K) recovers an approximation the
% 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.
%
%reduce the original dimension to K dimension
Ureduce = U(:, 1:K);
% fprintf('\n The size of Z is : %d by %d',size(Z,1),size(Z,2) );
% fprintf('\n The size of Ureduce is : %d by %d',size(Ureduce,1),size(Ureduce,2) );
%compute aproximated values of X
%same as : X_rec = Ureduce * Z';
X_rec = Z * Ureduce' ;
% =============================================================
end