-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfscore.m
More file actions
39 lines (35 loc) · 1.26 KB
/
fscore.m
File metadata and controls
39 lines (35 loc) · 1.26 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
function [score, rec] = fscore(trueNotes, guessNotes, option)
% given true notes and guessed notes, compute f score
% count number of correctly labelled instrument-notes
if option == 0 % instrument-notes
elseif option == 1 % instruments
for i = 1:length(trueNotes)
noteStart = regexp(trueNotes{i}, '[ABCDEFG]S?[0123456789]');
trueNotes{i} = trueNotes{i}(1:(noteStart - 1));
end
for i = 1:length(guessNotes)
noteStart = regexp(guessNotes{i}, '[ABCDEFG]S?[0123456789]');
guessNotes{i} = guessNotes{i}(1:(noteStart - 1));
end
else % notes
for i = 1:length(trueNotes)
noteStart = regexp(trueNotes{i}, '[ABCDEFG]S?[0123456789]');
trueNotes{i} = trueNotes{i}(noteStart:length(trueNotes{i}));
end
for i = 1:length(guessNotes)
noteStart = regexp(guessNotes{i}, '[ABCDEFG]S?[0123456789]');
guessNotes{i} = guessNotes{i}(noteStart:length(guessNotes{i}));
end
end
trueNotes = unique(trueNotes);
guessNotes = unique(guessNotes);
numCorrect = sum(ismember(trueNotes, guessNotes));
% calculate fscore
prec = numCorrect / length(guessNotes);
rec = numCorrect / length(trueNotes);
if ((prec == 0) && (rec == 0)) || isempty(guessNotes)
score = 0;
else
score = 2 * prec * rec / (prec + rec);
end
end