[PCA]
- minor improvements git-svn-id: http://moon:8086/svn/matlab/trunk@95 801c6759-fa7c-4059-a304-17956f83a07c
This commit is contained in:
@@ -5,8 +5,9 @@
|
||||
% the raw image data from the kth 12x12 image patch sampled.
|
||||
% You do not need to change the code below.
|
||||
|
||||
function [xHat, k, xZCAWhite] = pca(x, retained_variance_target)
|
||||
|
||||
function [xHat, k, xZCAWhite, xPCAWhite] = pca(x, retained_variance_target)
|
||||
epsilon = 1e-1;
|
||||
|
||||
%%================================================================
|
||||
%% Step 1a: Implement PCA to obtain xRot
|
||||
% Implement PCA to obtain xRot, the matrix in which the data is expressed
|
||||
@@ -19,8 +20,8 @@ fprintf('Perform Singular Value Decomposition\n');
|
||||
[U,S,V] = svd(sigma);
|
||||
|
||||
fprintf('Perform PCA transformation\n');
|
||||
xrot = U' * x;
|
||||
|
||||
wpca = U' * diag(sqrt(1./(diag(S) + epsilon)));
|
||||
wzca = U * wpca;
|
||||
%%================================================================
|
||||
%% Step 2: Find k, the number of components to retain
|
||||
% Write code to determine k, the number of components to retain in order
|
||||
@@ -51,6 +52,7 @@ k = k
|
||||
% correspond to dimensions with low variation.
|
||||
|
||||
fprintf('Calculate xHat\n');
|
||||
xrot = U' * x;
|
||||
xHat = U(:, 1:k) * xrot(1:k, :);
|
||||
|
||||
%%================================================================
|
||||
@@ -58,10 +60,9 @@ xHat = U(:, 1:k) * xrot(1:k, :);
|
||||
% Implement PCA with whitening and regularisation to produce the matrix
|
||||
% xPCAWhite.
|
||||
|
||||
epsilon = 1e-1;
|
||||
%%% YOUR CODE HERE %%%
|
||||
fprintf('Calculate xPCAWhite\n');
|
||||
xPCAWhite = diag(sqrt(1./(diag(S) + epsilon))) * xrot;
|
||||
xPCAWhite = wpca * x;
|
||||
|
||||
%%================================================================
|
||||
%% Step 5: Implement ZCA whitening
|
||||
@@ -71,5 +72,5 @@ xPCAWhite = diag(sqrt(1./(diag(S) + epsilon))) * xrot;
|
||||
|
||||
%%% YOUR CODE HERE %%%
|
||||
fprintf('Calculate xZCAWhite\n');
|
||||
xZCAWhite = U * xPCAWhite;
|
||||
xZCAWhite = wzca * x;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user