Ning Sun avatar Ning Sun committed 292105c

finished pca functions

Comments (0)

Files changed (3)

mlclass-ex7/pca.m

 %       number of examples).
 %
 
-
+sigma = 1/m * X'*X;
+[U, S, V] = svd(sigma);
 
 
 

mlclass-ex7/projectData.m

 %                    projection_k = x' * U(:, k);
 %
 
-
+for i=1:size(X,1)
+  projection_k = X(i,:) * U(:,1:K);
+  Z(i,:) = projection_k;
+endfor
 
 
 % =============================================================

mlclass-ex7/recoverData.m

 %               Notice that U(j, 1:K) is a row vector.
 %               
 
-
+for i=1:size(Z,1)
+  z = Z(i,:);
+  rec = z * U(:, 1:K)';
+  X_rec(i,:) = rec;
+endfor
 
 % =============================================================
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.