- Timestamp:
- May 22, 2005, 1:50:49 PM (20 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:
- 23a44c1
- Parents:
- edca23f
- Location:
- python
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/aubio/onsetcompare.py
redca23f r9cf2833 28 28 from numarray import * 29 29 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: 40 42 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: 48 49 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 66 76 def notes_roc (la, lb, eps): 67 77 """ creates a matrix of size len(la)*len(lb) then look for hit and miss … … 98 108 99 109 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,0108 missed, bad = 0, 0109 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 += 1116 resbad = add.reduce(teps,axis=1)117 for i in range(m) :118 if resbad[i] == 0:119 bad += 1120 ok = n - missed121 hits = m - bad122 total = n123 return ok,bad,missed,total,hits124 """125 -
python/aubioonset
redca23f r9cf2833 36 36 action="store", dest="outplot", default=None, 37 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 41 (options, args) = parser.parse_args() 39 42 if not len(args): … … 50 53 #onsets = getonsets(filename,threshold,silence,mode=options.mode) 51 54 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
Note: See TracChangeset
for help on using the changeset viewer.