diff testdata/scripts/matlab/computeNoteLevelAccuracy.m @ 223:51c18a17404a

Move some scripts about, make piano test script produce norm'd ref output as well as non-norm'd test output
author Chris Cannam
date Wed, 16 Jul 2014 13:29:38 +0100
parents testdata/evaluation/computeNoteLevelAccuracy.m@ce64d11ef336
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/scripts/matlab/computeNoteLevelAccuracy.m	Wed Jul 16 13:29:38 2014 +0100
@@ -0,0 +1,48 @@
+function [Pre,Rec,F,Acc,PreOff,RecOff,FOff,AccOff] = computeNoteLevelAccuracy(nmat1,nmat2)
+
+% Compute note-level onset-only and onset-offset accuracy (Bay09)
+
+
+% Initialize
+if (isempty(nmat1)) Pre=0; Rec=0; F=0; Acc=0; return; end;
+
+% Total number of transcribed notes
+Ntot = size(nmat1,1);
+
+% Number of reference notes
+Nref = size(nmat2,1);
+
+% Number of correctly transcribed notes, onset within a +/-50 ms range
+Ncorr = 0;
+NcorrOff = 0;
+for j=1:size(nmat2,1)
+    for i=1:size(nmat1,1)
+        if( (nmat1(i,3) == nmat2(j,3)) && (abs(nmat2(j,1)-nmat1(i,1))<=0.05) )
+            Ncorr = Ncorr+1;
+            
+            % If offset within a +/-50 ms range or within 20% of ground-truth note's duration
+            if abs(nmat2(j,2) - nmat1(i,2)) <= max(0.05, 0.2 * (nmat2(j,2) - nmat2(j,1)))
+               NcorrOff = NcorrOff +1;
+            end;
+            
+            break; % In order to consider duplicates as false alarms
+            
+        end;
+    end;
+end;
+
+% Number of onset-only P-R-F-Acc
+Nfp = Ntot-Ncorr;
+Nfn = Nref-Ncorr;
+Rec = Ncorr/Nref;
+Pre = Ncorr/Ntot;
+F = 2*((Pre*Rec)/(Pre+Rec));
+Acc= Ncorr/(Ncorr+Nfp+Nfn);
+
+% Number of onset-offset P-R-F-Acc
+NfpOff = Ntot-NcorrOff;
+NfnOff = Nref-NcorrOff;
+RecOff = NcorrOff/Nref;
+PreOff = NcorrOff/Ntot;
+FOff = 2*((PreOff*RecOff)/(PreOff+RecOff));
+AccOff= NcorrOff/(NcorrOff+NfpOff+NfnOff);
\ No newline at end of file