Pca matlab code_matlab_central
April 4, 2018 | Author: Anonymous |
Category:
Documents
Description
1. Search: NewsgroupCreate Account Log InFile Exchange Answers Newsgroup Link Exchange Blogs Trendy Cody Contest MathWorks.comMATLAB Central > MATLAB Newsreader > pca(principle component analysis) matlab code r...Add thread to MyWatch List What is aWatch List?Thread Subject: pca(principle component analysis) matlab code result different fromSubject: pca(principle component analysis) matlab code result different fromFrom: Elizabeth HONGDate: 7 Apr, 2012 21:55:11Message: 1 of 3Reply to this messageAdd author to My Watch ListView original formatFlag as spamThere is princomp function to do pca available in matlab library, specified in http://www.mathworks.com/help/toolbox/stats/princomp.html.But Ialso read "A Tutorial on Principal Component Analysis" by Jonathon Shlens (which could be easily searchedon web). The codes given in that article is straightforward and I could not find anything wrong.The code is like:function [signals,PC,V] = pca1(data)% PCA1: Perform PCA using covariance.% data - MxN matrix of input data% (M dimensions, N trials)% signals - MxN matrix of projected data% PC - each column is a PC% V - Mx1 matrix of variances[M,N] = size(data);% subtract off the mean for each dimensionmn = mean(data,2);data = data - repmat(mn,1,N);% calculate the covariance matrixcovariance = 1 / (N-1) * data * data;% find the eigenvectors and eigenvalues[PC, V] = eig(covariance);% extract diagonal of matrix as vectorV = diag(V);% sort the variances in decreasing order[junk, rindices] = sort(-1*V);V = V(rindices);PC = PC(:,rindices);% project the original data setsignals = PC *data;When Itry to run pca on the same matrix, the result (eigenvalues of covariance, i.e. V in above code and latent inmatlab code) given by the above code is different from the result given by matlab code.Is there anywhere I could see the details of matlab pca code? Or is there anyone know the difference between twocodes ?ElizabethSubject: pca(principle component analysis) matlab code result different fromFrom: MatijaDate: 7 Apr, 2012 22:16:11Message: 2 of 3Reply to this messageAdd author to My Watch ListView original formatFlag as spamHere you have some nice examples of PCA (check the first one) explained:http://www.face-rec.org/source-codes/As the name implies, they are related to face recognition.Subject: pca(principle component analysis) matlab code result differentFrom: Ilya NarskyDate: 8 Apr, 2012 00:00:19Message: 3 of 3pca(principle component analysis) matlab code r... - Newsreader - MAT... http://www.mathworks.in/matlabcentral/newsreader/view_thread/3188441 of 2 4/16/2013 10:15 AM 2. Site Help Patents Trademarks Privacy Policy Preventing Piracy Terms of UseFeatured MathWorks.com Topics: New Products Support Documentation Training Webinars Newsletters MATLAB Trials CareersReply to this messageAdd author to My Watch ListView original formatFlag as spamOn 4/7/2012 5:55 PM, Elizabeth HONG wrote:> There is princomp function to do pca available in matlab library,> specified in http://www.mathworks.com/help/toolbox/stats/princomp.html.>> But I also read "A Tutorial on Principal Component Analysis" by Jonathon> Shlens (which could be easily searched on web). The codes given in that> article is straightforward and I could not find anything wrong.> The code is like:> function [signals,PC,V] = pca1(data) % PCA1: Perform PCA using> covariance. % data - MxN matrix of input data % (M dimensions, N trials)> % signals - MxN matrix of projected data % PC - each column is a PC % V> - Mx1 matrix of variances [M,N] = size(data); % subtract off the mean> for each dimension mn = mean(data,2); data = data - repmat(mn,1,N); %> calculate the covariance matrix covariance = 1 / (N-1) * data * data; %> find the eigenvectors and eigenvalues [PC, V] = eig(covariance); %> extract diagonal of matrix as vector V = diag(V); % sort the variances> in decreasing order [junk, rindices] = sort(-1*V); V = V(rindices); PC => PC(:,rindices); % project the original data set signals = PC *data;>> When I try to run pca on the same matrix, the result (eigenvalues of> covariance, i.e. V in above code and latent in matlab code) given by> the above code is different from the result given by matlab code.>> Is there anywhere I could see the details of matlab pca code? Or is> there anyone know the difference between two codes ?>> ElizabethTo see the MATLAB code, type edit princomp in your command window. Ortype which princomp to see where the file is.PRINCOMP takes a predictor matrix in which rows represent observationsand columns represent variables. Your PCA1 function uses the oppositeconvention. So you would have to compare output of princomp(X) with thatof pca1(X). -IlyaTags for this ThreadAdd a New Tag:AddSeparated by commasEx.: root locus, bodeWhat are tags?A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.Anyone can tag a thread. Tags are public and visible to everyone.Feed for this ThreadContact us© 1994-2013 The MathWorks, Inc.pca(principle component analysis) matlab code r... - Newsreader - MAT... http://www.mathworks.in/matlabcentral/newsreader/view_thread/3188442 of 2 4/16/2013 10:15 AM
Comments
Copyright © 2024 UPDOCS Inc.