changeset 233:7cb021e40732 norm

Move evaluate_lab script to scripts/
author Chris Cannam
date Wed, 16 Jul 2014 18:35:07 +0100
parents aec03b944a5e
children 8aa810eeff40
files testdata/evaluation/evaluate_lab.yeti testdata/evaluation/run-piano.sh testdata/evaluation/run-singleinstrumenttest.sh testdata/evaluation/run.sh testdata/scripts/evaluate_lab.yeti
diffstat 5 files changed, 77 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/testdata/evaluation/evaluate_lab.yeti	Wed Jul 16 18:26:48 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,70 +0,0 @@
-
-// Take two lab files of the form
-//
-// onset offset frequency
-//
-// and report their onset-only note-level accuracy F-measure.
-
-program evaluate_lab;
-
-usage () =
-   (eprintln "\nUsage: evaluate_lab reqd reference.lab transcribed.lab\n";
-    eprintln "where reqd is the number of milliseconds allowed for timing error (+/-)\n");
-
-toMIDIPitch f = 
-    round (12 * (Math#log(f / 220) / Math#log(2)) + 57);
-
-suck f =
-   (str = openInFile f "UTF-8"; // better to use readFile here, oh well
-    d = map do line:
-        case list (strSplit "\t" line) of
-        onset::offset::frequency::_:
-            { onset = number onset, midi = toMIDIPitch (number frequency) };
-        _:
-            failWith "badly formed line: \(line)";
-        esac;
-    done (str.lines ());
-    str.close ();
-    d);
-
-select f = fold do r x: if f x then x::r else r fi done [];
-
-evaluate permitted ref trans =
-   (reference = suck ref;
-    transcribed = suck trans;
-    accurate = 
-        select do here :
-            any do other:
-                here.midi == other.midi and
-                    abs (here.onset - other.onset) < permitted
-            done reference
-        done transcribed;
-    {
-        ntot = length transcribed,
-        nref = length reference,
-        ncorr = length accurate,
-    });
-
-pc n =
-    int (n * 1000) / 10;
-
-report { ntot, nref, ncorr } =
-   (nfp = ntot - ncorr;
-    nfn = nref - ncorr;
-    if nref == 0 then
-        println "ERROR: no events in reference!"
-    elif ntot == 0 then
-        println "WARNING: no events transcribed!"
-    else
-        rec = ncorr / nref;
-        pre = ncorr / ntot;
-        f = if pre + rec == 0 then 0 else 2 * ((pre * rec) / (pre + rec)) fi;
-        acc = ncorr / (ncorr + nfp + nfn);
-        println "precision \(pc pre), recall \(pc rec), accuracy \(pc acc), F \(pc f)";
-    fi);
-
-case (list _argv) of
-reqd::ref::trans::[]: report (evaluate (number reqd / 1000) ref trans);
-_: usage ();
-esac;
-
--- a/testdata/evaluation/run-piano.sh	Wed Jul 16 18:26:48 2014 +0100
+++ b/testdata/evaluation/run-piano.sh	Wed Jul 16 18:35:07 2014 +0100
@@ -110,7 +110,7 @@
 		echo
 		echo "Validating against ground truth at $ms ms:"
 		egrep '(^[0-9]\.)|(^[012][0-9]\.)' "../piano-groundtruth/$filename.lab" > "$reference.lab"
-		"$yc" ./evaluate_lab.yeti "$ms" "$reference.lab" "$outfile.lab" | sed 's,$,'"$mark"','
+		"$yc" ../scripts/evaluate_lab.yeti "$ms" "$reference.lab" "$outfile.lab" | sed 's,$,'"$mark"','
 		cp "$reference.lab" /tmp/reference.lab
 		cp "$outfile.lab" /tmp/detected.lab
 	    done;
--- a/testdata/evaluation/run-singleinstrumenttest.sh	Wed Jul 16 18:26:48 2014 +0100
+++ b/testdata/evaluation/run-singleinstrumenttest.sh	Wed Jul 16 18:35:07 2014 +0100
@@ -111,13 +111,13 @@
 	    if [ "$ms" = "50" ]; then mark="  <-- main $piece/$arrangement"; fi;
 	    echo
 	    echo "Validating against ground truth at $ms ms:"
-	    "$yc" ./evaluate_lab.yeti "$ms" "../TRIOS-groundtruth/$piece/$arrangement.lab" "$outfile.lab" | sed 's,$,'"$mark"','
+	    "$yc" ../scripts/evaluate_lab.yeti "$ms" "../TRIOS-groundtruth/$piece/$arrangement.lab" "$outfile.lab" | sed 's,$,'"$mark"','
 	    echo
 	    echo "Validating against MIREX submission at $ms ms:"
-	    "$yc" ./evaluate_lab.yeti "$ms" "../TRIOS-mirex2012-matlab/$piece/$arrangement.lab" "$outfile.lab"
+	    "$yc" ../scripts/evaluate_lab.yeti "$ms" "../TRIOS-mirex2012-matlab/$piece/$arrangement.lab" "$outfile.lab"
 	    echo
 	    echo "Validating MIREX against ground truth at $ms ms":
-	    "$yc" ./evaluate_lab.yeti "$ms" "../TRIOS-groundtruth/$piece/$arrangement.lab" "../TRIOS-mirex2012-matlab/$piece/$arrangement.lab"
+	    "$yc" ../scripts/evaluate_lab.yeti "$ms" "../TRIOS-groundtruth/$piece/$arrangement.lab" "../TRIOS-mirex2012-matlab/$piece/$arrangement.lab"
 	done;
 
 	echo
--- a/testdata/evaluation/run.sh	Wed Jul 16 18:26:48 2014 +0100
+++ b/testdata/evaluation/run.sh	Wed Jul 16 18:35:07 2014 +0100
@@ -107,13 +107,13 @@
 	if [ "$ms" = "50" ]; then mark="  <-- main $piece/$arrangement"; fi;
 	echo
 	echo "Validating against ground truth at $ms ms:"
-	"$yc" ./evaluate_lab.yeti "$ms" "../TRIOS-groundtruth/$piece/$arrangement.lab" "$outfile.lab" | sed 's,$,'"$mark"','
+	"$yc" ../scripts/evaluate_lab.yeti "$ms" "../TRIOS-groundtruth/$piece/$arrangement.lab" "$outfile.lab" | sed 's,$,'"$mark"','
 	echo
 	echo "Validating against MIREX submission at $ms ms:"
-	"$yc" ./evaluate_lab.yeti "$ms" "../TRIOS-mirex2012-matlab/$piece/$arrangement.lab" "$outfile.lab"
+	"$yc" ../scripts/evaluate_lab.yeti "$ms" "../TRIOS-mirex2012-matlab/$piece/$arrangement.lab" "$outfile.lab"
 	echo
 	echo "Validating MIREX against ground truth at $ms ms":
-	"$yc" ./evaluate_lab.yeti "$ms" "../TRIOS-groundtruth/$piece/$arrangement.lab" "../TRIOS-mirex2012-matlab/$piece/$arrangement.lab"
+	"$yc" ../scripts/evaluate_lab.yeti "$ms" "../TRIOS-groundtruth/$piece/$arrangement.lab" "../TRIOS-mirex2012-matlab/$piece/$arrangement.lab"
     done;
 
     echo
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/scripts/evaluate_lab.yeti	Wed Jul 16 18:35:07 2014 +0100
@@ -0,0 +1,70 @@
+
+// Take two lab files of the form
+//
+// onset offset frequency
+//
+// and report their onset-only note-level accuracy F-measure.
+
+program evaluate_lab;
+
+usage () =
+   (eprintln "\nUsage: evaluate_lab reqd reference.lab transcribed.lab\n";
+    eprintln "where reqd is the number of milliseconds allowed for timing error (+/-)\n");
+
+toMIDIPitch f = 
+    round (12 * (Math#log(f / 220) / Math#log(2)) + 57);
+
+suck f =
+   (str = openInFile f "UTF-8"; // better to use readFile here, oh well
+    d = map do line:
+        case list (strSplit "\t" line) of
+        onset::offset::frequency::_:
+            { onset = number onset, midi = toMIDIPitch (number frequency) };
+        _:
+            failWith "badly formed line: \(line)";
+        esac;
+    done (str.lines ());
+    str.close ();
+    d);
+
+select f = fold do r x: if f x then x::r else r fi done [];
+
+evaluate permitted ref trans =
+   (reference = suck ref;
+    transcribed = suck trans;
+    accurate = 
+        select do here :
+            any do other:
+                here.midi == other.midi and
+                    abs (here.onset - other.onset) < permitted
+            done reference
+        done transcribed;
+    {
+        ntot = length transcribed,
+        nref = length reference,
+        ncorr = length accurate,
+    });
+
+pc n =
+    int (n * 1000) / 10;
+
+report { ntot, nref, ncorr } =
+   (nfp = ntot - ncorr;
+    nfn = nref - ncorr;
+    if nref == 0 then
+        println "ERROR: no events in reference!"
+    elif ntot == 0 then
+        println "WARNING: no events transcribed!"
+    else
+        rec = ncorr / nref;
+        pre = ncorr / ntot;
+        f = if pre + rec == 0 then 0 else 2 * ((pre * rec) / (pre + rec)) fi;
+        acc = ncorr / (ncorr + nfp + nfn);
+        println "precision \(pc pre), recall \(pc rec), accuracy \(pc acc), F \(pc f)";
+    fi);
+
+case (list _argv) of
+reqd::ref::trans::[]: report (evaluate (number reqd / 1000) ref trans);
+_: usage ();
+esac;
+