-
Notifications
You must be signed in to change notification settings - Fork 8
/
score2017Challenge.m
125 lines (112 loc) · 3.63 KB
/
score2017Challenge.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
% This script will score your algorithm for classification accuracy, based on the reference classification results.
% Your final score for the challenge will be evaluated on the whole hidden test set.
%
% This script requires that you first run generateValidationSet.m
%
%
% Written by: Chengyu Liu and Qiao Li January 20 2017
%
% Last modified by:
%
%
clear all;
%% Load the answer classification results
fid = fopen('answers.txt','r');
if(fid ~= -1)
ANSWERS = textscan(fid, '%s %s','Delimiter',',');
else
error('Could not open users answer.txt for scoring. Run the generateValidationSet.m script and try again.')
end
fclose(fid);
%% Load the reference classification results
reffile = ['validation' filesep 'REFERENCE.csv'];
fid = fopen(reffile, 'r');
if(fid ~= -1)
Ref = textscan(fid,'%s %s','Delimiter',',');
else
error(['Could not open ' reffile ' for scoring. Exiting...'])
end
fclose(fid);
RECORDS = Ref{1};
target = Ref{2};
N = length(RECORDS);
a = find(strcmp(ANSWERS{2},'N'));
b = find(strcmp(ANSWERS{2},'A'));
c = find(strcmp(ANSWERS{2},'O'));
d = find(strcmp(ANSWERS{2},'~'));
ln = length(a)+length(b)+length(c)+length(d);
if(length(ANSWERS{2}) ~= ln);
error('Input must contain only N, A, O or ~');
end
%% Scoring
% We do not assume that the references and the answers are sorted in the
% same order, so we search for the location of the individual records in answer.txt file.
AA=zeros(4,4);
for n = 1:N
rec = RECORDS{n};
i = strmatch(rec, ANSWERS{1});
if(isempty(i))
warning(['Could not find answer for record ' rec '; treating it as NOISE (~).']);
this_answer = '~';
else
this_answer = ANSWERS{2}(i);
end
switch target{n}
case 'N'
if strcmp(this_answer,'N')
AA(1,1) = AA(1,1)+1;
elseif strcmp(this_answer,'A')
AA(1,2) = AA(1,2)+1;
elseif strcmp(this_answer,'O')
AA(1,3) = AA(1,3)+1;
elseif strcmp(this_answer,'~')
AA(1,4) = AA(1,4)+1;
end
case 'A'
if strcmp(this_answer,'N')
AA(2,1) = AA(2,1)+1;
elseif strcmp(this_answer,'A')
AA(2,2) = AA(2,2)+1;
elseif strcmp(this_answer,'O')
AA(2,3) = AA(2,3)+1;
elseif strcmp(this_answer,'~')
AA(2,4) = AA(2,4)+1;
end
case 'O'
if strcmp(this_answer,'N')
AA(3,1) = AA(3,1)+1;
elseif strcmp(this_answer,'A')
AA(3,2) = AA(3,2)+1;
elseif strcmp(this_answer,'O')
AA(3,3) = AA(3,3)+1;
elseif strcmp(this_answer,'~')
AA(3,4) = AA(3,4)+1;
end
case '~'
if strcmp(this_answer,'N')
AA(4,1) = AA(4,1)+1;
elseif strcmp(this_answer,'A')
AA(4,2) = AA(4,2)+1;
elseif strcmp(this_answer,'O')
AA(4,3) = AA(4,3)+1;
elseif strcmp(this_answer,'~')
AA(4,4) = AA(4,4)+1;
end
end
end
F1n=2*AA(1,1)/(sum(AA(1,:))+sum(AA(:,1)));
F1a=2*AA(2,2)/(sum(AA(2,:))+sum(AA(:,2)));
F1o=2*AA(3,3)/(sum(AA(3,:))+sum(AA(:,3)));
F1p=2*AA(4,4)/(sum(AA(4,:))+sum(AA(:,4)));
F1=(F1n+F1a+F1o)/3;
str = ['F1 measure for Normal rhythm: ' '%1.4f\n'];
fprintf(str,F1n)
str = ['F1 measure for AF rhythm: ' '%1.4f\n'];
fprintf(str,F1a)
str = ['F1 measure for Other rhythm: ' '%1.4f\n'];
fprintf(str,F1o)
str = ['F1 measure for Noisy recordings: ' '%1.4f\n'];
fprintf(str,F1p)
str = ['Final F1 measure: ' '%1.4f\n'];
fprintf(str,F1)