Commits

Ning Sun committed 292105c

finished pca functions

  • Participants
  • Parent commits c93126b

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
 
 % =============================================================