History

merge some benchonset code into node merge some benchonset code into node

Paul Brossier committed 20 years ago

Commit c912c671 parent e9689392 files · +74 −95Browse files

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

Unified · Split

2 files
  1. python/aubio/bench/node.py +48 −6
  2. python/test/bench/onset/bench-onset +26 −89
python/aubio/bench/node.py+48−6
@@ -143,20 +143,62 @@ class bench: · 142 unmodified lines
143143 print "Creating results directory"
144144 act_on_results(mkdir,self.datadir,self.resdir,filter='d')
145145
146− def pretty_print(self,values,sep='|'):
147− for i in range(len(values)):
148− print self.formats[i] % values[i], sep,
146+ def pretty_print(self,sep='|'):
147+ for i in self.printnames:
148+ print self.formats[i] % self.v[i], sep,
149+ print
150+
151+ def pretty_titles(self,sep='|'):
152+ for i in self.printnames:
153+ print self.formats[i] % i, sep,
149154 print
150155
151156 def dir_exec(self):
152157 """ run file_exec on every input file """
153− pass
158+ self.l , self.labs = [], []
159+ self.v = {}
160+ for i in self.valuenames:
161+ self.v[i] = []
162+ for i in self.valuelists:
163+ self.v[i] = []
164+ act_on_files(self.file_exec,self.sndlist,self.reslist, \
165+ suffix='',filter=sndfile_filter)
154166
155167 def dir_eval(self):
156168 pass
157169
158− def file_exec(self):
159− pass
170+ def file_gettruth(self,input):
171+ """ get ground truth filenames """
172+ from os.path import isfile
173+ ftrulist = []
174+ # search for match as filetask.input,".txt"
175+ ftru = '.'.join(input.split('.')[:-1])
176+ ftru = '.'.join((ftru,'txt'))
177+ if isfile(ftru):
178+ ftrulist.append(ftru)
179+ else:
180+ # search for matches for filetask.input in the list of results
181+ for i in range(len(self.reslist)):
182+ check = '.'.join(self.reslist[i].split('.')[:-1])
183+ check = '_'.join(check.split('_')[:-1])
184+ if check == '.'.join(input.split('.')[:-1]):
185+ ftrulist.append(self.reslist[i])
186+ return ftrulist
187+
188+ def file_exec(self,input,output):
189+ """ create filetask, extract data, evaluate """
190+ filetask = self.task(input,params=self.params)
191+ computed_data = filetask.compute_all()
192+ ftrulist = self.file_gettruth(filetask.input)
193+ for i in ftrulist:
194+ filetask.eval(computed_data,i,mode='rocloc',vmode='')
195+ """ append filetask.v to self.v """
196+ for i in self.valuenames:
197+ self.v[i].append(filetask.v[i])
198+ for j in self.valuelists:
199+ if filetask.v[j]:
200+ for i in range(len(filetask.v[j])):
201+ self.v[j].append(filetask.v[j][i])
160202
161203 def file_eval(self):
162204 pass
python/test/bench/onset/bench-onset+26−89
@@ -19,89 +19,38 @@ def stdev(l): · 18 unmodified lines
1919
2020 class benchonset(bench):
2121
22+ """ list of values to store per file """
2223 valuenames = ['orig','missed','Tm','expc','bad','Td']
24+ """ list of lists to store per file """
2325 valuelists = ['l','labs']
24− printnames = [ 'mode', 'thres', 'dist', 'prec', 'recl', 'Ttrue', 'Tfp', 'Tfn', 'Tm', 'Td',
25− 'aTtrue', 'aTfp', 'aTfn', 'aTm', 'aTd', 'mean', 'smean', 'amean', 'samean']
26−
27− formats = {'mode': "%12s" ,
28− 'thres': "%5.4s",
29− 'dist': "%5.4s",
30− 'prec': "%5.4s",
31− 'recl': "%5.4s",
32−
33− 'Ttrue': "%5.4s",
34− 'Tfp': "%5.4s",
35− 'Tfn': "%5.4s",
36− 'Tm': "%5.4s",
37− 'Td': "%5.4s",
38−
39− 'aTtrue':"%5.4s",
40− 'aTfp': "%5.4s",
41− 'aTfn': "%5.4s",
42− 'aTm': "%5.4s",
43− 'aTd': "%5.4s",
44−
45− 'mean': "%5.40s",
46− 'smean': "%5.40s",
47− 'amean': "%5.40s",
48− 'samean': "%5.40s"}
49−
50− def file_gettruth(self,input):
51− from os.path import isfile
52− ftrulist = []
53− # search for match as filetask.input,".txt"
54− ftru = '.'.join(input.split('.')[:-1])
55− ftru = '.'.join((ftru,'txt'))
56− if isfile(ftru):
57− ftrulist.append(ftru)
58− else:
59− # search for matches for filetask.input in the list of results
60− for i in range(len(self.reslist)):
61− check = '.'.join(self.reslist[i].split('.')[:-1])
62− check = '_'.join(check.split('_')[:-1])
63− if check == '.'.join(input.split('.')[:-1]):
64− ftrulist.append(self.reslist[i])
65− return ftrulist
66−
67− def file_exec(self,input,output):
68− filetask = self.task(input,params=self.params)
69− computed_data = filetask.compute_all()
70− ftrulist = self.file_gettruth(filetask.input)
71− for i in ftrulist:
72− #print i
73− filetask.eval(computed_data,i,mode='rocloc',vmode='')
74− for i in self.valuenames:
75− self.v[i] += filetask.v[i]
76− for i in filetask.v['l']:
77− self.v['l'].append(i)
78− for i in filetask.v['labs']:
79− self.v['labs'].append(i)
80−
81− def dir_exec(self):
82− """ run file_exec on every input file """
83− self.l , self.labs = [], []
84− self.v = {}
85− for i in self.valuenames:
86− self.v[i] = 0.
87− for i in self.valuelists:
88− self.v[i] = []
89− self.v['thres'] = self.params.threshold
90− act_on_files(self.file_exec,self.sndlist,self.reslist, \
91− suffix='',filter=sndfile_filter)
26+ """ list of values to print per dir """
27+ printnames = [ 'mode', 'thres', 'dist', 'prec', 'recl',
28+ 'Ttrue', 'Tfp', 'Tfn', 'Tm', 'Td',
29+ 'aTtrue', 'aTfp', 'aTfn', 'aTm', 'aTd',
30+ 'mean', 'smean', 'amean', 'samean']
31+
32+ """ per dir """
33+ formats = {'mode': "%12s" , 'thres': "%5.4s",
34+ 'dist': "%5.4s", 'prec': "%5.4s", 'recl': "%5.4s",
35+ 'Ttrue': "%5.4s", 'Tfp': "%5.4s", 'Tfn': "%5.4s",
36+ 'Tm': "%5.4s", 'Td': "%5.4s",
37+ 'aTtrue':"%5.4s", 'aTfp': "%5.4s", 'aTfn': "%5.4s",
38+ 'aTm': "%5.4s", 'aTd': "%5.4s",
39+ 'mean': "%5.40s", 'smean': "%5.40s",
40+ 'amean': "%5.40s", 'samean': "%5.40s"}
9241
9342 def dir_eval(self):
94− totaltrue = self.v['expc']-self.v['bad']-self.v['Td']
95− totalfp = self.v['bad']+self.v['Td']
96− totalfn = self.v['missed']+self.v['Tm']
43+ """ evaluate statistical data over the directory """
44+ totaltrue = sum(self.v['expc'])-sum(self.v['bad'])-sum(self.v['Td'])
45+ totalfp = sum(self.v['bad'])+sum(self.v['Td'])
46+ totalfn = sum(self.v['missed'])+sum(self.v['Tm'])
9747 self.P = 100*float(totaltrue)/max(totaltrue + totalfp,1)
9848 self.R = 100*float(totaltrue)/max(totaltrue + totalfn,1)
9949 if self.R < 0: self.R = 0
10050 self.F = 2.* self.P*self.R / max(float(self.P+self.R),1)
101−
10251 N = float(len(self.reslist))
103−
10452 self.v['mode'] = self.params.onsetmode
53+ self.v['thres'] = self.params.threshold
10554 self.v['thres'] = "%2.3f" % self.params.threshold
10655 self.v['dist'] = "%2.3f" % self.F
10756 self.v['prec'] = "%2.3f" % self.P
@@ -112,8 +61,8 @@ class benchonset(bench): · 4 unmodified lines
11261 self.v['aTtrue'] = totaltrue/N
11362 self.v['aTfp'] = totalfp/N
11463 self.v['aTfn'] = totalfn/N
115− self.v['aTm'] = self.v['Tm']/N
116− self.v['aTd'] = self.v['Td']/N
64+ self.v['aTm'] = sum(self.v['Tm'])/N
65+ self.v['aTd'] = sum(self.v['Td'])/N
11766 self.v['mean'] = mmean(self.v['l'])
11867 self.v['smean'] = stdev(self.v['l'])
11968 self.v['amean'] = mmean(self.v['labs'])
@@ -122,7 +71,6 @@ class benchonset(bench): · 2 unmodified lines
12271 def run_bench(self,modes=['dual'],thresholds=[0.5]):
12372 self.modes = modes
12473 self.thresholds = thresholds
125−
12674 self.pretty_titles()
12775 for mode in self.modes:
12876 self.params.onsetmode = mode
@@ -133,22 +81,12 @@ class benchonset(bench): · 4 unmodified lines
13381 self.pretty_print()
13482 #print self.v
13583
136− def pretty_print(self,sep='|'):
137− for i in self.printnames:
138− print self.formats[i] % self.v[i], sep,
139− print
140−
141− def pretty_titles(self,sep='|'):
142− for i in self.printnames:
143− print self.formats[i] % i, sep,
144− print
145−
14684 def auto_learn(self,modes=['dual'],thresholds=[0.1,1.5]):
14785 """ simple dichotomia like algorithm to optimise threshold """
14886 self.modes = modes
14987 self.pretty_titles()
15088 for mode in self.modes:
151− steps = 10
89+ steps = 11
15290 lesst = thresholds[0]
15391 topt = thresholds[1]
15492 self.params.onsetmode = mode
@@ -230,7 +168,7 @@ if __name__ == "__main__": · 75 unmodified lines
230168 if len(sys.argv) > 1: datapath = sys.argv[1]
231169 else: print "ERR: a path is required"; sys.exit(1)
232170 modes = ['complex', 'energy', 'phase', 'specdiff', 'kl', 'mkl', 'dual']
233− #modes = [ 'phase' ]
171+ #modes = [ 'mkl' ]
234172 thresholds = [ 0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2]
235173 #thresholds = [1.5]
236174
@@ -242,7 +180,6 @@ if __name__ == "__main__": · 5 unmodified lines
242180 benchonset.task = taskonset
243181 benchonset.valuesdict = {}
244182
245−
246183 try:
247184 #benchonset.auto_learn2(modes=modes)
248185 benchonset.run_bench(modes=modes,thresholds=thresholds)

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