-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperformpca.m
executable file
·62 lines (46 loc) · 1.66 KB
/
performpca.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function [] = performpca(matfile,storeredund,escape,calc_lagthreads)
fprintf('\n');
disp('PERFORMING PCA (performpca.m)');
% Performs PCA on TD.
m=load(['' matfile '']);
% Now compute TDz
disp('Executing computeTDz()');
[TDz,ColumnMeans,RowMeans]=computeTDz(m.TD);
if storeredund
save(matfile,'TDz','-append');
end
save(matfile,'ColumnMeans','-append');
save(matfile,'RowMeans','-append');
%PERFORM PCA AND SAVE---------------------------------%
disp('Performing PCA on TDz.');
% Use pcacov on covariance matrix, which then returns the percentage
% of variance explained (which function pca() does not).
% Number of columns corresponds to number of variables.
% Number of rows corresponds to number of observations.
[COMPONENTS,EIGENVALUES,explained]=pcacov(cov(TDz));
save(matfile,'COMPONENTS','-append');
save(matfile,'EIGENVALUES','-append');
save(matfile,'explained','-append');
%----------------------------------------------------%
if calc_lagthreads
%COMPUTE LAG THREAD TOPOGRAPHY-----------------------%
[rows, ~] = size(TDz);
%L contains lag thread topographies, ordered according to variance
%explained.
%TD(2,1)<0 if 1->2. This way, Column Means is the actual lag
%projection map. Thus we have to multiply by negative 1:
L=(-1)*(TDz*COMPONENTS)/sqrt(rows);
if isfield(m,'comment')
comment=strcat(m.comment,';','L=(-1)*(TDz*COMPONENTS)/sqrt(rows)');
else
comment='L=(-1)*(TDz*COMPONENTS)/sqrt(rows)';
end
save(matfile,'L','-append');
save(matfile,'comment','-append');
%%----------------------------------------------------%
end
disp('PCA Computation (performpca.m) done!');
if escape
quit
end
end