emmanouil@0: function [results] = eventDetectionMetrics_classWiseEventBased(outputFile,GTFile) emmanouil@0: emmanouil@0: % Class-wise event-based evaluation for event detection task emmanouil@0: % outputFile: the output of the event detection system emmanouil@0: % GTFile: the ground truth list of events emmanouil@0: emmanouil@0: % Initialize emmanouil@0: eventID = {'alert','clearthroat','cough','doorslam','drawer','keyboard','keys',... emmanouil@0: 'knock','laughter','mouse','pageturn','pendrop','phone','printer','speech','switch'}; emmanouil@0: emmanouil@0: emmanouil@0: % Load event list from output and ground-truth emmanouil@0: [onset,offset,classNames] = loadEventsList(outputFile); emmanouil@0: [onsetGT,offsetGT,classNamesGT] = loadEventsList(GTFile); emmanouil@0: emmanouil@0: emmanouil@0: % Total number of detected and reference events per class emmanouil@0: Ntot = zeros(16,1); emmanouil@0: for i=1:length(onset) emmanouil@0: pos = strmatch(classNames{i}, eventID); emmanouil@0: Ntot(pos) = Ntot(pos)+1; emmanouil@0: end; emmanouil@0: emmanouil@0: Nref = zeros(16,1); emmanouil@0: for i=1:length(onsetGT) emmanouil@0: pos = strmatch(classNamesGT{i}, eventID); emmanouil@0: Nref(pos) = Nref(pos)+1; emmanouil@0: end; emmanouil@0: I = find(Nref>0); % index for classes present in ground-truth emmanouil@0: emmanouil@0: emmanouil@0: % Number of correctly transcribed events per class, onset within a +/-100 ms range emmanouil@0: Ncorr = zeros(16,1); emmanouil@0: NcorrOff = zeros(16,1); emmanouil@0: for j=1:length(onsetGT) emmanouil@0: for i=1:length(onset) emmanouil@0: emmanouil@0: if( strcmp(classNames{i},classNamesGT{j}) && (abs(onsetGT(j)-onset(i))<=0.1) ) emmanouil@0: pos = strmatch(classNames{i}, eventID); emmanouil@0: Ncorr(pos) = Ncorr(pos)+1; emmanouil@0: emmanouil@0: % If offset within a +/-100 ms range or within 50% of ground-truth event's duration emmanouil@0: if abs(offsetGT(j) - offset(i)) <= max(0.1, 0.5 * (offsetGT(j) - onsetGT(j))) emmanouil@0: pos = strmatch(classNames{i}, eventID); emmanouil@0: NcorrOff(pos) = NcorrOff(pos) +1; emmanouil@0: end; emmanouil@0: emmanouil@0: break; % In order to not evaluate duplicates emmanouil@0: emmanouil@0: end; emmanouil@0: end; emmanouil@0: end; emmanouil@0: emmanouil@0: emmanouil@0: % Compute onset-only class-wise event-based metrics emmanouil@0: Nfp = Ntot-Ncorr; emmanouil@0: Nfn = Nref-Ncorr; emmanouil@0: Nsubs = min(Nfp,Nfn); emmanouil@0: tempRec = Ncorr(I)./(Nref(I)+eps); emmanouil@0: tempPre = Ncorr(I)./(Ntot(I)+eps); emmanouil@0: results.Rec = mean(tempRec); emmanouil@0: results.Pre = mean(tempPre); emmanouil@0: tempF = 2*((tempPre.*tempRec)./(tempPre+tempRec+eps)); emmanouil@0: results.F = mean(tempF); emmanouil@0: tempAEER = (Nfn(I)+Nfp(I)+Nsubs(I))./(Nref(I)+eps); emmanouil@0: results.AEER = mean(tempAEER); emmanouil@0: emmanouil@0: emmanouil@0: % Compute onset-offset class-wise event-based metrics emmanouil@0: NfpOff = Ntot-NcorrOff; emmanouil@0: NfnOff = Nref-NcorrOff; emmanouil@0: NsubsOff = min(NfpOff,NfnOff); emmanouil@0: tempRecOff = NcorrOff(I)./(Nref(I)+eps); emmanouil@0: tempPreOff = NcorrOff(I)./(Ntot(I)+eps); emmanouil@0: results.RecOff = mean(tempRecOff); emmanouil@0: results.PreOff = mean(tempPreOff); emmanouil@0: tempFOff = 2*((tempPreOff.*tempRecOff)./(tempPreOff+tempRecOff+eps)); emmanouil@0: results.FOff = mean(tempFOff); emmanouil@0: tempAEEROff = (NfnOff(I)+NfpOff(I)+NsubsOff(I))./(Nref(I)+eps); emmanouil@0: results.AEEROff = mean(tempAEEROff);