-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_results.py
More file actions
560 lines (464 loc) · 27.6 KB
/
plot_results.py
File metadata and controls
560 lines (464 loc) · 27.6 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
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pickle
import scipy.stats
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
plt.rcParams["font.family"] = "arial"
def plot_all_figures():
fig_params = {
'data_dir' : 'C:/Users/nicol/Projects/RNN_STP_analysis/',
'dt' : 10,
'models_per_task' : 20,
'N' : 100, # bootstrap iterations
'accuracy_th' : 0.9} # minimum accuracy of model required for analysis
#plot_supp_figure(fig_params)
#plot_figure3(fig_params)
#plot_figure4(fig_params)
plot_figure5(fig_params)
def plot_supp_figure(fig_params):
num_tasks = 3
chance_level = 1/8
model_signficance = np.zeros((num_tasks))
f = plt.figure(figsize=(3,4.25))
for n in range(num_tasks):
t = range(-900,2000+n*500,fig_params['dt'])
delay_epoch = range((2300+n*500)//fig_params['dt'],(2400+n*500)//fig_params['dt'])
# load following results from each task
delay_accuracy = np.zeros((fig_params['models_per_task']), dtype=np.float32)
neuronal_decoding = np.zeros((fig_params['models_per_task'], fig_params['N'], len(t)), dtype=np.float32)
synaptic_decoding = np.zeros((fig_params['models_per_task'], fig_params['N'], len(t)), dtype=np.float32)
good_model_count = 0
count = 1
while good_model_count < fig_params['models_per_task']:
if n == 0:
task_name = 'DMS_' + str(count)
elif n == 1:
task_name = 'DMS_' + str(count) + '_1500'
elif n == 2:
task_name = 'DMS_' + str(count) + '_2000'
x = pickle.load(open(fig_params['data_dir'] + task_name + '.pkl', 'rb'))
count += 1
if np.mean(x['accuracy']) > fig_params['accuracy_th']:
delay_accuracy[good_model_count] = np.mean(x['neuronal_decoding'][0,:,delay_epoch])
neuronal_decoding[good_model_count,:,:] = x['neuronal_decoding'][0,:,:]
synaptic_decoding[good_model_count,:,:] = x['synaptic_decoding'][0,:,:]
good_model_count +=1
print('number of models ', ' ', n, ' ', good_model_count)
if good_model_count < fig_params['models_per_task']:
print('Too few accurately trained models')
model_signficance[n] = np.sum(np.mean(np.mean(neuronal_decoding[:,:,delay_epoch],axis=2) \
>chance_level,axis=1)>0.95)
ax = f.add_subplot(num_tasks, 1, n+1)
plt.hold(True)
for j in range(fig_params['models_per_task']):
ax.plot(t,np.mean(neuronal_decoding[j,:,:],axis=0),'g')
ax.plot(t,np.mean(synaptic_decoding[j,:,:],axis=0),'m')
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.set_yticks([0,0.2,0.4,0.6,0.8,1])
ax.set_xticks([0,500,1500-10+n*500])
ax.set_ylim([0,1.02])
ax.set_xlim([-500,1500-10+n*500])
ax.plot([-900,4000],[chance_level,chance_level],'k--')
ax.plot([0,0],[0,1],'k--')
ax.plot([500,500],[0,1],'k--')
ax.set_ylabel('Decoding accuracy')
ax.set_xlabel('Time relative to sample onset (ms)')
plt.tight_layout()
plt.savefig('FigS1.pdf', format='pdf')
plt.show()
print(model_signficance)
def plot_figure4(fig_params):
task = 'DMS+DMRS'
t = range(-900,2000,fig_params['dt'])
delay_epoch = range(2300//fig_params['dt'],2400//fig_params['dt'])
f = plt.figure(figsize=(6,4.25))
chance_level = 1/8
# for each task, we will measure model significance with respect to:
# dim 1 = 0, neuronal decoding during delay_accuracy
# dim 1 = 1, shuffled neuronal accuracy > chance
# dim 1 = 2, shuffled neuronal accuracy < accuracy
# dim 1 = 3, shuffled synaptic accuracy > chance
# dim 1 = 4, shuffled synaptic accuracy < accuracy
model_signficance = np.zeros((2, 5))
p_val_th = 0.05
sig_neuronal_delay = np.zeros((2, fig_params['models_per_task']))
sig_decrease_neuronal_shuffling = np.zeros((2, fig_params['models_per_task']))
sig_decrease_syn_shuffling = np.zeros((2, fig_params['models_per_task']))
sig_syn_shuffling = np.zeros((2, fig_params['models_per_task']))
delay_accuracy = np.zeros((2,fig_params['models_per_task']), dtype=np.float32)
neuronal_decoding = np.zeros((2,fig_params['models_per_task'], fig_params['N'], len(t)), dtype=np.float32)
synaptic_decoding = np.zeros((2,fig_params['models_per_task'], fig_params['N'], len(t)), dtype=np.float32)
accuracy = np.zeros((2,fig_params['models_per_task'], fig_params['N']), dtype=np.float32)
accuracy_neural_shuffled = np.zeros((2,fig_params['models_per_task'], fig_params['N']), dtype=np.float32)
accuracy_syn_shuffled = np.zeros((2,fig_params['models_per_task'], fig_params['N']), dtype=np.float32)
corr_decoding_neuronal_shuf = np.zeros((2,2))
corr_decoding_syn_shuf = np.zeros((2,2))
corr_neuronal_shuf_syn_shuf = np.zeros((2,2))
good_model_count = 0
count = 0
while good_model_count < fig_params['models_per_task']:
x = pickle.load(open(fig_params['data_dir'] + task + '_' + str(count+1) + '.pkl', 'rb'))
count += 1
if np.mean(x['accuracy'][0,:]) > fig_params['accuracy_th'] and np.mean(x['accuracy'][1,:]) > fig_params['accuracy_th']:
for j in range(2):
delay_accuracy[j, good_model_count] = np.mean(x['neuronal_decoding'][j,:,delay_epoch])
neuronal_decoding[j, good_model_count,:,:] = x['neuronal_decoding'][j,:,:]
synaptic_decoding[j, good_model_count,:,:] = x['synaptic_decoding'][j,:,:]
accuracy[j, good_model_count,:] = x['accuracy'][j,:]
accuracy_neural_shuffled[j, good_model_count,:] = x['accuracy_neural_shuffled'][j, :]
accuracy_syn_shuffled[j, good_model_count,:] = x['accuracy_syn_shuffled'][j, :]
good_model_count +=1
if good_model_count < fig_params['models_per_task']:
print('Too few accurately trained models ', good_model_count)
for j in range(2):
model_signficance[j, 0] = np.sum(np.mean(np.mean(neuronal_decoding[j,:,:,delay_epoch],axis=2) \
>chance_level,axis=0)>1-p_val_th)
model_signficance[j, 1] = np.sum(np.mean(accuracy_neural_shuffled[j,:,:]>0.5,axis=1)>1-p_val_th)
model_signficance[j, 2] = np.sum(np.mean(accuracy[j,:,:] - accuracy_neural_shuffled[j,:,:]>0.5,axis=1)>1-p_val_th)
model_signficance[j, 3] = np.sum(np.mean(accuracy_syn_shuffled[j,:,:]>0.5,axis=1)>1-p_val_th)
model_signficance[j, 4] = np.sum(np.mean(accuracy[j,:,:] - accuracy_syn_shuffled[j,:,:]>0.5,axis=1)>1-p_val_th)
sig_neuronal_delay[j,:] =np.mean(np.mean(neuronal_decoding[j,:,:,delay_epoch],axis=2)>chance_level,axis=0)>1-p_val_th
sig_decrease_neuronal_shuffling[j,:] = np.mean(accuracy[j,:,:]-accuracy_neural_shuffled[j,:,:]>0,axis=1)>1-p_val_th
sig_decrease_syn_shuffling[j,:] = np.mean(accuracy[j,:,:]-accuracy_syn_shuffled[j,:,:]>0,axis=1)>1-p_val_th
sig_syn_shuffling[j,:] = np.mean(accuracy_syn_shuffled[j,:,:]>0.5,axis=1)>1-p_val_th
corr_decoding_neuronal_shuf[j,:] = scipy.stats.pearsonr(np.mean(np.mean(neuronal_decoding[j,:,:,delay_epoch],axis=2),axis=0), \
np.mean(accuracy_neural_shuffled[j,:,:],axis=1))
corr_decoding_syn_shuf[j,:] = scipy.stats.pearsonr(np.mean(np.mean(neuronal_decoding[j,:,:,delay_epoch],axis=2),axis=0), \
np.mean(accuracy_syn_shuffled[j,:,:],axis=1))
corr_neuronal_shuf_syn_shuf[j,:] = scipy.stats.pearsonr(np.mean(accuracy_neural_shuffled[j,:,:],axis=1), \
np.mean(accuracy_syn_shuffled[j,:,:],axis=1))
ax = f.add_subplot(2, 2, 2*j+1)
plt.hold(True)
for n in range(fig_params['models_per_task']):
ax.plot(t,np.mean(neuronal_decoding[j,n,:,:],axis=0),'g')
ax.plot(t,np.mean(synaptic_decoding[j,n,:,:],axis=0),'m')
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.set_yticks([0,0.2,0.4,0.6,0.8,1])
ax.set_xticks([0,500,1000, 1250, 1500-10])
ax.set_ylim([0,1.02])
ax.set_xlim([-500,1500-10])
ax.plot([-900,2000],[chance_level,chance_level],'k--')
ax.plot([0,0],[0,1],'k--')
ax.plot([500,500],[0,1],'k--')
ax.plot([1000,1000],[0,1],'k--')
ax.plot([1250,1250],[0,1],'k--')
ax.set_ylabel('Decoding accuracy')
ax.set_xlabel('Time relative to sample onset (ms)')
ax = f.add_subplot(2, 2, 2*j+2)
plt.hold(True)
ax.plot(delay_accuracy[j,:], np.mean(accuracy[j,:,:],axis=1),'b.')
ax.plot(delay_accuracy[j,:], np.mean(accuracy_syn_shuffled[j,:,:],axis=1),'c.')
ax.plot(delay_accuracy[j,:], np.mean(accuracy_neural_shuffled[j,:,:],axis=1),'r.')
ax.plot([chance_level,chance_level],[0,1],'k--')
ax.set_aspect(1/0.62)
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.set_yticks([0,0.5,0.6,0.7,0.8,0.9,1])
ax.set_xticks([0,0.2,0.4,0.6,0.8,1])
ax.set_ylim([0.4,1.02])
ax.set_ylabel('Task accuracy')
ax.set_xlabel('Delay neuronal decoding')
plt.tight_layout()
plt.savefig('Fig4.pdf', format='pdf')
plt.show()
print('Number of models with delay neuronal decoding accuracy signficantly greater than chance')
print(model_signficance)
print('Correlations...')
print(corr_decoding_neuronal_shuf)
print(corr_decoding_syn_shuf)
print(corr_neuronal_shuf_syn_shuf)
print('Number of models for which neuronal decoding is at chance')
print(np.sum(1-sig_neuronal_delay,axis=1))
print('Number of models for which shuffling neuronal activity has no effect')
print(np.sum(1-sig_decrease_neuronal_shuffling,axis=1))
print('Number of models for which shuffling STP causes accuracy to fall to chance')
print(np.sum(1-sig_syn_shuffling,axis=1))
print('Number of models for which 3 above conditions are satisfied')
print(np.sum((1-sig_neuronal_delay)*(1-sig_decrease_neuronal_shuffling)*(1-sig_syn_shuffling),axis=1))
print('Number of models for which shuffling neuronal and synaptic activity decreases accuracy')
print(np.sum((sig_decrease_neuronal_shuffling)*(sig_decrease_syn_shuffling),axis=1))
print('Mean accuracy after neuronal shuffling...')
print(np.mean(np.reshape(accuracy_neural_shuffled,(2,-1)),axis=1))
print('Mean accuracy after synaptic shuffling...')
print(np.mean(np.reshape(accuracy_syn_shuffled,(2,-1)),axis=1))
def plot_figure3(fig_params):
tasks = ['DMS', 'DMRS180','DMRS45','DMRS90','DMC']
num_tasks = len(tasks)
t = range(-900,2000,fig_params['dt'])
delay_epoch = range(2300//fig_params['dt'],2400//fig_params['dt'])
f = plt.figure(figsize=(6,8.5))
chance_level = 1/8
# for each task, we will measure model significance with respect to:
# dim 1 = 0, neuronal decoding during delay_accuracy
# dim 1 = 1, shuffled neuronal accuracy > chance
# dim 1 = 2, shuffled neuronal accuracy < accuracy
# dim 1 = 3, shuffled synaptic accuracy > chance
# dim 1 = 4, shuffled synaptic accuracy < accuracy
model_signficance = np.zeros((num_tasks, 5))
sig_neuronal_delay = np.zeros((num_tasks, fig_params['models_per_task']))
sig_decrease_neuronal_shuffling = np.zeros((num_tasks, fig_params['models_per_task']))
sig_decrease_syn_shuffling = np.zeros((num_tasks, fig_params['models_per_task']))
sig_syn_shuffling = np.zeros((num_tasks, fig_params['models_per_task']))
# correlation between neuronal decoding during the delay, accuracy after sig_syn_shuffling
# neuronal activity, and accuracy after shuffling synaptic activity
corr_decoding_neuronal_shuf = np.zeros((num_tasks,2))
corr_decoding_syn_shuf = np.zeros((num_tasks,2))
corr_neuronal_shuf_syn_shuf = np.zeros((num_tasks,2))
decoding_p_val = np.zeros((num_tasks))
p_val_th = 0.01
# will use DMS decoding results for comparison
neuronal_decoding_DMS = np.zeros((fig_params['models_per_task'], fig_params['N'], len(t)), dtype=np.float32)
for n in range(num_tasks):
if tasks[n] == 'DMC':
chance_level = 1/2
else:
chance_level = 1/8
# load following results from each task
delay_accuracy = np.zeros((fig_params['models_per_task']), dtype=np.float32)
neuronal_decoding = np.zeros((fig_params['models_per_task'], fig_params['N'], len(t)), dtype=np.float32)
synaptic_decoding = np.zeros((fig_params['models_per_task'], fig_params['N'], len(t)), dtype=np.float32)
accuracy = np.zeros((fig_params['models_per_task'], fig_params['N']), dtype=np.float32)
accuracy_neural_shuffled = np.zeros((fig_params['models_per_task'], fig_params['N']), dtype=np.float32)
accuracy_syn_shuffled = np.zeros((fig_params['models_per_task'], fig_params['N']), dtype=np.float32)
good_model_count = 0
count = 0
while good_model_count < fig_params['models_per_task']:
x = pickle.load(open(fig_params['data_dir'] + tasks[n] + '_' + str(count+1) + '.pkl', 'rb'))
count += 1
if np.mean(x['accuracy']) > fig_params['accuracy_th']:
delay_accuracy[good_model_count] = np.mean(x['neuronal_decoding'][0,:,delay_epoch])
neuronal_decoding[good_model_count,:,:] = x['neuronal_decoding'][0,:,:]
if tasks[n] == 'DMS':
neuronal_decoding_DMS[good_model_count,:,:] = x['neuronal_decoding'][0,:,:]
synaptic_decoding[good_model_count,:,:] = x['synaptic_decoding'][0,:,:]
accuracy[good_model_count,:] = x['accuracy']
accuracy_neural_shuffled[good_model_count,:] = x['accuracy_neural_shuffled']
accuracy_syn_shuffled[good_model_count,:] = x['accuracy_syn_shuffled']
good_model_count +=1
if good_model_count < fig_params['models_per_task']:
print('Too few accurately trained models')
model_signficance[n, 0] = np.sum(np.mean(np.mean(neuronal_decoding[:,:,delay_epoch],axis=2) \
>chance_level,axis=1)>1-p_val_th)
model_signficance[n, 1] = np.sum(np.mean(accuracy_neural_shuffled>0.5,axis=1)>1-p_val_th)
model_signficance[n, 2] = np.sum(np.mean(accuracy-accuracy_neural_shuffled>0,axis=1)>1-p_val_th)
model_signficance[n, 3] = np.sum(np.mean(accuracy_syn_shuffled>0.5,axis=1)>1-p_val_th)
model_signficance[n, 4] = np.sum(np.mean(accuracy-accuracy_syn_shuffled>0,axis=1)>1-p_val_th)
sig_neuronal_delay[n,:] =np.mean(np.mean(neuronal_decoding[:,:,delay_epoch],axis=2)>chance_level,axis=1)>1-p_val_th
sig_decrease_neuronal_shuffling[n,:] = np.mean(accuracy-accuracy_neural_shuffled>0,axis=1)>1-p_val_th
sig_decrease_syn_shuffling[n,:] = np.mean(accuracy-accuracy_syn_shuffled>0,axis=1)>1-p_val_th
sig_syn_shuffling[n,:] = np.mean(accuracy_syn_shuffled>0.5,axis=1)>1-p_val_th
N = 100
a = np.reshape(np.tile(accuracy,(1,1,N)),(20,N**2))
b = np.tile(accuracy_neural_shuffled,(1,1,N))
b = np.reshape(np.transpose(b,(0,2,1)),(20,N**2))
#print(tasks[n], np.mean(a-b>0,axis=1))
ind = np.where(np.mean(accuracy_neural_shuffled,axis=1)<0.9)[0]
print(tasks[n], ind)
print(tasks[n], np.mean(np.mean(accuracy_neural_shuffled[ind,:],axis=1)))
print(tasks[n], np.mean(np.mean(accuracy_syn_shuffled[ind,:],axis=1)))
corr_decoding_neuronal_shuf[n,:] = scipy.stats.pearsonr(np.mean(np.mean(neuronal_decoding[:,:,delay_epoch],axis=2),axis=1), \
np.mean(accuracy_neural_shuffled,axis=1))
corr_decoding_syn_shuf[n,:] = scipy.stats.pearsonr(np.mean(np.mean(neuronal_decoding[:,:,delay_epoch],axis=2),axis=1), \
np.mean(accuracy_syn_shuffled,axis=1))
corr_neuronal_shuf_syn_shuf[n,:] = scipy.stats.pearsonr(np.mean(accuracy_neural_shuffled,axis=1), \
np.mean(accuracy_syn_shuffled,axis=1))
decoding_p_val[n] = scipy.stats.ttest_ind(np.mean(np.mean(neuronal_decoding_DMS[:,:,delay_epoch],axis=2),axis=1), \
np.mean(np.mean(neuronal_decoding[:,:,delay_epoch],axis=2),axis=1))[1]
ax = f.add_subplot(num_tasks, 2, 2*n+1)
plt.hold(True)
for j in range(fig_params['models_per_task']):
ax.plot(t,np.mean(neuronal_decoding[j,:,:],axis=0),'g')
ax.plot(t,np.mean(synaptic_decoding[j,:,:],axis=0),'m')
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.set_yticks([0,0.2,0.4,0.6,0.8,1])
ax.set_xticks([0,500,1500-10])
ax.set_ylim([0,1.02])
ax.set_xlim([-500,1500-10])
ax.plot([-900,2000],[chance_level,chance_level],'k--')
ax.plot([0,0],[0,1],'k--')
ax.plot([500,500],[0,1],'k--')
ax.set_ylabel('Decoding accuracy')
ax.set_xlabel('Time relative to sample onset (ms)')
ax = f.add_subplot(num_tasks, 2, 2*n+2)
plt.hold(True)
ax.plot(delay_accuracy, np.mean(accuracy,axis=1),'b.')
ax.plot(delay_accuracy, np.mean(accuracy_neural_shuffled,axis=1),'r.')
ax.plot(delay_accuracy, np.mean(accuracy_syn_shuffled,axis=1),'c.')
ax.plot([chance_level,chance_level],[0,1],'k--')
ax.set_aspect(1/0.62)
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.set_yticks([0,0.5,0.6,0.7,0.8,0.9,1])
ax.set_xticks([0,0.2,0.4,0.6,0.8,1])
ax.set_ylim([0.4,1.02])
ax.set_ylabel('Task accuracy')
ax.set_xlabel('Delay neuronal decoding')
plt.tight_layout()
plt.savefig('Fig3.pdf', format='pdf')
plt.show()
print('Number of models with delay neuronal decoding accuracy signficantly greater than chance')
print(model_signficance)
print('Number of models for which neuronal decoding is at chance')
print(np.sum(1-sig_neuronal_delay,axis=1))
print('Number of models for which shuffling neuronal activity has no effect')
print(np.sum(1-sig_decrease_neuronal_shuffling,axis=1))
print('Number of models for which shuffling STP causes accuracy to fall to chance')
print(np.sum(1-sig_syn_shuffling,axis=1))
print('Number of models for which 3 above conditions are satisfied')
print(np.sum((1-sig_neuronal_delay)*(1-sig_decrease_neuronal_shuffling)*(1-sig_syn_shuffling),axis=1))
print('Number of models for which shuffling neuronal and synaptic activity decreases accuracy')
print(np.sum((sig_decrease_neuronal_shuffling)*(sig_decrease_syn_shuffling),axis=1))
print('Correlations...')
print(corr_decoding_neuronal_shuf)
print(corr_decoding_syn_shuf)
print(corr_neuronal_shuf_syn_shuf)
print('T-test neuroanl decoding p-val compared to DMS')
print(decoding_p_val)
def plot_figure5(fig_params):
tasks = ['ABCA', 'ABBA']
num_tasks = len(tasks)
t = range(-900,4000,fig_params['dt'])
delay_epoch = range(4300//fig_params['dt'],4400//fig_params['dt'])
f = plt.figure(figsize=(6,4))
chance_level = 1/8
# for each task, we will measure model significance with respect to:
# dim 1 = 0, neuronal decoding during delay_accuracy
# dim 1 = 1, shuffled neuronal accuracy > chance
# dim 1 = 2, shuffled neuronal accuracy < accuracy
# dim 1 = 3, shuffled synaptic accuracy > chance
# dim 1 = 4, shuffled synaptic accuracy < accuracy
model_signficance = np.zeros((num_tasks, 5))
sig_neuronal_delay = np.zeros((num_tasks, fig_params['models_per_task']))
sig_decrease_neuronal_shuffling = np.zeros((num_tasks, fig_params['models_per_task']))
sig_decrease_syn_shuffling = np.zeros((num_tasks, fig_params['models_per_task']))
sig_syn_shuffling = np.zeros((num_tasks, fig_params['models_per_task']))
# correlation between neuronal decoding during the delay, accuracy after sig_syn_shuffling
# neuronal activity, and accuracy after shuffling synaptic activity
corr_decoding_neuronal_shuf = np.zeros((num_tasks,2))
corr_decoding_syn_shuf = np.zeros((num_tasks,2))
corr_neuronal_shuf_syn_shuf = np.zeros((num_tasks,2))
decoding_p_val = np.zeros((num_tasks))
p_val_th = 0.01
chance_level = 1/8
for n in range(num_tasks):
# load following results from each task
delay_accuracy = np.zeros((fig_params['models_per_task']), dtype=np.float32)
neuronal_decoding = np.zeros((fig_params['models_per_task'], fig_params['N'], len(t)), dtype=np.float32)
synaptic_decoding = np.zeros((fig_params['models_per_task'], fig_params['N'], len(t)), dtype=np.float32)
accuracy = np.zeros((fig_params['models_per_task'], fig_params['N']), dtype=np.float32)
accuracy_neural_shuffled = np.zeros((fig_params['models_per_task'], fig_params['N']), dtype=np.float32)
accuracy_syn_shuffled = np.zeros((fig_params['models_per_task'], fig_params['N']), dtype=np.float32)
good_model_count = 0
count = 0
while good_model_count < fig_params['models_per_task'] and count < 49:
count += 1
try:
x = pickle.load(open(fig_params['data_dir'] + tasks[n] + '_' + str(count) + '_.pkl', 'rb'))
except:
continue
if np.mean(x['accuracy']) > fig_params['accuracy_th']:
#if 1 > fig_params['accuracy_th']:
delay_accuracy[good_model_count] = np.mean(x['neuronal_decoding'][0,:,delay_epoch])
neuronal_decoding[good_model_count,:,:] = x['neuronal_decoding'][0,:,:]
if tasks[n] == 'DMS':
neuronal_decoding_DMS[good_model_count,:,:] = x['neuronal_decoding'][0,:,:]
synaptic_decoding[good_model_count,:,:] = x['synaptic_decoding'][0,:,:]
accuracy[good_model_count,:] = x['accuracy']
accuracy_neural_shuffled[good_model_count,:] = x['accuracy_neural_shuffled']
accuracy_syn_shuffled[good_model_count,:] = x['accuracy_syn_shuffled']
good_model_count +=1
if good_model_count < fig_params['models_per_task']:
print('Too few accurately trained models, good models = ', good_model_count)
model_signficance[n, 0] = np.sum(np.mean(np.mean(neuronal_decoding[:,:,delay_epoch],axis=2) \
>chance_level,axis=1)>1-p_val_th)
model_signficance[n, 1] = np.sum(np.mean(accuracy_neural_shuffled>0.5,axis=1)>1-p_val_th)
model_signficance[n, 2] = np.sum(np.mean(accuracy-accuracy_neural_shuffled>0,axis=1)>1-p_val_th)
model_signficance[n, 3] = np.sum(np.mean(accuracy_syn_shuffled>0.5,axis=1)>1-p_val_th)
model_signficance[n, 4] = np.sum(np.mean(accuracy-accuracy_syn_shuffled>0,axis=1)>1-p_val_th)
sig_neuronal_delay[n,:] =np.mean(np.mean(neuronal_decoding[:,:,delay_epoch],axis=2)>chance_level,axis=1)>1-p_val_th
sig_decrease_neuronal_shuffling[n,:] = np.mean(accuracy-accuracy_neural_shuffled>0,axis=1)>1-p_val_th
sig_decrease_syn_shuffling[n,:] = np.mean(accuracy-accuracy_syn_shuffled>0,axis=1)>1-p_val_th
sig_syn_shuffling[n,:] = np.mean(accuracy_syn_shuffled>0.5,axis=1)>1-p_val_th
N = 100
a = np.reshape(np.tile(accuracy,(1,1,N)),(20,N**2))
b = np.tile(accuracy_neural_shuffled,(1,1,N))
b = np.reshape(np.transpose(b,(0,2,1)),(20,N**2))
#print(tasks[n], np.mean(a-b>0,axis=1))
ind = np.where(np.mean(accuracy_neural_shuffled,axis=1)<0.9)[0]
print(tasks[n], ind)
print(tasks[n], np.mean(np.mean(accuracy_neural_shuffled[ind,:],axis=1)))
print(tasks[n], np.mean(np.mean(accuracy_syn_shuffled[ind,:],axis=1)))
corr_decoding_neuronal_shuf[n,:] = scipy.stats.pearsonr(np.mean(np.mean(neuronal_decoding[:,:,delay_epoch],axis=2),axis=1), \
np.mean(accuracy_neural_shuffled,axis=1))
corr_decoding_syn_shuf[n,:] = scipy.stats.pearsonr(np.mean(np.mean(neuronal_decoding[:,:,delay_epoch],axis=2),axis=1), \
np.mean(accuracy_syn_shuffled,axis=1))
corr_neuronal_shuf_syn_shuf[n,:] = scipy.stats.pearsonr(np.mean(accuracy_neural_shuffled,axis=1), \
np.mean(accuracy_syn_shuffled,axis=1))
ax = f.add_subplot(num_tasks, 2, 2*n+1)
plt.hold(True)
for j in range(fig_params['models_per_task']):
ax.plot(t,np.mean(neuronal_decoding[j,:,:],axis=0),'g')
ax.plot(t,np.mean(synaptic_decoding[j,:,:],axis=0),'m')
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.set_yticks([0,0.2,0.4,0.6,0.8,1])
ax.set_xticks([0,500,1500,2500,3500])
ax.set_ylim([0,1.02])
ax.set_xlim([-500,4000-10])
ax.plot([-900,4000],[chance_level,chance_level],'k--')
ax.plot([0,0],[0,1],'k--')
ax.plot([500,500],[0,1],'k--')
ax.set_ylabel('Decoding accuracy')
ax.set_xlabel('Time relative to sample onset (ms)')
ax = f.add_subplot(num_tasks, 2, 2*n+2)
plt.hold(True)
ax.plot(delay_accuracy, np.mean(accuracy,axis=1),'b.')
ax.plot(delay_accuracy, np.mean(accuracy_neural_shuffled,axis=1),'r.')
ax.plot(delay_accuracy, np.mean(accuracy_syn_shuffled,axis=1),'c.')
ax.plot([chance_level,chance_level],[0,1],'k--')
ax.set_aspect(1/0.62)
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.set_yticks([0,0.5,0.6,0.7,0.8,0.9,1])
ax.set_xticks([0,0.2,0.4,0.6,0.8,1])
ax.set_ylim([0.4,1.02])
ax.set_ylabel('Task accuracy')
ax.set_xlabel('Delay neuronal decoding')
plt.tight_layout()
plt.savefig('Fig5.pdf', format='pdf')
plt.show()
print('Number of models with delay neuronal decoding accuracy signficantly greater than chance')
print(model_signficance)
print('Number of models for which neuronal decoding is at chance')
print(np.sum(1-sig_neuronal_delay,axis=1))
print('Number of models for which shuffling neuronal activity has no effect')
print(np.sum(1-sig_decrease_neuronal_shuffling,axis=1))
print('Number of models for which shuffling STP causes accuracy to fall to chance')
print(np.sum(1-sig_syn_shuffling,axis=1))
print('Number of models for which 3 above conditions are satisfied')
print(np.sum((1-sig_neuronal_delay)*(1-sig_decrease_neuronal_shuffling)*(1-sig_syn_shuffling),axis=1))
print('Number of models for which shuffling neuronal and synaptic activity decreases accuracy')
print(np.sum((sig_decrease_neuronal_shuffling)*(sig_decrease_syn_shuffling),axis=1))
print('Correlations...')
print(corr_decoding_neuronal_shuf)
print(corr_decoding_syn_shuf)
print(corr_neuronal_shuf_syn_shuf)