-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdimensionalAnalysis.m
More file actions
210 lines (161 loc) · 5.06 KB
/
dimensionalAnalysis.m
File metadata and controls
210 lines (161 loc) · 5.06 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
function dimensionalAnalysis()
if true
% h = combineFitHistories('FitHistory-*-AscFullHistD2thin.mat',true,true);
% h = combineFitHistories('FitHistory-*-jAscMultiDim.mat',true,true);
% load('/groups/wilson/FitHistory/jAscMultiDim-path.mat');
% load('/groups/wilson/FitHistory/jAscMultiDim-endpoints.mat');
% scoresByFly = h.scoresByFly;
% meanIX = h.meanIX;
% load('~/gateSpec/allMetrics.mat');
% decPI = allMetrics(:,2);
% decPI(find(isnan(decPI))) = 0;
% load('/groups/wilson/gatePop/gatePopResults-totalPop.mat');
% newMeanIX = meanIX;
% newMeanIX(:,1) = meanIX(:,3);
% newMeanIX(:,3) = meanIX(:,1);
% meanIX = newMeanIX;
load('/groups/wilson/gatePop/gatePopResults-totalPop150616.mat');
newMeanIX = meanIX;
newMeanIX(:,1) = meanIX(:,3);
newMeanIX(:,3) = meanIX(:,1);
meanIX = newMeanIX;
% load('/groups/wilson/gatePop/gatePopResults-totalPopStarts.mat');
% newMeanIXs = meanIX;
% newMeanIXs(:,1) = meanIX(:,3);
% newMeanIXs(:,3) = meanIX(:,1);
% scoresByFlyS = scoresByFly;
% PIs = PI;
% decPIs = decPI;
% load('/groups/wilson/gatePop/gatePopResults-totalPopEnds.mat');
% scoresByFlyE = scoresByFly;
% scoresByFly = cat(2,scoresByFlyS,scoresByFlyE);
% PI = PIs;
% decPI = decPIs;
% meanIX = newMeanIXs;
% gateLearn data needs to be stratified by fly
% load('~/gateLearn/GateScores.mat');
% [scoresByFly, meanIX] = stratifyByFly(gateScores, sampleIX);
% scoresByFly = h.scoresByFly;
% meanIX = h.meanIX;
plotTitle = 'Fit Metrics';
for mN = 1:size(scoresByFly,2)
metricLabels{mN} = ['G',num2str(mN,'%03d')];
end
scoresByFly = zscore(scoresByFly,0,1);
classIX = uniqueTypes(meanIX);
else
plotTitle = 'a priori Metrics';
load('~/gateSpec/allMetrics.mat');
scoresByFly = nanZscore(allMetrics);
ix = find(isnan(scoresByFly)); scoresByFly(ix) = 0;
meanIX = allMetricIX;
classIX = uniqueTypes(meanIX);
end
% Do the signal correlation
[sigCorr, noiseCorr] = signalCorrelation(scoresByFly, classIX);
% Resort by the signal auto-correlation
[B, IX] = sort(diag(sigCorr),'descend');
% IX = IX(1:nBest);
sigCorr = sigCorr(IX,IX);
noiseCorr = noiseCorr(IX,IX);
scoresByFly = scoresByFly(:,IX);
n = 1:100;
[n(:) IX(1:100)]
gateRawOrder = IX;
% Display labels
if false
disp(' ');
disp(' ');
for n = 1:length(IX)
ordLabels{n} = metricLabels{IX(n)};
disp(['#:',num2str(n),' ',ordLabels{n}]);
end
disp(' ');
disp(' ');
metricLabels = ordLabels;
end
ffsubplot(2,3,1);
image(sigCorr,'CDataMapping','scaled');
title('Sig. Corr.'); colorbar;
axis square;
ffsubplot(2,3,2);
image(noiseCorr,'CDataMapping','scaled');
title('Noise Corr.'); colorbar;
axis square;
ffsubplot(2,3,3);
[coeffs,scores,latent,mu,expVar] = signalPCA(scoresByFly,classIX,64);
plot(latent,'b.-'); hold on;
xlim([0 10]);
nPerms = 20;
nFlies = size(scoresByFly,1);
allLatents = zeros(nPerms,32);
if false
for permN = 1:nPerms
permN
% Shuffle scores
shuffledScores = permuteScores(scoresByFly, classIX);
[scoeffs,sscores,slatent,smu,sexpVar] = signalPCA(shuffledScores,classIX,64);
allLatents(permN,:) = slatent(1:32);
end
for PCn = 1:32
lIX = round(.05*nPerms);
uIX = round(.95*nPerms);
sortedL = sort(allLatents(:,PCn),'ascend');
lBound(PCn) = sortedL(lIX);
uBound(PCn) = sortedL(uIX);
end
% plot(mean(allLatents,1),'k');
% plot(lBound,'k--');
plot(uBound,'k--');
title(['First 3 PCs: ',num2str(sum(latent(1:3)))]);
xlim([.5 10.5]);
xlabel('PC #');
axis square;
cumsum(latent(1:5))
end
% FF = ffsubplot(2,3,3);
% FF.PDF('FullShuffle.pdf');
for eigN = 1:4
V = coeffs(:,eigN);
[B,IX] = sort(abs(V),'descend');
disp(['PC #',num2str(eigN)]);
disp('--------------------');
for loadN = 1:50
disp([num2str(V(IX(loadN)),'%+1.3f'),' - #',num2str(IX(loadN)),' - ',metricLabels{IX(loadN)},' ', num2str(gateRawOrder(IX(loadN)))]);
end
disp(' ');
end
transScoresByFly = scores;
[transSigCov, transNoiseCov] = signalCovariance(transScoresByFly, classIX);
ffsubplot(2,3,4);
image(transSigCov./expVar,'CDataMapping','scaled');
title('Signal cov. after sigPCA'); colorbar;
xlim([.5 10.5]);
ylim([.5 10.5]);
axis square;
ffsubplot(2,3,5);
image(transNoiseCov./expVar,'CDataMapping','scaled');
title('Noise Cov. after sigPCA'); colorbar;
axis square;
FF = ffsubplot(2,3,6);
image((transSigCov + transNoiseCov)./expVar,'CDataMapping','scaled');
title('Total cov. after sigPCA'); colorbar;
FF.setTitle(plotTitle);
nullDimension(transScoresByFly, meanIX,scoresByFly,coeffs,sigCorr, decPI, gateRawOrder);
return;
figure;
scatterByPower(transScoresByFly, meanIX,scoresByFly,coeffs,sigCorr, decPI);
figure;
plotRaster(transScoresByFly, meanIX, decPI);
function shuffledScores = permuteScores(scoresByFly, classIX)
nClasses = length(unique(classIX));
for dimN = 1:size(scoresByFly,2)
classMapping = randperm(nClasses);
for destClass = 1:nClasses
destIXs = find(classIX == destClass);
sourceClass = classMapping(destClass);
sourceIXs = find(classIX == sourceClass);
sourceIX = sourceIXs(randi(length(sourceIXs),length(destIXs),1));
shuffledScores(destIXs(:),dimN) = scoresByFly(sourceIX(:),dimN);
end
end