Mercurial > hg > silvet
comparison testdata/scripts/evaluate_lab.yeti @ 267:a8c05709e486
Merge from branch "norm"
author | Chris Cannam |
---|---|
date | Wed, 23 Jul 2014 17:51:58 +0100 |
parents | 7cb021e40732 |
children |
comparison
equal
deleted
inserted
replaced
250:ec296f783a6f | 267:a8c05709e486 |
---|---|
1 | |
2 // Take two lab files of the form | |
3 // | |
4 // onset offset frequency | |
5 // | |
6 // and report their onset-only note-level accuracy F-measure. | |
7 | |
8 program evaluate_lab; | |
9 | |
10 usage () = | |
11 (eprintln "\nUsage: evaluate_lab reqd reference.lab transcribed.lab\n"; | |
12 eprintln "where reqd is the number of milliseconds allowed for timing error (+/-)\n"); | |
13 | |
14 toMIDIPitch f = | |
15 round (12 * (Math#log(f / 220) / Math#log(2)) + 57); | |
16 | |
17 suck f = | |
18 (str = openInFile f "UTF-8"; // better to use readFile here, oh well | |
19 d = map do line: | |
20 case list (strSplit "\t" line) of | |
21 onset::offset::frequency::_: | |
22 { onset = number onset, midi = toMIDIPitch (number frequency) }; | |
23 _: | |
24 failWith "badly formed line: \(line)"; | |
25 esac; | |
26 done (str.lines ()); | |
27 str.close (); | |
28 d); | |
29 | |
30 select f = fold do r x: if f x then x::r else r fi done []; | |
31 | |
32 evaluate permitted ref trans = | |
33 (reference = suck ref; | |
34 transcribed = suck trans; | |
35 accurate = | |
36 select do here : | |
37 any do other: | |
38 here.midi == other.midi and | |
39 abs (here.onset - other.onset) < permitted | |
40 done reference | |
41 done transcribed; | |
42 { | |
43 ntot = length transcribed, | |
44 nref = length reference, | |
45 ncorr = length accurate, | |
46 }); | |
47 | |
48 pc n = | |
49 int (n * 1000) / 10; | |
50 | |
51 report { ntot, nref, ncorr } = | |
52 (nfp = ntot - ncorr; | |
53 nfn = nref - ncorr; | |
54 if nref == 0 then | |
55 println "ERROR: no events in reference!" | |
56 elif ntot == 0 then | |
57 println "WARNING: no events transcribed!" | |
58 else | |
59 rec = ncorr / nref; | |
60 pre = ncorr / ntot; | |
61 f = if pre + rec == 0 then 0 else 2 * ((pre * rec) / (pre + rec)) fi; | |
62 acc = ncorr / (ncorr + nfp + nfn); | |
63 println "precision \(pc pre), recall \(pc rec), accuracy \(pc acc), F \(pc f)"; | |
64 fi); | |
65 | |
66 case (list _argv) of | |
67 reqd::ref::trans::[]: report (evaluate (number reqd / 1000) ref trans); | |
68 _: usage (); | |
69 esac; | |
70 |