-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotExampleResponses.m
329 lines (275 loc) · 11.6 KB
/
plotExampleResponses.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
close all;
% Define parameters
stim_period = [0.1 0.3];
mem_period = [0.3 1];
%%
stim_ind = ((t >= stim_period(1)) & (t <= stim_period(2)));
mem_ind = ((t >= mem_period(1)) & (t <= mem_period(2)));
%% Plot one of the example responses
plot_run = 12;
figure;
subplot(1,2,1);
imagesc(t, [1:size(r_rec, 1)], squeeze(r_rec(:, 1, :, plot_run))); hold all;
shading interp; view([0 90]); axis tight; axis square;
v = axis;
plot3(stim_period(1)*[1 1], v(3:4), 90*[1 1], 'w-', 'LineWidth', 2);
plot3(stim_period(2)*[1 1], v(3:4), 90*[1 1], 'w-', 'LineWidth', 2);
xlabel('Time (s)'); ylabel('Neuron #');
set(gca, 'CLim', [0 80]);
colorbar('horiz');
title('Mnemonic Representation of a Stimulus');
subplot(1,2,2);
imagesc(t, [1:size(r_rnd, 1)], squeeze(r_rnd(:, :, plot_run))); hold all;
shading interp; view([0 90]); axis tight; axis square;
v = axis;
plot3(stim_period(1)*[1 1], v(3:4), 90*[1 1], 'w-', 'LineWidth', 2);
plot3(stim_period(2)*[1 1], v(3:4), 90*[1 1], 'w-', 'LineWidth', 2);
xlabel('Time (s)'); ylabel('Neuron #');
set(gca, 'CLim', [0 80]);
colorbar('horiz');
set(gcf, 'Position', [100 100 1200 600]);
saveas(gcf, 'ExampleMnemonicEncoding.fig');
saveas(gcf, 'ExampleMnemonicEncoding.svg');
saveas(gcf, 'ExampleMnemonicEncoding.eps', 'psc2');
%% Plot the responses of neurons across stimuli, single stimulus alone into sensory network #1
figure;
subplot(2,2,1);
temp_resp = squeeze(nanmean(r_rec(:, 1, stim_ind, 1:8), 3));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Stimulus Network, Sorted by Preferred Stimulus');
subplot(2,2,3);
temp_resp = squeeze(nanmean(r_rec(:, 2, stim_ind, 1:8), 3));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Stimulus Network #2, Sorted by Preferred Stimulus');
subplot(2,2,[2 4]);
temp_resp = squeeze(nanmean(r_rnd(:, stim_ind, 1:8), 2));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Random Network, Sorted by Preferred Stimulus');
%% Plot the responses of neurons across stimuli, single stimulus alone into sensory network #2
figure;
subplot(2,2,1);
temp_resp = squeeze(nanmean(r_rec(:, 1, stim_ind, 9:16), 3));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Stimulus Network, Sorted by Preferred Stimulus');
subplot(2,2,3);
temp_resp = squeeze(nanmean(r_rec(:, 2, stim_ind, 9:16), 3));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Stimulus Network #2, Sorted by Preferred Stimulus');
subplot(2,2,[2 4]);
temp_resp = squeeze(nanmean(r_rnd(:, stim_ind, 9:16), 2));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Random Network, Sorted by Preferred Stimulus');
%% Plot the responses of neurons across stimuli, two stimuli presentations
figure;
subplot(2,3,1);
temp_resp = squeeze(nanmean(r_rec(:, 1, stim_ind, 17:80), 3));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Stimulus Network #1, Sorted by Preferred 2-Item Stimulus');
set(gca, 'CLim', [0 80]);
subplot(2,3,4);
temp_resp = squeeze(nanmean(r_rec(:, 2, stim_ind, 17:80), 3));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Stimulus Network #2, Sorted by Preferred 2-Item Stimulus');
set(gca, 'CLim', [0 80]);
subplot(2,3,[2 5]);
temp_resp = squeeze(nanmean(r_rnd(:, stim_ind, 17:80), 2));
[~, max_ind] = max(nanmean(r_rnd(:, stim_ind, 17:80), 2), [], 3);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Random Network, Sorted by Preferred 2-Item Stimulus');
set(gca, 'CLim', [0 80]);
subplot(2,3,3);
temp_resp = squeeze(nanmean(r_rnd(:, stim_ind, 17:80), 2));
[~, max_ind] = max(nanmean(r_rnd(:, stim_ind, 1:8), 2), [], 3);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Random Network, Sorted by Preferred Stim #1 Stimulus');
set(gca, 'CLim', [0 80]);
subplot(2,3,6);
temp_resp = squeeze(nanmean(r_rnd(:, stim_ind, 17:80), 2));
[~, max_ind] = max(nanmean(r_rnd(:, stim_ind, 9:16), 2), [], 3);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Random Network, Sorted by Preferred Stim #2 Stimulus');
set(gca, 'CLim', [0 80]);
%% Plot the time course of stimuli to their 'preferred' stimulus
rec_plot_ind = [1:round(size(r_rec, 1)/5):size(r_rec, 1)];
rnd_plot_ind = [1:round(size(r_rnd, 1)/5):size(r_rnd, 1)];
figure;
subplot(1,2,1);
temp_resp = squeeze(nanmean(r_rec(:, 1, stim_ind, :), 3));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
for i = 1:length(rec_plot_ind),
plot(t, squeeze(r_rec(rec_plot_ind(i), 1, :, max_ind(rec_plot_ind(i))))); hold all;
end
ovr_sum_resp = zeros(length(t), 1);
for i = 1:size(r_rec, 1),
ovr_sum_resp = ovr_sum_resp + squeeze(r_rec(i, 1, :, max_ind(i)));
end
ovr_sum_resp = ovr_sum_resp./size(r_rec, 1);
plot(t, ovr_sum_resp, 'k-', 'LineWidth', 2);
title('Example (and Average) Sensory Responses to Preferred Stimulus');
subplot(1,2,2);
temp_resp = squeeze(nanmean(r_rnd(:, stim_ind, :), 2));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
for i = 1:length(rnd_plot_ind),
plot(t, squeeze(r_rnd(rnd_plot_ind(i), :, max_ind(rnd_plot_ind(i))))); hold all;
end
ovr_sum_resp = zeros(1, length(t));
for i = 1:size(r_rnd, 1),
ovr_sum_resp = ovr_sum_resp + squeeze(r_rnd(i, :, max_ind(i)));
end
ovr_sum_resp = ovr_sum_resp./size(r_rnd, 1);
plot(t, ovr_sum_resp, 'k-', 'LineWidth', 2);
title('Example (and Average) Random Responses to Preferred Stimulus');
%% Plot example neuron's selectivity for memory delay
figure;
subplot(1,2,1);
plot(squeeze(nanmean(r_rec(1:round(size(r_rec, 1)/8):end, 1, mem_ind, 1:8), 3))');
subplot(1,2,2);
plot(squeeze(nanmean(r_rnd(1:round(size(r_rnd, 1)/8):end, mem_ind, 1:8), 2))');
title('Example neuron responses to individual memories into Sensory Network #1');
%% Plot the responses of neurons across stimuli, single stimulus alone into sensory network #1
figure;
subplot(2,2,1);
temp_resp = squeeze(nanmean(r_rec(:, 1, mem_ind, 1:8), 3));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Stimulus Network, Sorted by Preferred Memory');
subplot(2,2,3);
temp_resp = squeeze(nanmean(r_rec(:, 2, mem_ind, 1:8), 3));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Stimulus Network #2, Sorted by Preferred Memory');
subplot(2,2,[2 4]);
temp_resp = squeeze(nanmean(r_rnd(:, mem_ind, 1:8), 2));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Random Network, Sorted by Preferred Memory');
%% Plot the responses of neurons across stimuli, single stimulus alone into sensory network #2
figure;
subplot(2,2,1);
temp_resp = squeeze(nanmean(r_rec(:, 1, mem_ind, 9:16), 3));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Stimulus Network, Sorted by Preferred Memory');
subplot(2,2,3);
temp_resp = squeeze(nanmean(r_rec(:, 2, mem_ind, 9:16), 3));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Stimulus Network #2, Sorted by Preferred Memory');
subplot(2,2,[2 4]);
temp_resp = squeeze(nanmean(r_rnd(:, mem_ind, 9:16), 2));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Random Network, Sorted by Preferred Memory');
%% Plot the responses of neurons across stimuli, two stimuli presentations
figure;
subplot(2,3,1);
temp_resp = squeeze(nanmean(r_rec(:, 1, mem_ind, 17:80), 3));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Stimulus Network #1, Sorted by Preferred 2-Item Memory');
set(gca, 'CLim', [0 80]); colorbar;
subplot(2,3,4);
temp_resp = squeeze(nanmean(r_rec(:, 2, mem_ind, 17:80), 3));
[~, max_ind] = max(temp_resp, [], 2);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Stimulus Network #2, Sorted by Preferred 2-Item Memory');
set(gca, 'CLim', [0 80]); colorbar;
subplot(2,3,[2 5]);
temp_resp = squeeze(nanmean(r_rnd(:, mem_ind, 17:80), 2));
[~, max_ind] = max(nanmean(r_rnd(:, mem_ind, 17:80), 2), [], 3);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Random Network, Sorted by Preferred 2-Item Memory');
set(gca, 'CLim', [0 40]); colorbar;
subplot(2,3,3);
temp_resp = squeeze(nanmean(r_rnd(:, mem_ind, 17:80), 2));
[~, max_ind] = max(nanmean(r_rnd(:, mem_ind, 1:8), 2), [], 3);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Random Network, Sorted by Preferred Stim #1 Memory');
set(gca, 'CLim', [0 40]); colorbar;
subplot(2,3,6);
temp_resp = squeeze(nanmean(r_rnd(:, mem_ind, 17:80), 2));
[~, max_ind] = max(nanmean(r_rnd(:, mem_ind, 9:16), 2), [], 3);
[~, sort_ind] = sort(max_ind);
imagesc(temp_resp(sort_ind, :));
title('Random Network, Sorted by Preferred Stim #2 Memory');
set(gca, 'CLim', [0 40]); colorbar;
%% Plot the responses of neurons comparing the response to two single stimuli and their combination
[i1,i2] = meshgrid([1:8], [1:8]);
rnd_stim = squeeze(nanmean(r_rnd(:, stim_ind, :), 2));
rnd_mem = squeeze(nanmean(r_rnd(:, mem_ind, :), 2));
for i = 1:size(rnd_stim, 1),
[b_stim(:, i), ~, stats_stim(i)] = glmfit(cat(2, i1(:), i2(:)), rnd_stim(i, 17:80)');
[b_mem(:, i), ~, stats_mem(i)] = glmfit(cat(2, i1(:), i2(:)), rnd_mem(i, 17:80)');
end
figure;
imagesc(rnd_stim(:, 17:80) - (rnd_stim(:, i1(:)) + rnd_stim(:, i2(:) + 8)));
resid = rnd_stim(:, 17:80) - (rnd_stim(:, i1(:)) + rnd_stim(:, i2(:) + 8));
resid = sum(abs(resid), 2);
num_rnd_perm = 1000;
rnd_resid = NaN*ones(size(resid, 1), num_rnd_perm);
rnd_rnd_stim = rnd_stim(:, 17:80);
for i = 1:num_rnd_perm,
%Randomly permute the associations
rnd_rnd_stim = rnd_rnd_stim(:, randperm(size(rnd_rnd_stim, 2)));
rnd_resid(:, i) = sum(abs(rnd_rnd_stim(:, :) - (rnd_stim(:, i1(:)) + rnd_stim(:, i2(:) + 8))), 2);
end
figure;
plot(resid, 'r-'); hold all;
plot(nanmean(rnd_resid, 2), 'k--');
plot(nanmean(rnd_resid, 2) + nanstd(rnd_resid, [], 2), 'k:');
plot(nanmean(rnd_resid, 2) - nanstd(rnd_resid, [], 2), 'k:');
hist_fig = figure;
[n,x] = hist((resid - nanmean(rnd_resid, 2))./nanstd(rnd_resid, [], 2), 100);
plot(x, n); hold all;
v = axis;
plot(nanmean((resid - nanmean(rnd_resid, 2))./nanstd(rnd_resid, [], 2))*[1 1], v(3:4), 'r-');
text(nanmean((resid - nanmean(rnd_resid, 2))./nanstd(rnd_resid, [], 2)), v(4), sprintf('%4.3f', nanmean((resid - nanmean(rnd_resid, 2))./nanstd(rnd_resid, [], 2))), 'HorizontalAlignment', 'left', 'VerticalAlignment', 'top');
figure;
imagesc(rnd_mem(:, 17:80) - (rnd_mem(:, i1(:)) + rnd_mem(:, i2(:) + 8)));
resid = rnd_mem(:, 17:80) - (rnd_mem(:, i1(:)) + rnd_mem(:, i2(:) + 8));
resid = sum(abs(resid), 2);
num_rnd_perm = 1000;
rnd_resid = NaN*ones(size(resid, 1), num_rnd_perm);
rnd_rnd_mem = rnd_mem(:, 17:80);
for i = 1:num_rnd_perm,
%Randomly permute the associations
rnd_rnd_mem = rnd_rnd_mem(:, randperm(size(rnd_rnd_mem, 2)));
rnd_resid(:, i) = sum(abs(rnd_rnd_mem(:, :) - (rnd_mem(:, i1(:)) + rnd_mem(:, i2(:) + 8))), 2);
end
figure(hist_fig);
[n,x] = hist((resid - nanmean(rnd_resid, 2))./nanstd(rnd_resid, [], 2), 100);
plot(x, n, '--');
v = axis;
plot(nanmean((resid - nanmean(rnd_resid, 2))./nanstd(rnd_resid, [], 2))*[1 1], v(3:4), 'r--');
text(nanmean((resid - nanmean(rnd_resid, 2))./nanstd(rnd_resid, [], 2)), v(4), sprintf('%4.3f', nanmean((resid - nanmean(rnd_resid, 2))./nanstd(rnd_resid, [], 2))), 'HorizontalAlignment', 'left', 'VerticalAlignment', 'top');