source: proiecte/PPPP/ica/pcaFn.m @ 94

Last change on this file since 94 was 94, checked in by (none), 14 years ago

PPPP - ica serial implementation

File size: 875 bytes
Line 
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
11function [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
18mb=mean(B');
19B=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
25eigvalvec = max(D);
26[seigvals, index] = sort(eigvalvec); % sort goes low to high
27Vsort = V(:,[fliplr(index)]);
28
29U=Vsort;
30length = sqrt (sum (U.^2));
31U = U ./ (ones(N,1) * length);
32R = B'*U;
33E = fliplr(seigvals);
34
Note: See TracBrowser for help on using the repository browser.