-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdrgCaImAn_pre_per_to_PCA_fsdz_new.m
681 lines (604 loc) · 24.2 KB
/
drgCaImAn_pre_per_to_PCA_fsdz_new.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
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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
function handles_out2=drgCaImAn_pre_per_to_PCA_fsdz_new(pre_perBatchPathName, pre_perFileName, figNo, show_figures,no_sp_sm_trials_to_use,first_sp_sm_trial_no)
%
% reads the pre_per file and saves .mat files to process with
% Kording's lab
%
% close all
% clearvars -except pre_perBatchPathName pre_perFileName show_figures no_sp_sm_trials_to_use first_sp_sm_trial_no figNo
warning('off')
% simulation=0;
classifier_names{1}='Linear Discriminant';
classifier_names{2}='Support Vector Machine';
classifier_names{3}='Naive Bayes Classifier';
classifier_names{4}='Neural Network';
classifier_names{5}='Decision tree';
handles_out2.classifier_names=classifier_names;
% if nargin==0
% [pre_perFileName,pre_perBatchPathName] = uigetfile({'*pre_per.mat'},'Select the pre_per.mat file');
% fprintf(1, ['\ndrgCaImAn_pre_per_to_pydec run for ' pre_perFileName '\n\n']);
%
% p_threshold=0.05;
%
% %Choose the machine learning algorithm
% % 1 = linear discriminant analysis
% % 2 = SVM
% % 3 = Naive Bayes Classifier
% % 4 = neural network
% % 5 = decision tree
% MLalgo=1;
% show_figures=1;
% end
min_no_trials=10;
handles_out2.pre_perBatchPathName=pre_perBatchPathName;
handles_out2.pre_perFileName=pre_perFileName;
% handles_out2.p_threshold=p_threshold;
% handles_out2.MLalgo=MLalgo;
handles_out2.decoding_processed=1;
% if ~iscell(pre_perFileName)
load([pre_perBatchPathName pre_perFileName])
handles_out2.trialNo_sp=zeros(1,handles_out.no_sp_trials);
ii_sp=0;
handles_out2.trialNo_sm=zeros(1,handles_out.no_sm_trials);
ii_sm=0;
for ii_trials=1:no_odor_trials
if (epoch_per_trial(ii_trials)==6)||(epoch_per_trial(ii_trials)==7)
%This is an S+ trial
ii_sp=ii_sp+1;
handles_out2.trialNo_sp(ii_sp)=ii_trials;
else
%This is an S- trial
ii_sm=ii_sm+1;
handles_out2.trialNo_sm(ii_sm)=ii_trials;
end
end
handles_out2.no_odor_trials=no_odor_trials;
if (handles_out.no_sp_trials>=min_no_trials)&(handles_out.no_sm_trials>=min_no_trials)
szSp=size(splus_traces);
szSm=size(sminus_traces);
%time_to_event=([1:szSm(2)]*dt-dt_before);
time_to_eventSm=([1:szSm(2)]*dt-dt_before);
time_to_eventSp=([1:szSp(2)]*dt-dt_before);
handles_out2.time_to_eventSm=time_to_eventSm;
handles_out2.time_to_eventSp=time_to_eventSp;
if show_figures==1
%S+, S-, all snips
CIsm = bootci(1000, @mean, sminus_traces);
meansm=mean(sminus_traces,1);
CIsm(1,:)=meansm-CIsm(1,:);
CIsm(2,:)=CIsm(2,:)-meansm;
CIsp = bootci(1000, @mean, splus_traces);
meansp=mean(splus_traces,1);
CIsp(1,:)=meansp-CIsp(1,:);
CIsp(2,:)=CIsp(2,:)-meansp;
%First plot the average Splus and Sminus
figNo=figNo+1;
try
close(figNo)
catch
end
hFig = figure(figNo);
hold on
pct1=prctile([mean(sminus_traces,1)'; mean(splus_traces(:,1:szSp(2)),1)'],1);
pct99=prctile([mean(sminus_traces,1)'; mean(splus_traces(:,1:szSp(2)),1)'],99);
[hlsm, hpsm] = boundedline(time_to_eventSm',mean(sminus_traces,1)', CIsm', 'b');
[hlsp, hpsp] = boundedline(time_to_eventSp',mean(splus_traces,1)', CIsp', 'r');
%Odor on markers
plot([0 0],[pct1-0.1*(pct99-pct1) pct99+0.1*(pct99-pct1)],'-k')
odorhl=plot([0 mean(delta_odor)],[pct1-0.1*(pct99-pct1) pct1-0.1*(pct99-pct1)],'-k','LineWidth',5);
plot([mean(delta_odor) mean(delta_odor)],[pct1-0.1*(pct99-pct1) pct99+0.1*(pct99-pct1)],'-k')
%Reinforcement markers
plot([mean(delta_odor_on_reinf_on) mean(delta_odor_on_reinf_on)],[pct1-0.1*(pct99-pct1) pct99+0.1*(pct99-pct1)],'-r')
reinfhl=plot([mean(delta_odor_on_reinf_on) mean(delta_odor_on_reinf_on)+mean(delta_reinf)],[pct1-0.1*(pct99-pct1) pct1-0.1*(pct99-pct1)],'-r','LineWidth',5);
plot([mean(delta_odor_on_reinf_on)+mean(delta_reinf) mean(delta_odor_on_reinf_on)+mean(delta_reinf)],[pct1-0.1*(pct99-pct1) pct99+0.1*(pct99-pct1)],'-r')
title("Ca changes aligned to odor onset")
legend([hlsp hlsm odorhl reinfhl],'S+','S-','Odor','Reinforcement')
xlabel('Time (sec)')
ylabel('dF/F')
ylim([pct1-0.2*(pct99-pct1) pct99+0.2*(pct99-pct1)])
xlim([-10 19.8])
end
%Initialize variables
time_bins=length(handles_out.time_to_eventSp);
time=time_to_eventSp;
trNo=0;
tr_trNo=0;
%First and last sp trial numbers
if (first_sp_sm_trial_no<handles_out.no_sp_trials)&(first_sp_sm_trial_no+no_sp_sm_trials_to_use-1<=handles_out.no_sp_trials)
first_sp_trial=first_sp_sm_trial_no;
last_sp_trial=first_sp_sm_trial_no+no_sp_sm_trials_to_use-1;
else
if first_sp_sm_trial_no+no_sp_sm_trials_to_use-1>handles_out.no_sp_trials
first_sp_trial=handles_out.no_sp_trials-no_sp_sm_trials_to_use+1;
last_sp_trial=handles_out.no_sp_trials;
end
end
%First and last sm trial numbers
if (first_sp_sm_trial_no<handles_out.no_sm_trials)&(first_sp_sm_trial_no+no_sp_sm_trials_to_use-1<handles_out.no_sm_trials)
first_sm_trial=first_sp_sm_trial_no;
last_sm_trial=first_sp_sm_trial_no+no_sp_sm_trials_to_use-1;
else
if first_sp_sm_trial_no+no_sp_sm_trials_to_use-1>handles_out.no_sm_trials
first_sm_trial=handles_out.no_sm_trials-no_sp_sm_trials_to_use+1;
last_sm_trial=handles_out.no_sm_trials;
end
end
%Note: Training is done with no_sp_sm_trials_to_use and outcome is
%calculated for all trials
all_trials=handles_out.no_sm_trials+handles_out.no_sp_trials;
decisions=zeros(1,all_trials);
neural_recordings=zeros(all_trials,handles_out.no_components,time_bins);
ii_all=zeros(1,2*no_sp_sm_trials_to_use);
training_decisions=zeros(1,2*no_sp_sm_trials_to_use);
training_neural_recordings=zeros(2*no_sp_sm_trials_to_use,handles_out.no_components,time_bins);
%Save S+
%All trials, and training trials if adequate
ii=1;
for trialNo=1:handles_out.no_sp_trials
trNo=trNo+1;
if (trialNo>=first_sp_trial)&(trialNo<=last_sp_trial)
tr_trNo=tr_trNo+1;
end
for traceNo=1:handles_out.no_components
neural_recordings(trNo,traceNo,:)=splus_traces(ii,:);
if (trialNo>=first_sp_trial)&(trialNo<=last_sp_trial)
training_neural_recordings(tr_trNo,traceNo,:)=splus_traces(ii,:);
end
ii=ii+1;
end
decisions(trNo)=1;
if (trialNo>=first_sp_trial)&(trialNo<=last_sp_trial)
training_decisions(tr_trNo)=1;
ii_all(tr_trNo)=trialNo;
end
end
%Save S-
%All trials
ii=1;
for trialNo=1:handles_out.no_sm_trials
trNo=trNo+1;
if (trialNo>=first_sp_trial)&(trialNo<=last_sp_trial)
tr_trNo=tr_trNo+1;
end
for traceNo=1:handles_out.no_components
neural_recordings(trialNo+handles_out.no_sp_trials,traceNo,:)=sminus_traces(ii,:);
if (trialNo>=first_sp_trial)&(trialNo<=last_sp_trial)
training_neural_recordings(tr_trNo,traceNo,:)=sminus_traces(ii,:);
end
ii=ii+1;
end
decisions(trNo)=0;
if (trialNo>=first_sp_trial)&(trialNo<=last_sp_trial)
training_decisions(tr_trNo)=0;
ii_all(tr_trNo)=trialNo;
end
end
%For the training set calculate p values for the difference per neuron
no_neurons=handles_out.no_components;
tr_no_trials=tr_trNo;
no_timepoints=length(time_to_eventLDA);
p=[];
for ii_neuron=1:handles_out.no_components
these_recordings_sp=zeros(no_sp_sm_trials_to_use,no_timepoints);
these_recordings_sp(:,:)=training_neural_recordings(logical(training_decisions),ii_neuron,:);
these_recordings_sm=zeros(no_sp_sm_trials_to_use,no_timepoints);
these_recordings_sm(:,:)=training_neural_recordings(~logical(training_decisions),ii_neuron,:);
mean_sp_odor=zeros(no_sp_sm_trials_to_use,1);
mean_sp_odor(:,1)=mean(these_recordings_sp(:,time_to_eventLDA>0),2);
mean_sm_odor=zeros(no_sp_sm_trials_to_use,1);
mean_sm_odor(:,1)=mean(these_recordings_sm(:,time_to_eventLDA>0),2);
[h,p(ii_neuron)]=ttest2(mean_sp_odor,mean_sm_odor);
end
handles_out2.p=p;
else
handles_out2.decoding_processed=0;
end
% else
% sp_trials_per_file=[];
% sm_trials_per_file=[];
% len_time_to_eventSp=[];
% len_time_to_eventSm=[];
% no_components=[];
% for ii_file=1:length(pre_perFileName)
% load([pre_perBatchPathName{ii_file} pre_perFileName{ii_file}])
% sp_trials_per_file(ii_file)=handles_out.no_sp_trials;
% sm_trials_per_file(ii_file)=handles_out.no_sm_trials;
% len_time_to_eventSp(ii_file)=length(handles_out.time_to_eventSp);
% len_time_to_eventSm(ii_file)=length(handles_out.time_to_eventSm);
% no_components(ii_file)=handles_out.no_components;
% end
%
%
%
% if (max(sp_trials_per_file)<min_no_trials)||(max(sm_trials_per_file)<min_no_trials)
% handles_out2.decoding_processed=0;
% else
% no_sp_trials=max([min_no_trials min(sp_trials_per_file)]);
% no_sm_trials=max([min_no_trials min(sm_trials_per_file)]);
%
%
% no_timepoints=min([min(len_time_to_eventSp) min(len_time_to_eventSm)]);
% time=handles_out.time_to_eventSp(1:no_timepoints);
% neural_recordings=zeros(no_sp_trials+no_sm_trials,sum(no_components),no_timepoints);
% decisions=zeros(1,no_sp_trials+no_sm_trials);
%
% no_neurons=0;
% for ii_file=1:length(pre_perFileName)
%
% load([pre_perBatchPathName{ii_file} pre_perFileName{ii_file}])
%
% %Save S+
%
% trNo=1;
% ii=1;
% for trialNo=1:no_sp_trials
% for traceNo=1:handles_out.no_components
% neural_recordings(trialNo,traceNo+no_neurons,1:no_timepoints)=splus_traces(ii,1:no_timepoints);
% ii=ii+1;
% end
% decisions(trNo)=1;
% trNo=trNo+1;
% end
%
% %Save S-
% ii=1;
% for trialNo=1:no_sm_trials
% for traceNo=1:handles_out.no_components
% neural_recordings(trialNo+no_sp_trials,traceNo+no_neurons,1:no_timepoints)=sminus_traces(ii,1:no_timepoints);
% ii=ii+1;
% end
% decisions(trNo)=0;
% trNo=trNo+1;
% end
%
% no_neurons=no_neurons+handles_out.no_components;
%
% end
%
% %Calculate p values for the difference per neuron
% p=[];
% for ii_neuron=1:no_neurons
% these_recordings_sp=zeros(no_sp_trials,no_timepoints);
% these_recordings_sp=neural_recordings(logical(decisions),ii_neuron,:);
%
% these_recordings_sm=zeros(no_sm_trials,no_timepoints);
% these_recordings_sm=neural_recordings(~logical(decisions),ii_neuron,:);
%
% mean_sp_odor=zeros(no_sp_trials,1);
% mean_sp_odor(:,1)=mean(these_recordings_sp(:,time>0),2);
%
% mean_sm_odor=zeros(no_sm_trials,1);
% mean_sm_odor(:,1)=mean(these_recordings_sm(:,time>0),2);
%
% [h,p(ii_neuron)]=ttest2(mean_sp_odor,mean_sm_odor);
% end
%
% handles_out2.p=p;
% handles_out2.time=time;
% no_trials=trNo-1;
% end
% end
if handles_out2.decoding_processed==1
%Now do the PCA
for time_point=1:no_timepoints
these_neural_recs=zeros(tr_no_trials,no_neurons);
these_neural_recs(:,:)=training_neural_recordings(:,:,time_point);
[coeff,score,latent] = pca(these_neural_recs);
if time_point==1
pca_scores=zeros(no_timepoints,tr_no_trials,size(score,2));
end
pca_scores(time_point,:,:)=score;
end
show_figures=1;
if show_figures==1
%Plot trajectory in 3D space
figNo=figNo+1;
try
close(figNo)
catch
end
figure(figNo)
hold on
for trNo=1:tr_no_trials
x=zeros(1,no_timepoints);
x(1,:)=pca_scores(:,trNo,1);
y=zeros(1,no_timepoints);
y(1,:)=pca_scores(:,trNo,2);
z=zeros(1,no_timepoints);
z(1,:)=pca_scores(:,trNo,3);
if training_decisions(trNo)==1
plot3(x,y,z,'-r')
else
plot3(x,y,z,'-b')
end
end
%Plot average trajectory in 3D space
figNo=figNo+1;
try
close(figNo)
catch
end
figure(figNo)
hold on
x=zeros(1,no_timepoints);
x(1,:)=mean(pca_scores(:,training_decisions==1,1),2);
y=zeros(1,no_timepoints);
y(1,:)=mean(pca_scores(:,training_decisions==1,2),2);
z=zeros(1,no_timepoints);
z(1,:)=mean(pca_scores(:,training_decisions==1,3),2);
plot3(x,y,z,'-r')
x=zeros(1,no_timepoints);
x(1,:)=mean(pca_scores(:,training_decisions==0,1),2);
y=zeros(1,no_timepoints);
y(1,:)=mean(pca_scores(:,training_decisions==0,2),2);
z=zeros(1,no_timepoints);
z(1,:)=mean(pca_scores(:,training_decisions==0,3),2);
plot3(x,y,z,'-b')
%Plot average single points per trial in 3D space
figNo=figNo+1;
try
close(figNo)
catch
end
figure(figNo)
hold on
x=zeros(1,sum(training_decisions==1));
x(1,:)=mean(pca_scores(time_to_eventLDA>0,training_decisions==1,1),1);
y=zeros(1,sum(training_decisions==1));
y(1,:)=mean(pca_scores(time_to_eventLDA>0,training_decisions==1,2),1);
z=zeros(1,sum(training_decisions==1));
z(1,:)=mean(pca_scores(time_to_eventLDA>0,training_decisions==1,3),1);
plot3(x,y,z,'or')
x=zeros(1,sum(training_decisions==0));
x(1,:)=mean(pca_scores(time_to_eventLDA>0,training_decisions==0,1),1);
y=zeros(1,sum(training_decisions==1));
y(1,:)=mean(pca_scores(time_to_eventLDA>0,training_decisions==0,2),1);
z=zeros(1,sum(training_decisions==1));
z(1,:)=mean(pca_scores(time_to_eventLDA>0,training_decisions==0,3),1);
plot3(x,y,z,'ob')
%Now do the PCA for mean(time>0)
these_neural_recs=zeros(tr_no_trials,no_neurons);
these_neural_recs(:,:)=mean(training_neural_recordings(:,:,time_to_eventLDA>0),3);
[coeff,pca_scores_past_zero,latent] = pca(these_neural_recs);
%Plot average single points per trial in 3D space
figNo=figNo+1;
try
close(figNo)
catch
end
figure(figNo)
hold on
x=zeros(1,sum(training_decisions==1));
x(1,:)=pca_scores_past_zero(training_decisions==1,1);
y=zeros(1,sum(training_decisions==1));
y(1,:)=pca_scores_past_zero(training_decisions==1,2);
z=zeros(1,sum(training_decisions==1));
z(1,:)=pca_scores_past_zero(training_decisions==1,3);
plot3(x,y,z,'or')
x=zeros(1,sum(training_decisions==0));
x(1,:)=pca_scores_past_zero(training_decisions==0,1);
y=zeros(1,sum(training_decisions==0));
y(1,:)=pca_scores_past_zero(training_decisions==0,2);
z=zeros(1,sum(training_decisions==0));
z(1,:)=pca_scores_past_zero(training_decisions==0,3);
plot3(x,y,z,'ob')
%Now do the PCA for all points time>0
these_neural_recs=zeros(tr_no_trials,no_neurons*length(time_to_eventLDA>0));
ii_time_first=find(time_to_eventLDA>0,1,'first');
ii_comps=0;
for ii_time=ii_time_first:length(time_to_eventLDA)
these_neural_recs(:,ii_comps+1:ii_comps+no_neurons)=training_neural_recordings(:,:,ii_time);
ii_comps=ii_comps+no_neurons;
end
[coeff,pca_scores_past_zero,latent] = pca(these_neural_recs);
%Plot average single points per trial in 3D space
figNo=figNo+1;
try
close(figNo)
catch
end
figure(figNo)
hold on
x=zeros(1,sum(training_decisions==1));
x(1,:)=pca_scores_past_zero(training_decisions==1,1);
y=zeros(1,sum(training_decisions==1));
y(1,:)=pca_scores_past_zero(training_decisions==1,2);
z=zeros(1,sum(training_decisions==1));
z(1,:)=pca_scores_past_zero(training_decisions==1,3);
plot3(x,y,z,'or')
x=zeros(1,sum(training_decisions==0));
x(1,:)=pca_scores_past_zero(training_decisions==0,1);
y=zeros(1,sum(training_decisions==0));
y(1,:)=pca_scores_past_zero(training_decisions==0,2);
z=zeros(1,sum(training_decisions==0));
z(1,:)=pca_scores_past_zero(training_decisions==0,3);
plot3(x,y,z,'ob')
end
pffft=1;
else
handles_out2.decoding_processed=0;
end
% %Note that the accuracy output is only for the training trial set
% handles_out2.accuracy=accuracy;
% handles_out2.sh_accuracy=sh_accuracy;
% handles_out2.mean_accuracy=mean(accuracy(time>=0));
% handles_out2.mean_sh_accuracy=mean(sh_accuracy(time>=0));
% handles_out2.delta_odor=mean(delta_odor);
% handles_out2.delta_odor_on_reinf_on=mean(delta_odor_on_reinf_on);
% handles_out2.delta_reinf=mean(delta_reinf);
% handles_out2.no_sp_trials=handles_out.no_sp_trials;
% handles_out2.no_sm_trials=handles_out.no_sm_trials;
%
% %Now use Bishop's (2006) majority rule
% winning_label=zeros(1,Nall);
% for this_tr_No=1:Nall
% these_labels=zeros(1,sum(time>=0));
% these_labels(1,:)=training_output_labels(time>=0,this_tr_No);
% if sum(these_labels==1)>sum(these_labels==0)
% winning_label(this_tr_No)=1;
% else
% if sum(these_labels==0)>sum(these_labels==1)
% winning_label(this_tr_No)=0;
% else
% if rand>0.5
% winning_label(this_tr_No)=1;
% else
% winning_label(this_tr_No)=0;
% end
% end
% end
% end
%
% handles_out2.bishop_accuracy=sum(winning_label==training_decisions)/Nall;
% these_bishop_sh_accuracy=[];
% for ii_no=1:5
% shuffled_training_decisions=training_decisions(randperm(Nall));
% these_bishop_sh_accuracy(ii_no)=sum(winning_label==shuffled_training_decisions)/Nall;
% end
% handles_out2.bishop_sh_accuracy=mean(these_bishop_sh_accuracy);
%
% handles_out2.winning_label=winning_label;
% handles_out2.training_decisions=training_decisions;
%
% %Now decode for the rest of the trials using the entire training set for training
% if sum(p<=p_threshold)>0
%
%
% %Calculate the z values
% z_neural_recordings=zeros(all_trials,handles_out.no_components,no_timepoints);
% for ii_neurons=1:no_neurons
% z_neural_recordings(:,ii_neurons,:)=(neural_recordings(:,ii_neurons,:)-mean_per_neuron(ii_neurons))/STD_per_neuron(ii_neurons);
% end
%
%
%
%
% for time_point=1:no_timepoints
%
% %dFF per trial per component
% measurements=zeros(Nall,sum(p<p_threshold));
% measurements(:,:)=z_training_neural_recordings(:,p<p_threshold,time_point);
%
%
%
% correct_predict=[];
% correct_predict_shuffled=[];
%
%
%
% %Now train the decoder with all trials in the decoding data set
%
%
%
% %Store the training data in a table.
% tblTrn=[];
% tblTrn = array2table(measurements);
%
% %Store the decisions in Y
% Y=training_decisions;
%
% %Train a discriminant analysis model using the training set and default options.
% %By default this is a regularized linear discriminant analysis (LDA)
% switch MLalgo
% case 1
% Mdl = fitcdiscr(tblTrn,Y);
% case 2
% Mdl = fitcsvm(tblTrn,Y);
% case 3
% Mdl = fitcnb(tblTrn,Y);
% case 4
% Mdl = fitcnet(tblTrn,Y);
% case 5
% Mdl = fitctree(tblTrn,Y);
% end
%
% %Now predict the outcome for all trials excluding the training set
% all_measurements=zeros(all_trials,sum(p<p_threshold));
% all_measurements(:,:)=z_neural_recordings(:,p<p_threshold,time_point);
%
% %Predict labels for all trials excluding the training set
% for jj=1:all_trials
% if sum(jj==ii_all)>0
% [label,score] = predict(Mdl,all_measurements(jj,:));
%
% %label is the predicted label, and score is the predicted class
% %posterior probability
%
% if label==decisions(jj)
% handles_out2.correct_predict(time_point,jj)=1;
% else
% handles_out2.correct_predict(time_point,jj)=0;
% end
%
% jj_shuffled=randperm(all_trials);
%
% if label==decisions(jj_shuffled(jj))
% handles_out2.correct_predict_shuffled(time_point,jj)=1;
% else
% handles_out2.correct_predict_shuffled(time_point,jj)=0;
% end
%
% end
% end
%
%
% if show_figures==1
% fprintf(1, ['For timepoint %d accuracy= %d and shuffled accuracy= %d\n'],time_point,accuracy(time_point),sh_accuracy(time_point));
% end
% end
%
%
% end
%
% if show_figures==1
% figNo=figNo+1;
% try
% close(figNo)
% catch
% end
%
% figure(figNo)
%
% % subplot(1,2,1)
% hold on
%
%
% %Plot the bounded line for the 5 percentile for the shuffled trials
% per95=prctile(sh_accuracy(1,:),95);
% per5=prctile(sh_accuracy(1,:),5);
% CIsh=[mean(sh_accuracy)-per5 per95-mean(sh_accuracy)]';
% [hlCR, hpCR] = boundedline([time_to_eventLDA(1) time_to_eventLDA(end)],[mean(sh_accuracy) mean(sh_accuracy)], CIsh', 'r');
%
% %Plot the accuracy
% plot(time',accuracy,'-k')
%
% %Now plot the bootstrapped confidence intervals for the original and
%
% %For the accuracy use odor 0 to the end
% CI = bootci(1000, {@mean, accuracy(time>=0)},'type','cper');
% bar_offset=max(time)+1;
% plot([bar_offset bar_offset],CI,'-k','LineWidth',3)
% plot([bar_offset],mean(accuracy(time>=0)),'ok')
%
% %For the shuffled accuracy use all points
% CI = bootci(1000, {@mean, sh_accuracy},'type','cper');
% bar_offset=max(time)+1;
% plot([bar_offset bar_offset],CI,'-r','LineWidth',3)
% plot([bar_offset],mean(sh_accuracy),'ok')
%
% %Odor on markers
% plot([0 0],[0 1.1],'-k')
% odorhl=plot([0 mean(delta_odor)],[0.32 0.32],'-k','LineWidth',5);
% plot([mean(delta_odor) mean(delta_odor)],[0 1.10],'-k')
%
% %Reinforcement markers
% plot([mean(delta_odor_on_reinf_on) mean(delta_odor_on_reinf_on)],[0 1.10],'-r')
% reinfhl=plot([mean(delta_odor_on_reinf_on) mean(delta_odor_on_reinf_on)+mean(delta_reinf)],[.32 .32],'-r','LineWidth',5);
% plot([mean(delta_odor_on_reinf_on)+mean(delta_reinf) mean(delta_odor_on_reinf_on)+mean(delta_reinf)],[0 1.10],'-r')
%
%
% ylim([00 1.10])
%
% xlabel('Time (sec)')
% ylabel('Accuracy')
% end
pffft=1;