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
27 27
28from numarray import *28from numarray import *
29 29
30def onset_roc(la, lb, eps):30def onset_roc(ltru, lexp, eps):
31 """ thanks to nicolas wack for the rewrite"""31 """ compute differences between two lists
32 """ compute differences between two lists """32 orig = hits + missed + merged
33 """ feature: scalable to huge lists """33 expc = hits + bad + doubled
34 n, m = len(la), len(lb)34 returns orig, missed, merged, expc, bad, doubled
35 if m == 0 :35 """
36 return 0,0,0,n,036 orig, expc = len(ltru), len(lexp)
37 missed, bad = 0, 037 # if lexp is empty
38 # find missed ones first38 if expc == 0 : return orig,orig,0,0,0,0
39 for x in la:39 missed, bad, doubled, merged = 0, 0, 0, 0
40 # find missed and doubled ones first
41 for x in ltru:
40 correspond = 042 correspond = 0
41 for y in lb:43 for y in lexp:
42 if abs(x-y) <= eps:44 if abs(x-y) <= eps: correspond += 1
43 correspond += 145 if correspond == 0: missed += 1
44 if correspond == 0:46 elif correspond > 1: doubled += correspond - 1
45 missed += 147 # then look for bad and merged ones
46 # then look for bad ones48 for y in lexp:
47 for y in lb:
48 correspond = 049 correspond = 0
49 for x in la:50 for x in ltru:
50 if abs(x-y) <= eps:51 if abs(x-y) <= eps: correspond += 1
51 correspond += 152 if correspond == 0: bad += 1
52 if correspond == 0:53 elif correspond > 1: merged += correspond - 1
53 bad += 154 # check consistancy of the results
54 ok = n - missed55 assert ( orig - missed - merged == expc - bad - doubled)
55 hits = m - bad56 return orig, missed, merged, expc, bad, doubled
56 # at this point, we must have ok = hits. if not we had57
57 # - a case were one onset counted for two labels (ok>hits)58def onset_diffs(ltru, lexp, eps):
58 # - a case were one labels matched two onsets (hits>ok)59 """ compute differences between two lists
59 # bad hack for now (fails if both above cases have happened):60 orig = hits + missed + merged
60 if ok > hits: bad += ok-hits; ok = hits61 expc = hits + bad + doubled
61 if hits > ok: missed += hits-ok; hits = ok62 returns orig, missed, merged, expc, bad, doubled
62 total = n63 """
63 return ok,bad,missed,total,hits64 orig, expc = len(ltru), len(lexp)
64 65 # if lexp is empty
65 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
66def notes_roc (la, lb, eps):76def notes_roc (la, lb, eps):
67 """ creates a matrix of size len(la)*len(lb) then look for hit and miss77 """ creates a matrix of size len(la)*len(lb) then look for hit and miss
68 in it within eps tolerance windows """78 in it within eps tolerance windows """
@@ -97,29 +107,3 @@ def load_onsets(filename) : · 28 unmodified lines
97 l.append(float(line[0]))107 l.append(float(line[0]))
98 108
99 return l109 return l
100
101"""
102def 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
35 parser.add_option("-o","--outplot",35 parser.add_option("-o","--outplot",
36 action="store", dest="outplot", default=None, 36 action="store", dest="outplot", default=None,
37 help="be quiet [default=None]")37 help="be quiet [default=None]")
38 parser.add_option("-M","--mintol",
39 action="store", dest="mintol", default=-70,
40 help="mintol [default=0.48]")
38 (options, args) = parser.parse_args()41 (options, args) = parser.parse_args()
39 if not len(args): 42 if not len(args):
40 print "no file name given\n", usage43 print "no file name given\n", usage
@@ -49,4 +52,13 @@ silence = float(options.silence) · 8 unmodified lines
49 52
50#onsets = getonsets(filename,threshold,silence,mode=options.mode)53#onsets = getonsets(filename,threshold,silence,mode=options.mode)
51onsets = getonsetscausal(filename,threshold,silence,mode=options.mode)54onsets = getonsetscausal(filename,threshold,silence,mode=options.mode)
52for i in onsets: print i*512./44100.55
56# print all
57#for i in onsets: print i*512./44100.
58# prune doubled
59last = -10.
60mintol = float(options.mintol)
61for 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