Last change
on this file since 142 was
94,
checked in by (none), 14 years ago
|
PPPP - ica serial implementation
|
File size:
875 bytes
|
Rev | Line | |
---|
[94] | 1 | %function [U,R,E] = pcaFn(B); |
---|
| 2 | % |
---|
| 3 | %Principal components the normal way. Data in columns of B. |
---|
| 4 | %U is a matrix containing the principal component eigenvectors in |
---|
| 5 | % its columns. |
---|
| 6 | %R is a matrix containing the principal component representations in its |
---|
| 7 | % rows. Each row is the representation for the corresponding column |
---|
| 8 | % of B. |
---|
| 9 | %E is the vector of eigenvaules corresponding to the eigenvectors in U. |
---|
| 10 | |
---|
| 11 | function [U,R,E] = pcaFn(B); |
---|
| 12 | |
---|
| 13 | %Read data into columns of B; |
---|
| 14 | %B = datamat'; |
---|
| 15 | [N,P] = size(B); |
---|
| 16 | |
---|
| 17 | %********subtract mean |
---|
| 18 | mb=mean(B'); |
---|
| 19 | B=B-(ones(P,1)*mb)'; |
---|
| 20 | |
---|
| 21 | %********Find eigenvectors vi of BB' (NxN) |
---|
| 22 | [V,D] = eig (1/(P-1)*(B*B')); |
---|
| 23 | |
---|
| 24 | %********Sort eigenvectors |
---|
| 25 | eigvalvec = max(D); |
---|
| 26 | [seigvals, index] = sort(eigvalvec); % sort goes low to high |
---|
| 27 | Vsort = V(:,[fliplr(index)]); |
---|
| 28 | |
---|
| 29 | U=Vsort; |
---|
| 30 | length = sqrt (sum (U.^2)); |
---|
| 31 | U = U ./ (ones(N,1) * length); |
---|
| 32 | R = B'*U; |
---|
| 33 | E = fliplr(seigvals); |
---|
| 34 | |
---|
Note: See
TracBrowser
for help on using the repository browser.