History

evaluate doubled detection evaluate doubled detection

Paul Brossier committed 21 years ago

Commit 9cf28331 parent edca23f2 files · +57 −61Browse files

Showing the changes to python (2 of 2 files). Show all

Unified · Split

2 files
  1. python/aubio/onsetcompare.py +44 −60
  2. python/aubioonset +13 −1
python/aubio/onsetcompare.py+44−60
@@ -27,42 +27,52 @@ see http://en.wikipedia.org/wiki/Receiver_operating_characteristic · 26 unmodified lines
2727
2828 from numarray import *
2929
30−def onset_roc(la, lb, eps):
31− """ thanks to nicolas wack for the rewrite"""
32− """ compute differences between two lists """
33− """ feature: scalable to huge lists """
34− n, m = len(la), len(lb)
35− if m == 0 :
36− return 0,0,0,n,0
37− missed, bad = 0, 0
38− # find missed ones first
39− for x in la:
30+def onset_roc(ltru, lexp, eps):
31+ """ compute differences between two lists
32+ orig = hits + missed + merged
33+ expc = hits + bad + doubled
34+ returns orig, missed, merged, expc, bad, doubled
35+ """
36+ orig, expc = len(ltru), len(lexp)
37+ # if lexp is empty
38+ if expc == 0 : return orig,orig,0,0,0,0
39+ missed, bad, doubled, merged = 0, 0, 0, 0
40+ # find missed and doubled ones first
41+ for x in ltru:
4042 correspond = 0
41− for y in lb:
42− if abs(x-y) <= eps:
43− correspond += 1
44− if correspond == 0:
45− missed += 1
46− # then look for bad ones
47− for y in lb:
43+ for y in lexp:
44+ if abs(x-y) <= eps: correspond += 1
45+ if correspond == 0: missed += 1
46+ elif correspond > 1: doubled += correspond - 1
47+ # then look for bad and merged ones
48+ for y in lexp:
4849 correspond = 0
49− for x in la:
50− if abs(x-y) <= eps:
51− correspond += 1
52− if correspond == 0:
53− bad += 1
54− ok = n - missed
55− hits = m - bad
56− # at this point, we must have ok = hits. if not we had
57− # - a case were one onset counted for two labels (ok>hits)
58− # - a case were one labels matched two onsets (hits>ok)
59− # bad hack for now (fails if both above cases have happened):
60− if ok > hits: bad += ok-hits; ok = hits
61− if hits > ok: missed += hits-ok; hits = ok
62− total = n
63− return ok,bad,missed,total,hits
64−
65−
50+ for x in ltru:
51+ if abs(x-y) <= eps: correspond += 1
52+ if correspond == 0: bad += 1
53+ elif correspond > 1: merged += correspond - 1
54+ # check consistancy of the results
55+ assert ( orig - missed - merged == expc - bad - doubled)
56+ return orig, missed, merged, expc, bad, doubled
57+
58+def onset_diffs(ltru, lexp, eps):
59+ """ compute differences between two lists
60+ orig = hits + missed + merged
61+ expc = hits + bad + doubled
62+ returns orig, missed, merged, expc, bad, doubled
63+ """
64+ orig, expc = len(ltru), len(lexp)
65+ # if lexp is empty
66+ l = []
67+ if expc == 0 : return l
68+ # find missed and doubled ones first
69+ for x in ltru:
70+ correspond = 0
71+ for y in lexp:
72+ if abs(x-y) <= eps: l.append(y-x)
73+ # return list of diffs
74+ return l
75+
6676 def notes_roc (la, lb, eps):
6777 """ creates a matrix of size len(la)*len(lb) then look for hit and miss
6878 in it within eps tolerance windows """
@@ -97,29 +107,3 @@ def load_onsets(filename) : · 28 unmodified lines
97107 l.append(float(line[0]))
98108
99109 return l
100−
101−"""
102−def onset_roc (la, lb, eps):
103− \"\"\" build a matrix of all possible differences between two lists \"\"\"
104− \"\"\" bug: not scalable to huge lists \"\"\"
105− n, m = len(la), len(lb)
106− if m ==0 :
107− return 0,0,0,n,0
108− missed, bad = 0, 0
109− x = resize(la[:],(m,n))
110− y = transpose(resize(lb[:],(n,m)))
111− teps = (abs(x-y) <= eps)
112− resmis = add.reduce(teps,axis = 0)
113− for i in range(n) :
114− if resmis[i] == 0:
115− missed += 1
116− resbad = add.reduce(teps,axis=1)
117− for i in range(m) :
118− if resbad[i] == 0:
119− bad += 1
120− ok = n - missed
121− hits = m - bad
122− total = n
123− return ok,bad,missed,total,hits
124−"""
125−
python/aubioonset+13−1
@@ -35,6 +35,9 @@ def parse_args(): · 34 unmodified lines
3535 parser.add_option("-o","--outplot",
3636 action="store", dest="outplot", default=None,
3737 help="be quiet [default=None]")
38+ parser.add_option("-M","--mintol",
39+ action="store", dest="mintol", default=-70,
40+ help="mintol [default=0.48]")
3841 (options, args) = parser.parse_args()
3942 if not len(args):
4043 print "no file name given\n", usage
@@ -49,4 +52,13 @@ silence = float(options.silence) · 8 unmodified lines
4952
5053 #onsets = getonsets(filename,threshold,silence,mode=options.mode)
5154 onsets = getonsetscausal(filename,threshold,silence,mode=options.mode)
52−for i in onsets: print i*512./44100.
55+
56+# print all
57+#for i in onsets: print i*512./44100.
58+# prune doubled
59+last = -10.
60+mintol = float(options.mintol)
61+for i in onsets:
62+ new = i*512./44100.
63+ if (new - last > mintol): print "%f" % new
64+ last = new

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t