%% Sample script for the "author" data % Some cleaning commands: close all; %Close all open figures clear %Clear the memory clc %Clear the command window % Download the data from the class website, so it can be loaded here: load author Y1=double(Y1); %Changes the data from "integers" to "floating point" %The data was saved as integers to save on memory. % We can visualize the "movie" figure(1) for j=1:109 A=reshape(Y1(:,j),120,160); imagesc(A); colormap(gray); axis equal; axis off; pause(0.1) end % Now that we've all had a good laugh, let's continue. %% Find the mean of the collection, subtract it (different label to save the original data) Ymean=mean(Y1,2); figure(2) imagesc(reshape(Ymean,120,160)); colormap(gray); axis equal; axis off; title('The Movie Mean'); X=Y1-repmat(Ymean,1,109); %% The SVD [U,S,V]=svd(X,'econ'); tempS=diag(S).^2; tempS=tempS/sum(tempS); %Normalized eigenvalues. figure(3) plot(tempS); title('The Eigenvalues of X^TX (Singular Values squared)') %% Visualize the basis vectors- Here are 4 of them figure(4) for j=1:4 subplot(2,2,j) imagesc(reshape(U(:,j),120,160)); colormap(gray); axis equal; axis off end title('The first four basis vectors'); %% Projection to R^2 Coord=U(:,1:2)'*X; %The matrix Xcoords is now 2 x 109 figure(5) plot(Coord(1,:),Coord(2,:),'.'); title('The movie data presented in the best two dimensional basis'); %% The Best two dimensional reconstruction as a movie Recon=U(:,1:2)*Coord; figure(6) for j=1:109 A=reshape(Recon(:,j),120,160); imagesc(A); colormap(gray); axis equal; axis off; M(j)=getframe; pause(0.05) end