-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopGeneralizeFigGen.m
364 lines (281 loc) · 11.7 KB
/
popGeneralizeFigGen.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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
% population generalization figure - showing that hetero pops generalize to
% other stim better than homo pops
%% compute PSD's for example populations and example stim stats
% this is a file which contains 2 example pops (44 and 155) and 4 stim
% stats for 200 stimuli each (slen = 512)
cd('C:\Users\Shreejoy\Desktop\shreejoy\neural_diversity\ST_machinelearn\reconKP\populationsims\diffStimStats\finSims\sim10');
load('reconsMerged');
freqSimStimInds = [1 2 4 6 10];
[freq, stimSpect, reconSpect, infoSpect] = computeFreqSpectra(stimParms, reconStructOut, popAssignInds);
%recon and info spect are organized s.t rows are diff stim, and columns are
%diff populations
%% plot example stim and recons for a hetero and homo pop
% load data
cd('C:\Users\Shreejoy\Desktop\shreejoy\neural_diversity\ST_machinelearn\reconKP\populationsims\diffStimStats\finSims\finData\');
load reconPlusAnal2
%% plot example recons
colorCodePlot(1,:) = [1 0 0];
colorCodePlot(2,:) = [0 1 0];
colorCode = colormap(jet(length(keepCells)));
%% plot some example recons between
currStimInd = 66;%20;
popInds = [44 155];
% popInds = [44 624];
for i = 1:size(popInds,2)
plotInds(i) = find(currStimInd == popAssignInds.stimInd & popInds(i) == popAssignInds.popInd);
end
a = figure(); subplot(3,1,1:2); plot(1:slen, outSignal(:,currStimInd), 'k', 'LineWidth' , 2) % axis([1 slen -3 3]);
testSpikesPlot = [];
hold on;
rasterColors = [];
for i = 1:2%length(currCellInds)
tempCurrCellInds = reconStructIn(plotInds(i)).popMakeup;
subplot(3,1,1:2); plot(1:slen, reconStructOut(plotInds(i)).optStim, 'Color', colorCodePlot(i,:), 'LineWidth' , 2)
testSpikesPlot = vectCat(testSpikesPlot, reconStructIn(plotInds(i)).testSpikes);
% rasterColors(end+1:end+nnz(tempCurrCellInds),:) = repmat(colorCodePlot(i,:), nnz(tempCurrCellInds),1);
rasterColors(end+1:end+nnz(tempCurrCellInds),:) = colorCode(tempCurrCellInds,:);
if i ~= 2
rasterColors(end+1,:) = [1,1,1]; %white
testSpikesPlot = vectCat(testSpikesPlot, 0);
end
end
axis([0 slen -3 3]);
% legend('real stim', 'same recon1', 'same recon2','diff recon');
ylabel('Stimulus (a.u.)'); set(gca,'XTickLabel', []); axis tight; box off;
subplot(3,1,3);createRaster3(testSpikesPlot',1, slen, rasterColors); %ylabel('Neuron ID');
xlabel('Time (ms)'); set(gca,'YTick', []);
%% find stim where diff between pop 1 and 2 is largest
cnt = 1;
for i = 1:stimParms.numStimStats
for j = 1:numSignalsPerStat
stimStatInds(cnt) = i;
cnt = cnt + 1;
end
end
currStimStat = 6;
stimInds = stimStatInds==currStimStat;
reconDiffVals = popValsAll(stimInds, popInds(1)) - popValsAll(stimInds, popInds(2));
[bestVal bestInds] = sort(reconDiffVals, 'descend');
%% set up global sturcture for figure
popInds = [44 155];
stimStatExamples = [1 2 6];
stimExampleInds = [7 16 45];
colorCode = colormap(jet(length(keepCells)));
%% plot the glm parms for a few pops
glmParmPan = panel();
glmParmPan.pack('v', [25 25 25 -1 ]);
for j = 1:length(popInds)
currGlmPan = glmParmPan(j);
currGlmPan.pack('h', [45 45 -1]);
kFilt = currGlmPan(1);
hFilt = currGlmPan(2);
bFilt = currGlmPan(3);
currCellInds = pop(popInds(j)).dat;
% figure;
% box off;
allCellInds = unique(nonzeros(currCellInds));
for i = 1:length(allCellInds)
kFilt.select(); hold on; plot(-49:0, cellModels(allCellInds(i)).k, 'Color', colorCode(allCellInds(i),:) , 'LineWidth' , 1);
axis([-50 0 -.2 1.1]); xTickPos = [-50 -25 0]; hold on;
set(gca, 'XTick', xTickPos);
hFilt.select(); plot(cellModels(1).iht,log10(exp(cellModels(allCellInds(i)).ihbas*cellModels(allCellInds(i)).ih)), 'Color', colorCode(allCellInds(i),:), 'LineWidth' , 1); hold on;
axis ([0 60 -1.6 2.2]);
yTickPos = [-1:2]; yTickLabels = [.1 1 10 100];
set(gca, 'YTick', yTickPos, 'YTickLabel', yTickLabels);
bFilt.select(); plot(1, log10(exp(cellModels(allCellInds(i)).dc)), '.', 'Color', colorCode(allCellInds(i),:)); hold on;
axis ([0 2 -1.6 2.2]);
set(gca, 'YTick', yTickPos, 'YTickLabel', [], 'XTick', []);
end
currGlmPan.margin = 5;
end
glmParmPan.margin = 5;
glmParmPan.fontsize = 6;
%plot all stim stats in frequency domain
stimFreqPan = glmParmPan(3);
stimFreqPan.pack('h', 2);
allFreqPan = stimFreqPan(1);
figure;
allFreqPan = panel();
plotStims = [1 2 6];
tapers=3; avg=1; fs = 1000;
pars = struct ('Fs', fs, ...
'tapers', [tapers 2*tapers-1], ...
'pad', 0, ...
'trialave', 1);
for k = 1:numStimStats
[S(:,k), f] = mtspectrumc(outSignal(:,1+(k-1)*numSignalsPerStat:k*numSignalsPerStat), pars);
end
allFreqPan.select();
plot(f,S(:,plotStims), 'LineWidth' , 1); ylabel('Power'); xlabel('Frequency (Hz)');
axis([0 100 0 .05]);
allFreqPan.fontsize = 6;
% subplot(1,5,1:2);box off;
% subplot(1,5,3:4); box off;
% subplot(1,5,5);box off;
%% plot stim and recons
allReconsPan = panel();
freqInds = 1:53;
allReconsPan.pack(length(stimStatExamples),1);
for k = 1:length(stimStatExamples)
currStimStat = stimStatExamples(k);
currStim = (currStimStat-1)*numSignalsPerStat + stimExampleInds(k);
stimExample = allReconsPan(k,1);
stimExample.pack('h', [1]);
stimReconPan = stimExample(1);
% freqPan = stimExample(2);
stimReconPan.pack('v', [2/3 -1]);
stimPan = stimReconPan(1);
rasterPan = stimReconPan(2);
currStimInd = currStim;%20;
% popInds = [44 624];
for i = 1:size(popInds,2)
plotInds(i) = find(currStimInd == popAssignInds.stimInd & popInds(i) == popAssignInds.popInd);
end
stimPan.select(); plot(1:slen, outSignal(:,currStimInd), 'k', 'LineWidth' , 1) % axis([1 slen -3 3]);
testSpikesPlot = [];
hold on;
rasterColors = [];
for i = 1:2%length(currCellInds)
tempCurrCellInds = reconStructIn(plotInds(i)).popMakeup;
plot(1:slen, reconStructOut(plotInds(i)).optStim, 'Color', colorCodePlot(i,:), 'LineWidth' , 1)
testSpikesPlot = vectCat(testSpikesPlot, reconStructIn(plotInds(i)).testSpikes);
% rasterColors(end+1:end+nnz(tempCurrCellInds),:) = repmat(colorCodePlot(i,:), nnz(tempCurrCellInds),1);
rasterColors(end+1:end+nnz(tempCurrCellInds),:) = colorCode(tempCurrCellInds,:);
if i ~= 2
rasterColors(end+2,:) = [1,1,1]; %white
testSpikesPlot = vectCat(testSpikesPlot, [0 0]);
end
end
axis([0 slen -3 3]);
% legend('real stim', 'same recon1', 'same recon2','diff recon');
ylabel('Stimulus (a.u.)'); set(gca,'XTickLabel', []); axis tight; box off;
rasterPan.select(); createRaster3(testSpikesPlot',1, slen, rasterColors); %ylabel('Neuron ID');
xlabel('Time (ms)'); set(gca,'YTick', []);
set(gca,'TickDir', 'out')
% plot freqPan;
% currFreqInd = find(stimStatExamples(k) == freqSimStimInds);
% freqPan.select();
% plot(freq(freqInds), stimSpect(currFreqInd).dat(freqInds), 'k', 'LineWidth' , 1); hold on;
% for i = 1:2%length(currCellInds)
% plot(freq(freqInds), reconSpect(currFreqInd,i).dat(freqInds), 'Color', colorCodePlot(i,:), 'LineWidth' , 1);
% end
% axis tight;
stimReconPan.de.margin = 2;
stimExample.margin = 10;
end
allReconsPan.margin = 10;
allReconsPan.fontsize = 6;
%% plot stimuli population comparison panel
stimComps = [1 2; 1 6];
homoInds = 1:numModels;
heteroInds = numModels+1:numPops;
for i = 1:size(popAvgVal,2)
for j = 1:numPops
popPositionsStim(j,i) = find(sortedPopsStim(:,i) == j);
end
end
figure;
compPan = panel();
compPan.pack(2, 2);
% stimCompExBothPan = compPan(1);
for i = 1:2
stimInd1 = stimComps(i,1);
stimInd2 = stimComps(i,2);
compPan(1, i).select();
% stimCompExPan(1,i).select();
% compute average pairwise correlation of pop position across stim stats
% stimCompExPan.select();
% subplot(2,2,i);
hold on;
plot([1 numPops], [1 numPops], 'Color', [.4 .4 .4]);
plot(popPositionsStim(heteroInds,stimInd1), popPositionsStim(heteroInds,stimInd2),'g.')
plot(popPositionsStim(homoInds,stimInd1), popPositionsStim(homoInds,stimInd2),'r.')
plot(popPositionsStim(popInds(2),stimInd1), popPositionsStim(popInds(2),stimInd2),'g*')
plot(popPositionsStim(popInds(1),stimInd1), popPositionsStim(popInds(1),stimInd2),'r*')
set(gca,'YDir','reverse','XDir','reverse');
xlabel(['stim ', num2str(stimInd1)]);
ylabel(['stim ', num2str(stimInd2)]);
axis([0 244 0 244]);
set(gca, 'XTick', [1 100 200])
set(gca, 'YTick', [1 100 200])
end
% plot pairwise correlation panel for homo and hetero
% stimCorrPan = compPan(3);
numStimStats = stimParms.numStimStats;
bestPops = sortedPopsStim;
removeStims = [7 9];
includeStims = setdiff(1:numStimStats, removeStims);
homoCorr = 1 - pdist(popPositionsStim(homoInds,includeStims)', 'correlation');
heteroCorr = 1 - pdist(popPositionsStim(heteroInds,includeStims)', 'correlation');
homoSpread = pdist(popPositionsStim(homoInds,includeStims)', 'correlation');
heteroSpread = pdist(popPositionsStim(heteroInds,includeStims)', 'correlation');
homoCorrSq = squareform(homoCorr);
heteroCorrSq = squareform(heteroCorr);
% (1/(length(heteroInds)-1))*sum( (popPositionsStim(heteroInds, 1) - mean(1:numPops)).*(popPositionsStim(heteroInds, 6) - mean(1:numPops)))...
% /(std(popPositionsStim(heteroInds, 1))*std(popPositionsStim(heteroInds, 6)));
% (1/(length(homoInds)-1))*sum( (popPositionsStim(homoInds, 1) - mean(1:numPops)).*(popPositionsStim(homoInds, 6) - mean(1:numPops)))...
% /(std(popPositionsStim(homoInds, 1))*std(popPositionsStim(homoInds, 6)))
% heteroPts = popPositionsStim(heteroInds, 1);
%
% dHet=abs(-popPositionsStim(heteroInds, 1)+popPositionsStim(heteroInds, 2))/sqrt(2);
% dHom=abs(-popPositionsStim(homoInds, 1)+popPositionsStim(heteroInds, 2))/sqrt(2);
%
% for i = 1:numel(heteroInds)
% currPt = [popPositionsStim(heteroInds(i), 1); popPositionsStim(heteroInds(i), 2)];
% d(i) = point_to_line(currPt, [0; 0], [1; 1]);
% end
%
% stimCorrPan.select();
compPan(2,2).select();
plot(homoSpread, heteroSpread, 'k.')
hold on;
plot([0 1], [0 1], 'Color', [.4 .4 .4])
xlabel('Homog- spread');
ylabel('Heterog- spread');
[pval, hyp] = signrank(heteroSpread, homoSpread);
compPan.de.margin = 10;
compPan.fontsize = 6;
%% plot average position for het and hom across stims
meanPosHom = mean(mean(popPositionsStim(homoInds,includeStims)));
stdErrPosHom = myStdErr(nonzeros(popPositionsStim(homoInds,includeStims)));
meanPosHet = mean(mean(popPositionsStim(heteroInds,includeStims)));
stdErrPosHet = myStdErr(nonzeros(popPositionsStim(heteroInds,includeStims)));
compPan(2,1).select();
hold on;
errorbar([meanPosHom meanPosHet], [stdErrPosHom stdErrPosHet], 'Color', 'k', 'LineStyle', 'none');
bar([meanPosHom meanPosHet], 'baseValue', numPops);
set(gca,'YDir','reverse')
ylabel('Mean population position');
currxTickLabel = {'Hom-', 'Het-'};
set(gca,'XTick', [1 2], 'XTickLabel', currxTickLabel)
axis([0 3 50 numPops]);
[pval, hyp] = signrank(mean(popPositionsStim(homoInds,includeStims)), mean(popPositionsStim(heteroInds,includeStims)));
%
% plot(ones(10,1), mean(popPositionsStim(homoInds,:)), 'r.'); hold on;
% plot(ones(10,1)+1, mean(popPositionsStim(heteroInds,:)), 'g.')
%
% plot([ones(10,1) ones(10,1)+1]', [mean(popPositionsStim(homoInds,:))', mean(popPositionsStim(heteroInds,:))']', 'k')
%% plot frequency panel
p = panel();
freqInds = 1:53;
p.pack(length(stimStatExamples),1);
for k = 1:length(stimStatExamples)
currFreqInd = find(stimStatExamples(k) == freqSimStimInds);
freqPan = p(k,1);
freqPan.select();
plot(freq(freqInds), stimSpect(currFreqInd).dat(freqInds), 'k'); hold on;
for i = 1:2%length(currCellInds)
plot(freq(freqInds), reconSpect(currFreqInd,i).dat(freqInds), 'Color', colorCodePlot(i,:));
end
axis tight;
end
%% make entire figure
close all
clf
set(gcf, 'units', 'centimeters');
set(gcf, 'Position', [0 0 18.3 12.7]);
popGenFig = panel();
popGenFig.pack('h', [35 40 25]);
glmParmPan = popGenFig(1);
allReconsPan = popGenFig(2);
compPan = popGenFig(3);