Project data
parent
2b98bd80f0
commit
798f82ecc1
@ -1,26 +1,36 @@
|
|||||||
function Z = projectData(X, U, K)
|
function Z = projectData(X, U, K)
|
||||||
%PROJECTDATA Computes the reduced data representation when projecting only
|
%PROJECTDATA Computes the reduced data representation when projecting only
|
||||||
%on to the top k eigenvectors
|
%on to the top k eigenvectors
|
||||||
% Z = projectData(X, U, K) computes the projection of
|
% Z = projectData(X, U, K) computes the projection of
|
||||||
% the normalized inputs X into the reduced dimensional space spanned by
|
% the normalized inputs X into the reduced dimensional space spanned by
|
||||||
% the first K columns of U. It returns the projected examples in Z.
|
% the first K columns of U. It returns the projected examples in Z.
|
||||||
%
|
%
|
||||||
|
|
||||||
% You need to return the following variables correctly.
|
% You need to return the following variables correctly.
|
||||||
Z = zeros(size(X, 1), K);
|
Z = zeros(size(X, 1), K);
|
||||||
|
|
||||||
% ====================== YOUR CODE HERE ======================
|
% ====================== YOUR CODE HERE ======================
|
||||||
% Instructions: Compute the projection of the data using only the top K
|
% Instructions: Compute the projection of the data using only the top K
|
||||||
% eigenvectors in U (first K columns).
|
% eigenvectors in U (first K columns).
|
||||||
% For the i-th example X(i,:), the projection on to the k-th
|
% For the i-th example X(i,:), the projection on to the k-th
|
||||||
% eigenvector is given as follows:
|
% eigenvector is given as follows:
|
||||||
% x = X(i, :)';
|
% x = X(i, :)';
|
||||||
% projection_k = x' * U(:, k);
|
% projection_k = x' * U(:, k);
|
||||||
%
|
%
|
||||||
|
|
||||||
|
U_reduce = U(:, 1:K);
|
||||||
|
|
||||||
|
m = size(X, 1);
|
||||||
% =============================================================
|
n = size(X, 2);
|
||||||
|
for i = 1:m
|
||||||
end
|
x = X(i, :)';
|
||||||
|
z = x' * U_reduce;
|
||||||
|
|
||||||
|
Z(i, :) = z;
|
||||||
|
end
|
||||||
|
|
||||||
|
assert(size(Z) == [m K]);
|
||||||
|
|
||||||
|
% =============================================================
|
||||||
|
|
||||||
|
end
|
||||||
|
Reference in New Issue