comparison functions/challange/eventDetectionMetrics_classWiseEventBased.m @ 0:2fadb31a9d55 tip

Import code by Vuegen et al
author Dan Stowell <dan.stowell@elec.qmul.ac.uk>
date Fri, 11 Oct 2013 12:02:43 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:2fadb31a9d55
1 function [results] = eventDetectionMetrics_classWiseEventBased(outputFile,GTFile)
2
3 % Class-wise event-based evaluation for event detection task
4 % outputFile: the output of the event detection system
5 % GTFile: the ground truth list of events
6
7 % Initialize
8 eventID = {'alert','clearthroat','cough','doorslam','drawer','keyboard','keys',...
9 'knock','laughter','mouse','pageturn','pendrop','phone','printer','speech','switch'};
10
11
12 % Load event list from output and ground-truth
13 [onset,offset,classNames] = loadEventsList(outputFile);
14 [onsetGT,offsetGT,classNamesGT] = loadEventsList(GTFile);
15
16
17 % Total number of detected and reference events per class
18 Ntot = zeros(16,1);
19 for i=1:length(onset)
20 pos = strmatch(classNames{i}, eventID);
21 Ntot(pos) = Ntot(pos)+1;
22 end;
23
24 Nref = zeros(16,1);
25 for i=1:length(onsetGT)
26 pos = strmatch(classNamesGT{i}, eventID);
27 Nref(pos) = Nref(pos)+1;
28 end;
29 I = find(Nref>0); % index for classes present in ground-truth
30
31
32 % Number of correctly transcribed events per class, onset within a +/-100 ms range
33 Ncorr = zeros(16,1);
34 NcorrOff = zeros(16,1);
35 for j=1:length(onsetGT)
36 for i=1:length(onset)
37
38 if( strcmp(classNames{i},classNamesGT{j}) && (abs(onsetGT(j)-onset(i))<=0.1) )
39 pos = strmatch(classNames{i}, eventID);
40 Ncorr(pos) = Ncorr(pos)+1;
41
42 % If offset within a +/-100 ms range or within 50% of ground-truth event's duration
43 if abs(offsetGT(j) - offset(i)) <= max(0.1, 0.5 * (offsetGT(j) - onsetGT(j)))
44 pos = strmatch(classNames{i}, eventID);
45 NcorrOff(pos) = NcorrOff(pos) +1;
46 end;
47
48 break; % In order to not evaluate duplicates
49
50 end;
51 end;
52 end;
53
54
55 % Compute onset-only class-wise event-based metrics
56 Nfp = Ntot-Ncorr;
57 Nfn = Nref-Ncorr;
58 Nsubs = min(Nfp,Nfn);
59 tempRec = Ncorr(I)./(Nref(I)+eps);
60 tempPre = Ncorr(I)./(Ntot(I)+eps);
61 results.Rec = mean(tempRec);
62 results.Pre = mean(tempPre);
63 tempF = 2*((tempPre.*tempRec)./(tempPre+tempRec+eps));
64 results.F = mean(tempF);
65 tempAEER = (Nfn(I)+Nfp(I)+Nsubs(I))./(Nref(I)+eps);
66 results.AEER = mean(tempAEER);
67
68
69 % Compute onset-offset class-wise event-based metrics
70 NfpOff = Ntot-NcorrOff;
71 NfnOff = Nref-NcorrOff;
72 NsubsOff = min(NfpOff,NfnOff);
73 tempRecOff = NcorrOff(I)./(Nref(I)+eps);
74 tempPreOff = NcorrOff(I)./(Ntot(I)+eps);
75 results.RecOff = mean(tempRecOff);
76 results.PreOff = mean(tempPreOff);
77 tempFOff = 2*((tempPreOff.*tempRecOff)./(tempPreOff+tempRecOff+eps));
78 results.FOff = mean(tempFOff);
79 tempAEEROff = (NfnOff(I)+NfpOff(I)+NsubsOff(I))./(Nref(I)+eps);
80 results.AEEROff = mean(tempAEEROff);