annotate event_detection/eventDetectionMetrics_classWiseEventBased.m @ 10:507300d2ed66 tip

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