-
Notifications
You must be signed in to change notification settings - Fork 0
/
results_summary_fusion.m
133 lines (99 loc) · 3.61 KB
/
results_summary_fusion.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
close all; clc; clear;
addpath(genpath(pwd))
model_name_all = {'dgdss', 'tiny', 'seq', 'x_joint'};
type_fusion_all = {'', 'pool'}; % '' for standard fusion and 'pool' for integrated fusion
channel_num = 2;
sleepedf_num = 20;
for k = 1:length(model_name_all)
model_name = model_name_all{1,k};
load(['output_',model_name,'.mat'])
for i = 1:length(type_fusion_all)
load([type_fusion_all{i},'res_',num2str(channel_num),'ch_',model_name,'.mat'],"y_true","y_test")
[acc, kappa , f1, sens, spec] = calculate_overall_metrics(y_true, y_test);
acc_lsim(k,i) = acc;
f1_lsim(k,i) = f1;
kappa_lsim(k,i) = kappa;
end
% single channel results
for ch = 1:3
y_test_org = [];
y_true_org = [];
for i = 1:CV_number
response = true_label{ch,i};
response = response(:);
if sum(response==0)>0
response = response+1;
end
this_fold_number = fold_number{1,i};
test_set = this_fold_number==i;
[~,yhat]= max( softmax( hingeloss_traintest{ch,i}(:,test_set)')');
y_test_org = [y_test_org;yhat(:)];
y_true_org = [y_true_org;response(test_set)];
end
[acc, kappa , f1, sens, spec] = calculate_overall_metrics(y_true_org, y_test_org);
acc_single(k,ch) = acc;
f1_single(k,ch) = f1;
kappa_single(k,ch) = kappa;
end
end
%% plot confusion matrix
model_name_all = {'tiny'};
type_fusion_all = {'pool'};
channel_num = 3;
for k = 1:length(model_name_all)
model_name = model_name_all{1,k};
load(['output_',model_name,'.mat'])
for i = 1:length(type_fusion_all)
load([type_fusion_all{i},'res_',num2str(channel_num),'ch_',model_name,'.mat'],"y_true","y_test")
[acc, kappa , f1, sens, spec] = calculate_overall_metrics(y_true, y_test);
end
end
plotconfusion(categorical(y_true),categorical(y_test))
%% plot hypnogram
close all
clear y_test_singles
model_name_all = {'dgdss', 'tiny', 'seq', 'x_joint'};
type_fusion_all = {'pool'};
channel_num = 3;
for k = 1:length(model_name_all)
model_name = model_name_all{1,k};
load(['output_',model_name,'.mat'])
if k==2
load([type_fusion_all{1},'res_',num2str(channel_num),'ch_',model_name,'.mat'],"y_true","y_test")
y_test_model = y_test(1:10000)';
end
% single channel fusion
ch = 1;
y_test_org = [];
y_true_org = [];
for i = 1:CV_number
response = true_label{ch,i};
response = response(:);
if sum(response==0)>0
response = response+1;
end
this_fold_number = fold_number{1,i};
test_set = this_fold_number==i;
[~,yhat]= max( softmax( hingeloss_traintest{ch,i}(:,test_set)')');
y_test_org = [y_test_org;yhat(:)];
y_true_org = [y_true_org;response(test_set)];
end
y_test_org_copy = y_test_org;
if k==1
y_test_org(y_test_org_copy==5)=4;
y_test_org(y_test_org_copy==4)=3;
y_test_org(y_test_org_copy==3)=2;
y_test_org(y_test_org_copy==2)=5;
end
y_test_singles(k,1:10000) = y_test_org(1:10000)';
end
plot(y_test_singles(:,1971:2470)')
hold on
grid on
plot(y_test_model(1971:2470),'b','LineWidth',2.5)
plot(y_true(1971:2470),'m','LineWidth',2)
ylim([0.5,5.5])
legend({'DGDSS','TinySleepNet','SeqSleepNet', 'XSleepNet', 'LSIM fusion', 'True stages'},'FontSize',13,'Interpreter' ,'latex')
set(gca, 'FontWeight','bold','FontSize',11,'Ytick', [1:5],'YTickLabel',{'W','N1','N2','N3','REM'});
xlabel('Samples' ,'FontSize',14,'Interpreter' ,'latex' )
ylabel('Hypnogram' ,'FontSize',14,'Interpreter' ,'latex' )