Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!news.glorb.com!postnews.google.com!q27g2000vbn.googlegroups.com!not-for-mail
From: Greg Heath <heath@alumni.brown.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Feature Extraction for EMG data using PCA
Date: Tue, 10 Mar 2009 09:29:00 -0700 (PDT)
Organization: http://groups.google.com
Lines: 68
Message-ID: <8633c0c9-5282-48d3-84d6-26c832fbe0cc@q27g2000vbn.googlegroups.com>
References: <goh104$17e$1@fred.mathworks.com> <6a1f9244-51d8-4e3b-9fb8-2aefcab53109@y33g2000prg.googlegroups.com> 
	<golmid$8sp$1@fred.mathworks.com>
NNTP-Posting-Host: 68.39.98.10
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1236702540 20058 127.0.0.1 (10 Mar 2009 16:29:00 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 10 Mar 2009 16:29:00 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: q27g2000vbn.googlegroups.com; posting-host=68.39.98.10; 
	posting-account=mUealwkAAACvQrLWvunjg50tRAnsNtJR
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; 
	Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; 
	.NET CLR 2.0.50727; .NET CLR 3.0.04506.30; Seekmo 10.0.341.0),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:523783


On Mar 4, 6:53 am, "anoop " <nomail...@rediffmail.com> wrote:
> "russell.f...@gmail.com" <russell.f...@gmail.com> wrote in message <6a1f9244-51d8-4e3b-9fb8-2aefcab53...@y33g2000prg.googlegroups.com>...
> > On Mar 2, 10:20=A0am, "anoop " <nomail...@rediffmail.com> wrote:
> > > I have a EMG data matrix of size 90(subjects) x 4800(variables). I want t=
> > o apply PCA to reduce the no. of variables, e.g ( i want matrix of size 90 =
> > x 1200 after PCA).
> > > I need a matlab program to do so. suggestions are welcome!!
>
> > You can write a program to do PCA using subroutines included in basic
> > Matlab without any extra toolboxes.
>
> > You need to find the eigenvectors and eigenvalues of the covariance
> > matrix of your data, from which you find the most significant
> > principal components, then you expand your data along the principal
> > directions.

I agree. I do not recommend picking a number like 1200 out
of mid air when you can use the diagonal eigenvalue matrix
to estimate a more practical value. Typical rules of thumb are

1. Exclude eigenvectors associated with eigenvalues that
are less than x% (e.g., 1%) of the maximum eigenvalue.
2. Keep the minimum number of eigenvectors that will
preserve x% of the trace of the covariance matrix.

Recall that

trace(cov(A)) = sum(diag(cov(A)))= sum(eig(A))

> well i wrote the program as given below:
> max_PCs=1200;
> covariance_matrix=cov(data);
> [eigvect,eigval]=eig(covariance_matrix);

Wasted effort calculating 3600 useless eigenvectors

> eigval=diag(eigval);
> [junk,rindices]=sort(-1*eigval);

help fliplr
help flipud

> eigen_values=eigval(rindices);

= junk?

> arranged_eigen_vectors=eigvect(:,rindices);
> eigen_values_extacted=eigen_values(1:max_PCs);
> principle_components=arranged_eigen_vectors(:,1:max_PCs);
> projected_data=xpca*principle_components;
>
> but it takes very long time to execute. could you please give me faster matlab code?? what should i use for training theneuralnetwork (projected data or principal components) ??

C = cov(data); L0 = eig(C);         % No eigenvectors
L = diag(L0); cumsumL = cumsum(L);

% Find r to preserve 95% (or your choice) of trace(C), i.e.,
% cumsumL(r-1) < 0.95*cumsumL(end) <= cumsumL(r-1)
% Then use EIGS (NOT EIG) to caclculate exactly r
% eigenvectors

Hope this helps.

Greg