Exercise: PCA in 2D
From Ufldl
for
Exercise: PCA in 2D
Jump to:
navigation
,
search
In this exercise you will implement PCA and PCA whitening, as described in the notes, to generate the images displayed in the notes yourself. You will build on the starter code that has been provided to you at LOCATION HERE. You need only write code at the places indicated by "YOUR CODE HERE" in the files. The only file you need to modify is <tt>pca_2d.m</tt>. Implementing this exercise will make the next exercise significantly easier to understand and complete. === Step 0: Load data === The starter code contains code to load 45 2D data points. When plotted using the scatter function, the results should look like the following [[File:raw_images_2d.png|400px|alt=Raw images|Raw images]] === Step 1: Implement PCA === ==== Step 1a: Implement PCA ==== In this step, you will implement PCA to obtain <math>x_{rot}</math>, the matrix in which the data is "rotated" to the basis comprising the principal components (i.e. the eigenbasis of <math>\Sigma</math>). As mentioned in the implementation notes, you should make use of MATLAB's <tt>svd</tt> function here. Plot the resulting basis on top of the given data points. You may find it useful to use MATLAB's <tt>hold on</tt> and <tt>hold off</tt> functions. [[File:pca_2d_basis.png | 400px]] ==== Step 1b: Check xRot ==== Use the scatter function to check that xRot looks as it should, which should be something like the following: [[File:pca_xrot_2d.png|360px]] === Step 2: Dimension reduce and replot === In the next step, set <math>k</math>, the number of components to retain, to be 1 (we have already done this for you). Compute the resulting <math>xHat</math> and plot the results, which should look like the following: [[File:pca_xhat_2d.png|400px]] === Step 3: PCA Whitening === Implement PCA whitening using the formula from the notes. The resulting <tt>xPCAWhite</tt> should look like the following: [[File:pca_white_2d.png|400px]] === Step 4: ZCA Whitening === Implement ZCA whitening and plot the results. The results should look like the following: [[File:zca_white_2d.png|400px]]
Return to
Exercise: PCA in 2D
.
Views
Page
Discussion
View source
History
Personal tools
Log in
ufldl resources
UFLDL Tutorial
Recommended Readings
wiki
Main page
Recent changes
Random page
Help
Search
Toolbox
What links here
Related changes
Special pages