History

add beat p-score evaluation add beat p-score evaluation

Paul Brossier committed 20 years ago

Commit c2f39811 parent e81c0451 file · +58 −1Browse files

Showing the changes to python/aubio (1 of 1 file). Show all

Unified · Split

python/aubio/task/beat.py+58−1
@@ -40,7 +40,7 @@ class taskbeat(taskonset): · 39 unmodified lines
40 period = (60 * self.params.samplerate) / ((now - self.old) * self.params.hopsize)40 period = (60 * self.params.samplerate) / ((now - self.old) * self.params.hopsize)
41 self.old = now41 self.old = now
42 return now*self.btstep*self.params.step,period42 return now*self.btstep*self.params.step,period
43 43
44 def eval(self,results,tol=0.20,tolcontext=0.25):44 def eval(self,results,tol=0.20,tolcontext=0.25):
45 obeats = self.gettruth()45 obeats = self.gettruth()
46 etime = [result[0] for result in results]46 etime = [result[0] for result in results]
@@ -169,7 +169,64 @@ class taskbeat(taskonset): · 122 unmodified lines
169# while freq[i]>freqs[j]:169# while freq[i]>freqs[j]:
170# j += 1170# j += 1
171 171
172 def eval2(self,results,tol=0.2):
173 truth = self.gettruth()
174 obeats = [i[0] for i in truth]
175 ebeats = [i[0]*self.params.step for i in results]
176 NP = max(len(obeats), len(ebeats))
177 N = int(round(max(max(obeats), max(ebeats))*100.)+100)
178 W = int(round(tol*100.*60./median([i[1] for i in truth], len(truth)/2)))
179 ofunc = [0 for i in range(N+W)]
180 efunc = [0 for i in range(N+W)]
181 for i in obeats: ofunc[int(round(i*100.)+W)] = 1
182 for i in ebeats: efunc[int(round(i*100.)+W)] = 1
183 assert len(obeats) == sum(ofunc)
184 autocor = 0; m =0
185 for m in range (-W, W):
186 for i in range(W,N):
187 autocor += ofunc[i] * efunc[i-m]
188 autocor /= float(NP)
189 return autocor
172 190
191 def evaluation(self,results,tol=0.2,start=5.):
192
193 """ beat tracking evaluation function
194
195 computes P-score of experimental results (ebeats)
196 against ground truth annotations (obeats) """
197
198 from aubio.median import short_find as median
199 truth = self.gettruth()
200 ebeats = [i[0]*self.params.step for i in results]
201 obeats = [i[0] for i in truth]
202
203 # trim anything found before start
204 while obeats[0] < start: obeats.pop(0)
205 while ebeats[0] < start: ebeats.pop(0)
206 # maximum number of beats found
207 NP = max(len(obeats), len(ebeats))
208 # length of ofunc and efunc vector
209 N = int(round(max(max(obeats), max(ebeats))*100.)+100)
210 # compute W median of ground truth tempi
211 tempi = []
212 for i in range(1,len(obeats)): tempi.append(obeats[i]-obeats[i-1])
213 W = int(round(tol*100.*median(tempi,len(tempi)/2)))
214 # build ofunc and efunc functions, starting with W zeros
215 ofunc = [0 for i in range(N+W)]
216 efunc = [0 for i in range(N+W)]
217 for i in obeats: ofunc[int(round(i*100.)+W)] = 1
218 for i in ebeats: efunc[int(round(i*100.)+W)] = 1
219 # optional: make sure we didn't miss any beats
220 assert len(obeats) == sum(ofunc)
221 assert len(ebeats) == sum(efunc)
222 # compute auto correlation
223 autocor = 0; m =0
224 for m in range (-W, W):
225 for i in range(W,N):
226 autocor += ofunc[i] * efunc[i-m]
227 autocor /= float(NP)
228 return autocor
229
173 def gettruth(self):230 def gettruth(self):
174 import os.path231 import os.path
175 from aubio.txtfile import read_datafile232 from aubio.txtfile import read_datafile

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