-
Notifications
You must be signed in to change notification settings - Fork 0
/
chooseFeaturePostMortem.m
341 lines (222 loc) · 7.49 KB
/
chooseFeaturePostMortem.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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
% First run the choose feature script
%
% Exhaustive test of all 4-tuples.
% r = RGCclass(0); r.lazyLoad();
% r.chooseFeatures();
% This saves a chooseFeature-results-XXX.mat file
clear all, close all
% !! Update to the latest run
% fName = 'chooseFeature-results.mat';
% fName = 'chooseFeature-results-longrun.mat';
%fName = 'chooseFeature-results-735777.65614.mat'; % 3-tuples, small
fName = 'chooseFeature-results-735780.57279.mat'; % 3-tuples, large
% fName = 'chooseFeature-results-735776.22962.mat'; % 4-tuples, big run
load(fName)
nFeat = numel(allFeatureNames);
% Start by looking at the distribution of scores
uCF = unique(correctFrac(:));
N = hist(correctFrac(:),uCF);
bar(uCF,N)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('Worse than 60% classification')
[iSet,iRep] = find(correctFrac < 0.6);
badFeatCount = zeros(nFeat,1);
for i = 1:numel(iSet)
for j = 1:numel(featureIdxList{iSet(i)})
idx = featureIdxList{iSet(i)}(j);
badFeatCount(idx) = badFeatCount(idx) + 1;
end
end
[~,badIdx] = sort(badFeatCount,'descend');
for i = 1:nFeat
idx = badIdx(i);
fprintf('%d. %d bad counts, %s\n', ...
i, badFeatCount(idx), allFeatureNames{idx})
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('Better than 80 % classification')
[iSet,iRep] = find(correctFrac > 0.8);
goodFeatCount = zeros(nFeat,1);
for i = 1:numel(iSet)
for j = 1:numel(featureIdxList{iSet(i)})
idx = featureIdxList{iSet(i)}(j);
goodFeatCount(idx) = goodFeatCount(idx) + 1;
end
end
[~,goodIdx] = sort(goodFeatCount,'descend');
for i = 1:nFeat
idx = goodIdx(i);
fprintf('%d. %d good counts, %s\n', ...
i, goodFeatCount(idx), allFeatureNames{idx})
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% We also want to see which ones are consistently good
sumCF = sum(correctFrac > 0.75,2);
maxIdx = find(sumCF >= max(sumCF)-1);
[~,orderIdx] = sort(correctFracMean(maxIdx),'descend');
for i = 1:numel(maxIdx)
mi = maxIdx(orderIdx(i));
fprintf('#good = %d (mean score %.3f) ', sumCF(mi),mean(correctFrac(mi,:)))
for j = 1:numel(featureList{mi})
fprintf('%s ', featureList{mi}{j})
end
fprintf('\n')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ok, lets also look at the individual RGC are there any that are
% much more difficult than others to classify
sCF = size(corrFlag);
fracCorr = sum(sum(corrFlag,2),3)/(sCF(2)*sCF(3));
hist(fracCorr,20)
xlabel('Fraction of times correctly classified')
ylabel('Count')
badThresh = 0.2;
badIdx = find(fracCorr < badThresh);
[~,sortBadIdx] = sort(fracCorr(badIdx),'ascend');
fprintf('\n\nCells with are tough to classify\n')
for i = 1:numel(badIdx)
idx = badIdx(sortBadIdx(i));
fprintf(' %d. %.2f %% correct, File: %s\n', ...
i, fracCorr(idx)*100,fileNames{idx})
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot the really tough cases in feature space to see why they are
% so difficult.
% Features:
%
% Soma area
% Mean terminal segment length --> replace with mean segment length (highly correlated, but more data)
% Density of branch points
% Total dendritic length
%
% 14 - soma area
% 8 - mean segment length
% 5 - density of branch points
% 16 - total dendritic length
featIdx = [14 8 5 16];
% Hard coded, sine we only defined 5 colours
nID = 5;
typeCol = [228,26,28 ;...
55,126,184;...
77,175,74;...
152,78,163;...
255,127,0] / 255;
figure
p = [];
pLeg = {};
for iID = 1:nID
idx = find(iID == RGCtypeID);
p(iID) = plot3(featureMat(idx,featIdx(1)), ...
featureMat(idx,featIdx(2)), ...
featureMat(idx,featIdx(3)), ...
'.','color', typeCol(iID,:), ...
'markersize', 15);
pLeg{iID} = RGCtypeName{idx(1)};
hold on
end
% Mark bad cells
for iID = 1:numel(badIdx)
% Colour it according to the class it is mostly classified as
cAID = classifiedAsID(badIdx(iID),:,:);
mostFreqID(iID) = mode(cAID(:));
plot3(featureMat(badIdx(iID),featIdx(1)), ...
featureMat(badIdx(iID),featIdx(2)), ...
featureMat(badIdx(iID),featIdx(3)), ...
'o','color', typeCol(mostFreqID(iID),:), ...
'markersize', 12);
text(featureMat(badIdx(iID),featIdx(1)), ...
featureMat(badIdx(iID),featIdx(2)), ...
featureMat(badIdx(iID),featIdx(3)), ...
fileNames{badIdx(iID)},'fontsize',3)
end
title(sprintf('Marking RGCs missclassified more than %.1f %% of cases', ...
(1-badThresh)*100))
legend(p,pLeg)
xlabel(allFeatureNames{featIdx(1)})
ylabel(allFeatureNames{featIdx(2)})
zlabel(allFeatureNames{featIdx(3)})
saveas(gcf,'FIGS/Tough-to-classify-feature-space.pdf','pdf')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Use PCA on the four features selected
figure
[pc,score,latent] = princomp(featureMat(:,featIdx));
p = [];
pLeg = {};
for iID = 1:nID
idx = find(iID == RGCtypeID);
p(iID) = plot3(score(idx,1), ...
score(idx,2), ...
score(idx,3), ...
'.','color', typeCol(iID,:), ...
'markersize', 15);
pLeg{iID} = RGCtypeName{idx(1)};
hold on
end
% Mark bad cells
for iID = 1:numel(badIdx)
% Colour it according to the class it is mostly classified as
cAID = classifiedAsID(badIdx(iID),:,:);
mostFreqID(iID) = mode(cAID(:));
plot3(score(badIdx(iID),1), ...
score(badIdx(iID),2), ...
score(badIdx(iID),3), ...
'o','color', typeCol(mostFreqID(iID),:), ...
'markersize', 12);
text(score(badIdx(iID),1), ...
score(badIdx(iID),2), ...
score(badIdx(iID),3), ...
fileNames{badIdx(iID)},'fontsize',3)
end
legend(p,pLeg)
xlabel('PCA #1')
ylabel('PCA #2')
zlabel('PCA #3')
title(sprintf('Marking RGCs missclassified more than %.1f %% of cases (PCA from 4 features)', ...
(1-badThresh)*100))
view(0,90)
saveas(gcf,'FIGS/Tough-to-classify-PCA-space.pdf','pdf')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Use PCA on the four features selected
figure
[pc,score,latent] = princomp(featureMat);
p = [];
pLeg = {};
for iID = 1:nID
idx = find(iID == RGCtypeID);
p(iID) = plot3(score(idx,1), ...
score(idx,2), ...
score(idx,3), ...
'.','color', typeCol(iID,:), ...
'markersize', 15);
pLeg{iID} = RGCtypeName{idx(1)};
hold on
end
% Mark bad cells
for iID = 1:numel(badIdx)
% Colour it according to the class it is mostly classified as
cAID = classifiedAsID(badIdx(iID),:,:);
mostFreqID(iID) = mode(cAID(:));
plot3(score(badIdx(iID),1), ...
score(badIdx(iID),2), ...
score(badIdx(iID),3), ...
'o','color', typeCol(mostFreqID(iID),:), ...
'markersize', 12);
text(score(badIdx(iID),1), ...
score(badIdx(iID),2), ...
score(badIdx(iID),3), ...
fileNames{badIdx(iID)},'fontsize',3)
end
legend(p,pLeg)
xlabel('PCA #1')
ylabel('PCA #2')
zlabel('PCA #3')
title(sprintf('Marking RGCs missclassified more than %.1f %% of cases (PCA from all features)', ...
(1-badThresh)*100))
view(0,90)
saveas(gcf,'FIGS/Tough-to-classify-full-PCA-space.pdf','pdf')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% addpath('sparsePCA')
%
% card = 4;
% [cards,vars,Z]= sparsePCA(featureMat,card)
%