-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathplots.m
677 lines (636 loc) · 24.4 KB
/
plots.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
clear all
% load classProb
load ('./results/classProb_3class.mat'); NbrSess = subNbrOfSess;
Labels = Labels+1;
sub11.Labels = Labels(:,:,1:NbrSess(11),11);
sub11.classProb = classProb(:,:,:,1:NbrSess(11),11);
sub12.Labels = Labels(:,:,1:NbrSess(12),12);
sub12.classProb = classProb(:,:,:,1:NbrSess(12),12);
color = ['g','r','c'];
%
% for k = 1:4
% tmp = mean(sub11.classProb(:,:,sub11.Labels(:,1,1)==k,1),3);
% figure, plot(tmp', '-s', 'LineWidth',2, 'MarkerSize',5)
% end
% %frt = ['-sr';'-ob';'-dg';'-pk'; '-hm'; '-^c'];
%% PLOT CLASS PROBABILITY VS. NUMBER OF EPOCHS
%-- SUBJECT WITH LEAST PERFORMANCE
% for k = 1:4
% figure
% tmp = mean(sub11.classProb(:,:,sub11.Labels(:,1,1)==k,1),3);
% for l = 1:4
% if l == k
% plot((1:numel(tmp(l,:))),tmp(l,:), '-sr', 'LineWidth',2, 'MarkerSize',4)
% else
% plot((1:numel(tmp(l,:))),tmp(l,:), '-sk', 'LineWidth',2, 'MarkerSize',4)
% end
% hold on
% end
% end
% xlabel('#Epochs');
% ylabel('Class probability');
% set(gca,'FontSize',14,'fontWeight','normal')
% set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
%-- SUBJECT WITH BEST PERFOMANCE
legends = {'13Hz class', '21Hz class', '17Hz class'};
for k = 1:size(classProb,1)
figure
tmp = mean(sub12.classProb(:,:,sub12.Labels(:,1,1)==k,1),3);
for l = 1:size(classProb,1)
if l == k
plot((1:numel(tmp(l,1:18))),tmp(l,1:18), ['-p' color(l)], 'LineWidth',2, 'MarkerSize',5, 'MarkerFaceColor', color(l), 'DisplayName', legends{l})
legend('-DynamicLegend');
legend boxoff
else
plot((1:numel(tmp(l,1:18))),tmp(l,1:18), ['-d' color(l)], 'LineWidth',1, 'MarkerSize',5, 'MarkerFaceColor', color(l), 'DisplayName', legends{l})
legend('-DynamicLegend');
legend boxoff
end
hold all
end
xlabel('Epoch index');
ylabel('Class probability');
set(gca,'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
end
%% PLOT AVERAGE CLASSIFICATION ERROR VS. NUMBER OF EPOCHS
for sub = 1:12
clear er
sub_labels = Labels(:,:,1:NbrSess(sub),sub);
sub_prob = classProb(:,:,:,1:NbrSess(sub),sub);
for sess = 1:NbrSess(sub)
for tr = 1:8*size(classProb,1)
[v p] = max(sub_prob(:,:,tr,sess));
% er(tr,:,sess) = abs(p - sub_labels(tr,:,sess));
% er(tr,:,sess) = ceil(er(tr,:,sess)/4);
er1(tr,:,sess,sub) = abs(p - sub_labels(tr,:,sess));
er1(tr,:,sess,sub) = ceil(er1(tr,:,sess,sub)/size(classProb,1));
end
end
% tmp = permute(er,[2 1 3]);
% tmp2 = tmp(:,:);
% errMean(sub,:) = mean(tmp2,2);
e = squeeze(er1(:,:,1:NbrSess(sub),sub));
tmp = permute(e,[2 1 3]);
tmp2 = tmp(:,:);
errMean(sub,:) = mean(tmp2,2);
%figure, plot(errMean(sub,:))
end
mer = mean(errMean); %-- All subjects mean error
ser = std(errMean); %-- standard dev. of error accross subjects
figure, plot(mer(1:18), '-o','LineWidth',2)
xlabel('Epoch index');
ylabel('Average classification error');
set(gca,'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
%-- PLOT ERROR BAR
figure, errorbar(mer, ser, '-s','LineWidth',1, 'MarkerSize',10, 'MarkerFaceColor', 'b')
xlabel('Epoch index');
ylabel('Average classification error');
set(gca,'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
%% PLOT AVERAGE CLASSIFICATION ERROR VS. PROBABILITY THRESHOLD
clear all
% load classProb
load('./results/classProb_3class.mat'); NbrSess = subNbrOfSess;
Labels = Labels+1;
probIdx = 1;
for prob = 0:0.1:1
for sub = 1:12
sub_labels = Labels(:,:,1:NbrSess(sub),sub);
sub_prob = classProb(:,:,:,1:NbrSess(sub),sub);
for sess = 1:NbrSess(sub)
for tr = 1:8*size(classProb,1)
[v p] = max(sub_prob(:,:,tr,sess));
v2 = find(v>prob);
if (isempty(v2))
ytrial_pos = numel(v);
ytrial = 1;
else
ytrial_pos = v2(1);
ytrial = p(ytrial_pos);
end
er0 = abs(ytrial - sub_labels(tr,1,sess));
err(tr,sess,sub,probIdx) = ceil(er0/size(classProb,1));
temps(tr,sess,sub,probIdx) = ytrial_pos*0.2;
end
end
end
probIdx = probIdx + 1;
end
for sub = 1:12
tmp = squeeze(err(:,1:NbrSess(sub),sub,:));
tmp2 = permute(tmp, [3, 1, 2]);
tmp3 = tmp2(:,:);
erMean(:,sub) = mean(tmp3,2);
tmp = squeeze(temps(:,1:NbrSess(sub),sub,:));
tmp2 = permute(tmp, [3, 1, 2]);
tmp3 = tmp2(:,:);
tempsMean(:,sub) = mean(tmp3,2);
% e = squeeze(er1(:,:,:,sub));
% tmp = permute(e,[2 1 3]);
% tmp2 = tmp(:,:);
% errMean(sub,:) = mean(tmp2,2);
end
prob = 0:0.1:0.9;
figure, plot(prob, mean(erMean(1:10,:),2), '--s','LineWidth',2)
xlabel('Probability threshold ');
ylabel('Average classification error');
set(gca,'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
%-- PLOT ERROR BAR
figure, errorbar(prob, mean(erMean(1:10,:),2), std(erMean(1:10,:),[],2), '-s','LineWidth',1, 'MarkerSize',10, 'MarkerFaceColor', 'b')
xlim([-0.1 1])
ylim([0.1 0.4])
xlabel('Probability threshold ');
ylabel('Average classification error');
set(gca,'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
% %-- PLOT AVERAGE ITR VS. PROBABILITY THRESHOLD
% po = 1-mean(erMean(1:10,:),2);
% tLen = mean(tempsMean(1:10,:),2);
% B = log2(4)+po.*log2(po)+(1-po).*log2((1-po)/(4-1))
% bBm = B.*(60./tLen);
% figure, plot(bBm)
figure
%ylim([0 0.5])
[hAx,hLine1,hLine2] = plotyy(prob, mean(erMean(1:10,:),2), prob,mean(tempsMean(1:10,:),2),'plot');
set(get(hAx(1),'Ylabel'),'String','Average classification error')
set(get(hAx(2),'Ylabel'),'String','Average classification time (s)')
set(hLine1,'LineStyle','--','Marker', 's','LineWidth', 2)
set(hLine2,'LineStyle',':','Marker', 'o','LineWidth', 2)
xlabel('Probability threshold ')
set(gca,'FontSize',14,'fontWeight','normal')
set(hAx(2),'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
% %--PLot error bars
% hold(hAx(1),'on')
% errorbar(hAx(1), prob, mean(erMean(1:5,:),2), std(erMean(1:5,:),[],2), 's' )
% hold(hAx(1),'off')
% hold(hAx(2),'on')
% errorbar(hAx(2), alpha, resMean(:,4), resStd(:,4), 'o' )
% ylim(hAx(1),[20 max((round(1000*resMean(:,2)))/10+ (round(1000*resStd(:,2)))/10)])
% % ylim(hAx(2),[0 max(resMean(:,4)+ resStd(:,4))])
% ylim(hAx(2),[0 0.8])
%% PLOT IMPACT OF W (window size/tLen) on online clasification accuracy and ITR
load('./results/online_curve_tlen_3class_new.mat')
meanAcc = mean(subAcMean,2);
stdAcc = std(subAcMean,[],2);
meanItr = mean(itr3,2);
stdItr = std(itr3,[],2);
figure
[hAx,hLine1,hLine2] = plotyy(tlen,(round(1000*meanAcc))/10,tlen,meanItr,'plot');
set(get(hAx(1),'Ylabel'),'String','Accuracy (%)')
set(get(hAx(2),'Ylabel'),'String','ITR (bits/min)')
set(hLine1,'LineStyle','-', 'LineWidth', 3)
set(hLine2,'LineStyle','-', 'LineWidth', 3)
xlabel('Window size (w) in sec ')
set(gca,'FontSize',14,'fontWeight','normal')
set(hAx(2),'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
%--PLot error bars
hold(hAx(1),'on')
errorbar(hAx(1), tlen, (round(1000*meanAcc))/10, (round(1000*stdAcc))/10)
hold(hAx(1),'off')
hold(hAx(2),'on')
errorbar(hAx(2), tlen, meanItr, stdItr)
ylim(hAx(1),[50 max((round(1000*meanAcc))/10+ (round(1000*stdAcc))/10)])
% ylim(hAx(2),[0 max(resMean(:,4)+ resStd(:,4))])
ylim(hAx(2),[0 max(meanItr)+max(stdItr)])
%##################################################################################################################################################################
%% PLOT FOR 4 CLASSES
%##################################################################################################################################################################
clear all
% load classProb
load('./results/classProb_4class.mat'); NbrSess = subNbrOfSess;
Labels = Labels+1;
sub11.Labels = Labels(:,:,1:NbrSess(11),11);
sub11.classProb = classProb(:,:,:,1:NbrSess(11),11);
sub12.Labels = Labels(:,:,1:NbrSess(12),12);
sub12.classProb = classProb(:,:,:,1:NbrSess(12),12);
%
% for k = 1:4
% tmp = mean(sub11.classProb(:,:,sub11.Labels(:,1,1)==k,1),3);
% figure, plot(tmp', '-s', 'LineWidth',2, 'MarkerSize',5)
% end
% %frt = ['-sr';'-ob';'-dg';'-pk'; '-hm'; '-^c'];
%% PLOT CLASS PROBABILITY VS. NUMBER OF EPOCHS
%-- SUBJECT WITH LEAST PERFORMANCE
% for k = 1:4
% figure
% tmp = mean(sub11.classProb(:,:,sub11.Labels(:,1,1)==k,1),3);
% for l = 1:4
% if l == k
% plot((1:numel(tmp(l,:))),tmp(l,:), '-sr', 'LineWidth',2, 'MarkerSize',4)
% else
% plot((1:numel(tmp(l,:))),tmp(l,:), '-sk', 'LineWidth',2, 'MarkerSize',4)
% end
% hold on
% end
% end
% xlabel('Epoch index');
% ylabel('Class probability');
% set(gca,'FontSize',14,'fontWeight','normal')
% set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
%-- SUBJECT WITH BEST PERFOMANCE
color = ['b','g','r','c'];
legends = {'Resting clas', '13Hz class', '21Hz class', '17Hz class'};
for k = 1:size(classProb,1)
figure
tmp = mean(sub12.classProb(:,:,sub12.Labels(:,1,1)==k,1),3);
for l = 1:size(classProb,1)
if l == k
plot((1:numel(tmp(l,1:18))),tmp(l,1:18), ['-p' color(l)], 'LineWidth',2, 'MarkerSize',5, 'MarkerFaceColor', color(l), 'DisplayName', legends{l})
legend('-DynamicLegend');
%legend boxoff
else
plot((1:numel(tmp(l,1:18))),tmp(l,1:18), ['-d' color(l)], 'LineWidth',1, 'MarkerSize',5, 'MarkerFaceColor', color(l), 'DisplayName', legends{l})
legend('-DynamicLegend');
%legend boxoff
end
hold all
end
xlabel('Epoch index');
ylabel('Class probability');
set(gca,'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
end
%% PLOT AVERAGE CLASSIFICATION ERROR VS. NUMBER OF EPOCHS
for sub = 1:12
clear er
sub_labels = Labels(:,:,1:NbrSess(sub),sub);
sub_prob = classProb(:,:,:,1:NbrSess(sub),sub);
for sess = 1:NbrSess(sub)
for tr = 1:8*size(classProb,1)
[v p] = max(sub_prob(:,:,tr,sess));
% er(tr,:,sess) = abs(p - sub_labels(tr,:,sess));
% er(tr,:,sess) = ceil(er(tr,:,sess)/4);
er1(tr,:,sess,sub) = abs(p - sub_labels(tr,:,sess));
er1(tr,:,sess,sub) = ceil(er1(tr,:,sess,sub)/size(classProb,1));
end
end
% tmp = permute(er,[2 1 3]);
% tmp2 = tmp(:,:);
% errMean(sub,:) = mean(tmp2,2);
e = squeeze(er1(:,:,1:NbrSess(sub),sub));
tmp = permute(e,[2 1 3]);
tmp2 = tmp(:,:);
errMean(sub,:) = mean(tmp2,2);
%figure, plot(errMean(sub,:))
end
mer = mean(errMean); %-- All subjects mean error
ser = std(errMean); %-- standard dev. of error accross subjects
figure, plot(mer(1:18), '-o','LineWidth',2)
xlabel('Epoch index');
ylabel('Average classification error');
set(gca,'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
%-- PLOT ERROR BAR
figure, errorbar(mer, ser, '-s','LineWidth',1, 'MarkerSize',10, 'MarkerFaceColor', 'b')
xlabel('Epoch index');
ylabel('Average classification error');
set(gca,'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
%% PLOT AVERAGE CLASSIFICATION ERROR VS. PROBABILITY THRESHOLD
clear all
% load classProb
load('./results/classProb_4class.mat'); NbrSess = subNbrOfSess;
Labels = Labels+1;
probIdx = 1;
for prob = 0:0.1:1
for sub = 1:12
sub_labels = Labels(:,:,1:NbrSess(sub),sub);
sub_prob = classProb(:,:,:,1:NbrSess(sub),sub);
for sess = 1:NbrSess(sub)
for tr = 1:8*size(classProb,1)
[v p] = max(sub_prob(:,:,tr,sess));
v2 = find(v>prob);
if (isempty(v2))
ytrial_pos = numel(v);
ytrial = 1;
else
ytrial_pos = v2(1);
ytrial = p(ytrial_pos);
end
er0 = abs(ytrial - sub_labels(tr,1,sess));
err(tr,sess,sub,probIdx) = ceil(er0/size(classProb,1));
temps(tr,sess,sub,probIdx) = ytrial_pos*0.2;
end
end
end
probIdx = probIdx + 1;
end
for sub = 1:12
tmp = squeeze(err(:,1:NbrSess(sub),sub,:));
tmp2 = permute(tmp, [3, 1, 2]);
tmp3 = tmp2(:,:);
erMean(:,sub) = mean(tmp3,2);
tmp = squeeze(temps(:,1:NbrSess(sub),sub,:));
tmp2 = permute(tmp, [3, 1, 2]);
tmp3 = tmp2(:,:);
tempsMean(:,sub) = mean(tmp3,2);
end
prob = 0:0.1:0.9;
figure, plot(prob, mean(erMean(1:10,:),2), '--s','LineWidth',2)
xlabel('Probability threshold ');
ylabel('Average classification error');
set(gca,'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
%-- PLOT ERROR BAR
figure, errorbar(prob, mean(erMean(1:10,:),2), std(erMean(1:10,:),[],2), '-s','LineWidth',1, 'MarkerSize',10, 'MarkerFaceColor', 'b')
xlim([-0.1 1])
ylim([0.1 0.5])
xlabel('Probability threshold ');
ylabel('Average classification error');
set(gca,'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
% %-- PLOT AVERAGE ITR VS. PROBABILITY THRESHOLD
% po = 1-mean(erMean(1:10,:),2);
% tLen = mean(tempsMean(1:10,:),2);
% B = log2(4)+po.*log2(po)+(1-po).*log2((1-po)/(4-1))
% bBm = B.*(60./tLen);
% figure, plot(bBm)
figure
%ylim([0 0.5])
[hAx,hLine1,hLine2] = plotyy(prob, mean(erMean(1:10,:),2), prob,mean(tempsMean(1:10,:),2),'plot');
set(get(hAx(1),'Ylabel'),'String','Average classification error')
set(get(hAx(2),'Ylabel'),'String','Average classification time (s)')
set(hLine1,'LineStyle','--','Marker', 's','LineWidth', 2)
set(hLine2,'LineStyle',':','Marker', 'o','LineWidth', 2)
xlabel('Probability threshold ')
set(gca,'FontSize',14,'fontWeight','normal')
set(hAx(2),'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
% %--PLot error bars
% hold(hAx(1),'on')
% errorbar(hAx(1), prob, mean(erMean(1:5,:),2), std(erMean(1:5,:),[],2), 's' )
% hold(hAx(1),'off')
% hold(hAx(2),'on')
% errorbar(hAx(2), alpha, resMean(:,4), resStd(:,4), 'o' )
% ylim(hAx(1),[20 max((round(1000*resMean(:,2)))/10+ (round(1000*resStd(:,2)))/10)])
% % ylim(hAx(2),[0 max(resMean(:,4)+ resStd(:,4))])
% ylim(hAx(2),[0 0.8])
%% PLOT IMPACT OF W (window size/tLen) on online clasification accuracy and ITR
load('./results/online_curve_tlen_4class.mat')
meanAcc = mean(subAcMean,2);
stdAcc = std(subAcMean,[],2);
meanItr = mean(itr3,2);
stdItr = std(itr3,[],2);
figure
[hAx,hLine1,hLine2] = plotyy(tlen,(round(1000*meanAcc))/10,tlen,meanItr,'plot');
set(get(hAx(1),'Ylabel'),'String','Accuracy (%)')
set(get(hAx(2),'Ylabel'),'String','ITR (bits/min)')
set(hLine1,'LineStyle','-', 'LineWidth', 3)
set(hLine2,'LineStyle','-', 'LineWidth', 3)
xlabel('Window size (w) in sec ')
set(gca,'FontSize',14,'fontWeight','normal')
set(hAx(2),'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
%--PLot error bars
hold(hAx(1),'on')
errorbar(hAx(1), tlen, (round(1000*meanAcc))/10, (round(1000*stdAcc))/10)
hold(hAx(1),'off')
hold(hAx(2),'on')
errorbar(hAx(2), tlen, meanItr, stdItr)
ylim(hAx(1),[50 max((round(1000*meanAcc))/10+ (round(1000*stdAcc))/10)])
% ylim(hAx(2),[0 max(resMean(:,4)+ resStd(:,4))])
ylim(hAx(2),[0 max(meanItr)+max(stdItr)])
%% PLOT CONFUSION MATRIX AND ROC SPACE
clear all
load('./results/online_curve_potato_4class.mat')
LabelAll = LabelAll+1;
Yall = Yall+1;
targets = zeros(numel(unique(LabelAll)), numel(LabelAll));
outputs = zeros(numel(unique(LabelAll)), numel(LabelAll));
for k = 1:numel(unique(LabelAll))
lab = zeros(4,1);
lab(k) = 1;
targets(:,LabelAll==k) = repmat(lab,1,sum(LabelAll==k));
outputs(:,Yall==k) = repmat(lab,1,sum(Yall==k));
TPR(k) = CP{k}.Sensitivity;
FPR(k) = 1-CP{k}.Specificity;
end
figure,
plotconfusion(targets, outputs);
chance = [0 1];
figure,
plot([0 1], chance,'--r','LineWidth', 3, 'DisplayName', 'Random guess')
%legend('Random guess')
legend('-DynamicLegend');
hold all
marker = ['h','p','s','d'];
legends = {'Resting class', '13Hz class', '21Hz class', '17Hz class'};
for k = 1:numel(unique(LabelAll))
plot(FPR(k), TPR(k), marker(k), 'LineWidth', 3, 'MarkerSize',8, 'DisplayName', legends{k})
%legend('cl')
end
plot(0,1, 'o', 'LineWidth', 3, 'MarkerSize',8, 'DisplayName', 'Perfect classification')
plot(1,0, 'o', 'LineWidth', 3, 'MarkerSize',8, 'DisplayName', 'Worst classification')
xlabel('FPR or (1-specificity)');
ylabel('TPR or sensitivity');
set(gca,'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
%% PLOT DELAYS IN TIME SIGNAL SYNCHRONIZATION
clear all
tLen = 8;
delay = -2;
for sub = 16:17 %- ploting two subjects (11 and 12)
clear x_all H_all P X Pm PSD
%-- Load data
[S_all, H_all] = loaddata(sub); %Returns cells of data from all available sessions
Fs = H_all{1}.SampleRate;
nbrSessions = length(S_all);
sessions = 1:nbrSessions;
%- Preprocessing of all available sessions (Same for training and test data)
% 1) Band pass filter
for session = 1:nbrSessions
x_all{session} = bandpass_filter_ext([12.95 13.05], [16.9 17.1], [20.9 21.1], S_all{session}, H_all{session}); %74.31
end
X = get_trials(x_all, H_all, tLen, delay);
taxis = [delay:1/Fs:delay+tLen]; taxis = taxis(1:end-1);
titles = [
'Example trial from resting state';
' Example trial from 13Hz SSVEP ';
' Example trial from 21Hz SSVEP ';
' Example trial from 17Hz SSVEP '];
%klass = ['No'; '13'; '21'; '17'];
set(groot,'defaultAxesColorOrder','remove')
set(groot,'defaultAxesColorOrder',[0 1 0;1 0 0;0 1 1]);
figure
%set(groot,'defaultAxesColorOrder',[0 1 0;1 0 0;0 1 1]);
set(gcf,'DefaultAxesColorOrder',[0 1 0;1 0 0;0 1 1])
for cl = 1:size(X,2)
subplot(2,2,cl)
if sub == 16
%set(gca, 'ColorOrder', [0 1 0; 1 0 0;0 1 1], 'NextPlot', 'replacechildren');
plot(taxis, squeeze(X{cl}([1 17 9],:,7))'),
if cl > 2, xlabel('time(s)'); end
end
if sub == 17
%set(gca, 'ColorOrder', [0 1 0; 1 0 0;0 1 1]);%, 'NextPlot', 'replacechildren');
plot(taxis, squeeze(X{cl}([1 17 9],:,10))'),
if cl > 2, xlabel('time(s)'); end
end
hold on
if sub == 16
plot([0 0],[-0.0021 0.0021], '>--k')
ylim([-0.0021 0.0021])
end
if sub == 17
plot([0 0],[-0.006 0.006], '>--k')
ylim([-0.006 0.006])
end
if cl == 1 & sub == 17
legend(['13Hz';'21Hz';'17Hz']);
%legend boxoff
end
title(titles(cl,:))
yticks = get(gca,'ytick');
set(gca,'yticklabel',yticks*1000);
if mod(cl,2)==0
set(gca,'YTick',[])
end
if cl < 3
set(gca, 'XTick', [])
end
set(gca,'FontSize',12,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',12,'fontWeight','normal')
pbaspect([16/16 9/16 1]); %Set figure(plot) aspect ratio
end
%fpad = [0 0 0 0]; axpad = [0 0];
spaceplots; %cutt off blank margins (from matlab filexchage)
end
%% COMPUTE AND PLOT ROC CURVE BASED ON RHO
clear all
% load classProb
load('./results/classProb_4class.mat'); NbrSess = subNbrOfSess;
Labels = Labels+1;
rho4 = [];
label4 = [];
for sub = 1:12
sub_labels = Labels(:,:,1:NbrSess(sub),sub);
sub_prob = classProb(:,:,:,1:NbrSess(sub),sub);
Lsub = [];
rho = [];
label = [];
for sess = 1:NbrSess(sub)
for tr = 1:8*size(classProb,1)
Lsub(tr,sess) = sub_labels(tr,1,sess);
%rho(tr,:,sess) = sub_prob(:,:,tr,sess); %- Probability of groundtruth class (To be used as scrore in ROC)
%label(tr,:,sess) = repmat(Lsub(tr,sess),1,numel(rho(tr,:,sess)));
c = zeros(numel(unique(sub_labels)),1);
c(Lsub(tr,sess)) = 1;
rho(tr,:,:) = sub_prob(:,:,tr,sess); %- Probability of groundtruth class (To be used as scrore in ROC)
label(tr,:,:) = repmat(c,1,size(sub_prob,2));
end
rho2 = permute(rho,[2 1 3]);
rho3 = rho2(:,:);
label2 = permute(label,[2 1 3]);
label3 = label2(:,:);
rho4 = [rho4 rho3];
label4 = [label4 label3];
end
end
plotroc(label4, rho4);
[tpr,fpr,thresholds] = roc(label4, rho4);
chance = [0 1];
figure,
plot([0 1], chance,'--r','LineWidth', 1, 'DisplayName', 'Random guess');
legend('-DynamicLegend');
hold all
marker = ['h','p','s','d'];
color = ['b','g','r','c'];
legends = {'Resting class', '13Hz class', '21Hz class', '17Hz class'};
for i = 1:numel(unique(Labels))
plot([fpr{i} 1], [tpr{i} 1], color(i), 'LineWidth', 2, 'MarkerSize',4, 'DisplayName', legends{i})
%legend('cl')
end
xlabel('FPR or (1-specificity)');
ylabel('TPR or sensitivity');
set(gca,'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
% %% COMPUTE AND PLOT ROC CURVE BASED ON RHO and DELTA
% clear all
% % load classProb
% load('./results/classProbGrad_4class.mat'); NbrSess = subNbrOfSess;
% Labels = Labels+1;
%
% rho4 = [];
% delta4 = [];
% label4 = [];
% for sub = 1:12
% sub_labels = Labels(:,:,1:NbrSess(sub),sub);
% sub_prob = classProb(:,:,:,1:NbrSess(sub),sub);
% sub_grad = classGrad(:,:,:,1:NbrSess(sub),sub);
% Lsub = [];
% rho = [];
% delta = [];
% label = [];
% for sess = 1:NbrSess(sub)
% for tr = 1:8*size(classProb,1)
% Lsub(tr,sess) = sub_labels(tr,1,sess);
% %rho(tr,:,sess) = sub_prob(:,:,tr,sess); %- Probability of groundtruth class (To be used as scrore in ROC)
% %label(tr,:,sess) = repmat(Lsub(tr,sess),1,numel(rho(tr,:,sess)));
%
% c = zeros(numel(unique(sub_labels)),1);
% c(Lsub(tr,sess)) = 1;
% rho(tr,:,:) = sub_prob(:,:,tr,sess); %- Probability of groundtruth class (To be used as scrore in ROC)
% delta(tr,:,:) = sub_grad(:,:,tr,sess); %- gradient of groundtruth class (To be used as scrore in ROC)
% label(tr,:,:) = repmat(c,1,size(sub_prob,2));
% end
% rho2 = permute(rho,[2 1 3]);
% rho3 = rho2(:,:);
% delta2 = permute(delta,[2 1 3]);
% delta3 = delta2(:,:);
% label2 = permute(label,[2 1 3]);
% label3 = label2(:,:);
%
% rho4 = [rho4 rho3];
% delta4 = [delta4 delta3];
% label4 = [label4 label3];
% end
% end
% plotroc(label4, rho4);
% plotroc(label4, delta4);
% [tpr,fpr,thresholds] = roc(label4, rho4);
% [tpr_d,fpr_d,thresholds_d] = roc(label4, delta4);
% chance = [0 1];
% figure,
% plot([0 1], chance,'--r','LineWidth', 1, 'DisplayName', 'Random guess');
% legend('-DynamicLegend');
% hold all
% marker = ['h','p','s','d'];
% color = ['b','g','r','c'];
% legends = {'Resting class', '13Hz class', '21Hz class', '17Hz class'};
% for i = 1:numel(unique(Labels))
% plot([fpr{i} 1], [tpr{i} 1], color(i), 'LineWidth', 2, 'MarkerSize',4, 'DisplayName', legends{i})
% %legend('cl')
% end
% xlabel('FPR or (1-specificity)');
% ylabel('TPR or sensitivity');
% set(gca,'FontSize',14,'fontWeight','normal')
% set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
%
% figure,
% plot([0 1], chance,'--r','LineWidth', 1, 'DisplayName', 'Random guess');
% legend('-DynamicLegend');
% hold all
% marker = ['h','p','s','d'];
% color = ['b','g','r','c'];
% legends = {'Resting class', '13Hz class', '21Hz class', '17Hz class'};
% for i = 1:numel(unique(Labels))
% plot([fpr_d{i} 1], [tpr_d{i} 1], color(i), 'LineWidth', 2, 'MarkerSize',4, 'DisplayName', legends{i})
% %legend('cl')
% end
% xlabel('FPR or (1-specificity)');
% ylabel('TPR or sensitivity');
% set(gca,'FontSize',14,'fontWeight','normal')
% set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')
%% PLOT BARS
Y = [[70.8; 87.3; 87.7], [74.8; 79.1; 79.5]];
figure,
bar(Y)
%xlabel('FPR or (1-specificity)');
ylabel('Average classification accuracy (%)');
set(gca,'FontSize',14,'fontWeight','normal')
set(findall(gcf,'type','text'),'FontSize',14,'fontWeight','normal')