Changeset c2f3981 for python/aubio/task/beat.py
- Timestamp:
- Sep 5, 2006, 6:33:28 PM (18 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 5ce98d8
- Parents:
- e81c045
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/aubio/task/beat.py
re81c045 rc2f3981 41 41 self.old = now 42 42 return now*self.btstep*self.params.step,period 43 43 44 44 def eval(self,results,tol=0.20,tolcontext=0.25): 45 45 obeats = self.gettruth() … … 170 170 # 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 230 def gettruth(self): 174 231 import os.path
Note: See TracChangeset
for help on using the changeset viewer.