shithub: aubio

Download patch

ref: 6ae3a77f49a78ea78a4dca71a42ac2da5768fa3d
parent: a12563ea14df2b47881bd064768536f225683b0b
author: Paul Brossier <piem@altern.org>
date: Wed Feb 22 21:23:30 EST 2006

update onset bench
update onset bench


--- a/python/test/bench/onset/bench-delay
+++ b/python/test/bench/onset/bench-delay
@@ -1,6 +1,5 @@
 #! /usr/bin/python
 
-from aubio.bench.node import *
 from aubio.tasks import *
 
 from benchonset import mmean, stdev, benchonset
@@ -9,53 +8,44 @@
 
 	def run_bench(self,modes=['dual'],thresholds=[0.5]):
 		from os.path import dirname,basename
-		self.modes = modes
 		self.thresholds = thresholds
 		self.pretty_titles()
-		for mode in self.modes:
-			d = []
-			outplot = "_-_".join(("delay",mode,
-				basename(self.datadir) ))
 
+		for mode in modes:
+			d = []
 			self.params.onsetmode = mode
+			self.params.localmin = True
+			self.params.delay = 1. 
 			self.params.threshold = thresholds[0]
-
+			#
 			self.params.localmin = False 
 			self.params.delay = 0. 
-
-			self.dir_exec()
-			self.dir_eval()
-			self.pretty_print()
+			self.dir_eval_print()
 			self.plotdiffs(d,plottitle="Causal")
-
+			#
 			self.params.localmin = True
 			self.params.delay = 0. 
-			self.dir_exec()
-			self.dir_eval()
-			self.pretty_print()
+			self.dir_eval_print()
 			self.plotdiffs(d,plottitle="Local min")
 
 			self.params.localmin = False 
 			self.params.delay = 6. 
-			self.dir_exec()
-			self.dir_eval()
-			self.pretty_print()
+			self.dir_eval_print()
 			self.plotdiffs(d,plottitle="Fixed delay")
 
-			self.plotplotdiffs(d)
-			self.plotplotdiffs(d,outplot=outplot,extension="png")
-			self.plotplotdiffs(d,outplot=outplot,extension="ps")
-			self.plotplotdiffs(d,outplot=outplot,extension="svg")
+			#self.plotplotdiffs(d)
+			outplot = "_-_".join(("delay",mode,basename(self.datadir) ))
+			for ext in ("png","svg","ps"):
+				self.plotplotdiffs(d,outplot=outplot,extension=ext)
 
-
 if __name__ == "__main__":
 	import sys
 	if len(sys.argv) > 1: datapath = sys.argv[1]
 	else: print "ERR: a path is required"; sys.exit(1)
-	modes = ['complex', 'energy', 'phase', 'specdiff', 'kl', 'mkl', 'dual']
-	#modes = [ 'complex' ]
-	thresholds = [ 0.5]
-	#thresholds = [1.5]
+	modes = ['complex', 'energy', 'phase', 'hfc', 'specdiff', 'kl', 'mkl', 'dual']
+	#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]
+	#modes = [ 'hfc' ]
+	thresholds = [0.5]
 
 	#datapath = "%s%s" % (DATADIR,'/onset/DB/*/')
 	respath = '/var/tmp/DB-testings'
--- a/python/test/bench/onset/bench-onset
+++ b/python/test/bench/onset/bench-onset
@@ -10,21 +10,28 @@
 		from os.path import dirname,basename
 		self.thresholds = thresholds
 		self.pretty_titles()
-		d,e,f = [],[],[]
+		d,e,f,g = [],[],[],[]
 		for mode in modes:
 			self.vlist = []
 			self.params.onsetmode = mode
+			#self.params.localmin = True
+			self.params.delay = 2. 
+			self.params.bufsize = 1024 
+			self.params.hopsize = 256
+			self.params.step = float(self.params.hopsize)/float(self.params.samplerate)
+			#self.params.mintol = 8. 
+
 			for threshold in self.thresholds:
 				self.params.threshold = threshold
-				self.dir_exec()
-				self.dir_eval()
-				self.pretty_print()
-				#print self.v
+				self.dir_eval_print()
 				self.vlist.append(self.v)
 			self.plotroc(d)
 			self.plotfmeas(e)
 			self.plotpr(f)
-			#print vlist
+			#self.plothistcat(g)
+
+
+
 		#self.plotplotroc(d)
 		#self.plotplotfmeas(e)
 		#self.plotplotpr(f)
@@ -33,94 +40,8 @@
 			self.plotplotroc(d,outplot=outplot,extension=ext)
 			self.plotplotfmeas(e,outplot=outplot,extension=ext)
 			self.plotplotpr(f,outplot=outplot,extension=ext)
+			#self.plotplothistcat(g,outplot=outplot,extension=ext)
 
-
-	def auto_learn(self,modes=['dual'],thresholds=[0.1,1.5]):
-		""" simple dichotomia like algorithm to optimise threshold """
-		self.modes = modes
-		self.pretty_titles()
-		for mode in self.modes:
-			steps = 11 
-			lesst = thresholds[0] 
-			topt = thresholds[1]
-			self.params.onsetmode = mode
-
-			self.params.threshold = topt 
-			self.dir_exec()
-			self.dir_eval()
-			self.pretty_print()
-			topF = self.F 
-
-			self.params.threshold = lesst 
-			self.dir_exec()
-			self.dir_eval()
-			self.pretty_print()
-			lessF = self.F 
-
-			for i in range(steps):
-				self.params.localmin = True
-				self.params.delay = 1. 
-				self.dir_exec()
-				self.dir_eval()
-				self.params.threshold = ( lesst + topt ) * .5 
-				self.dir_exec()
-				self.dir_eval()
-				self.pretty_print()
-				if self.F == 100.0 or self.F == topF: 
-					print "assuming we converged, stopping" 
-					break
-				#elif abs(self.F - topF) < 0.01 :
-				#	print "done converging"
-				#	break
-				if topF < self.F:
-					#lessF = topF
-					#lesst = topt 
-					topF = self.F
-					topt = self.params.threshold
-				elif lessF < self.F:
-					lessF = self.F
-					lesst = self.params.threshold
-				if topt == lesst:
-					lesst /= 2.
-
-	def auto_learn2(self,modes=['dual'],thresholds=[0.00001,1.0]):
-		""" simple dichotomia like algorithm to optimise threshold """
-		self.modes = modes
-		self.pretty_titles([])
-		for mode in self.modes:
-			steps = 10 
-			step = 0.4
-			self.params.onsetmode = mode
-			self.params.threshold = thresholds[0] 
-			cur = 0
-
-			for i in range(steps):
-				self.dir_exec()
-				self.dir_eval()
-				self.pretty_print()
-				new = self.P
-				if self.R == 0.0:
-					#print "Found maximum, highering"
-					step /= 2.
-					self.params.threshold -= step 
-				elif new == 100.0:
-					#print "Found maximum, highering"
-					step *= .99
-					self.params.threshold += step 
-				elif cur > new:
-					#print "lower"
-					step /= 2.
-					self.params.threshold -= step 
-				elif cur < new:
-					#print "higher"
-					step *= .99
-					self.params.threshold += step 
-				else:
-					print "Assuming we converged"
-					break
-				cur = new
-
-
 if __name__ == "__main__":
 	import sys
 	if len(sys.argv) > 1: datapath = sys.argv[1]
@@ -128,7 +49,7 @@
 	modes = ['complex', 'energy', 'phase', 'hfc', 'specdiff', 'kl', 'mkl', 'dual']
 	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]
 	#modes = [ 'hfc' ]
-	#thresholds = [0.1, 1.5]
+	#thresholds = [0.5]
 
 	#datapath = "%s%s" % (DATADIR,'/onset/DB/*/')
 	respath = '/var/tmp/DB-testings'
--- a/python/test/bench/onset/bench-window
+++ b/python/test/bench/onset/bench-window
@@ -2,7 +2,7 @@
 
 from aubio.tasks import *
 
-from benchonset import mmean, stdev, plotdiffs, plotplotdiffs, benchonset
+from benchonset import mmean, stdev, benchonset
 
 class mybenchonset(benchonset):
 
@@ -10,43 +10,39 @@
 		from os.path import dirname,basename
 		self.thresholds = thresholds
 		self.pretty_titles()
+
 		for mode in modes:
 
 			self.params.onsetmode = mode
+			self.params.localmin = True
+			self.params.delay = 1. 
 			self.params.threshold = thresholds[0]
 			self.params.localmin = False 
-
+			#
 			for delay in (0., 4.):
 				d = []
-				outplot = "_-_".join(("window",mode,"delay-%s" % delay,
-					basename(self.datadir) ))
 				self.params.delay = delay 
-
 				for buf in (2048, 1024, 512):
 					for hop in (buf/2, buf/4):
 						self.params.bufsize = buf 
 						self.params.hopsize = hop 
 						self.params.step = float(self.params.hopsize)/float(self.params.samplerate)
+						self.dir_eval_print()
+						self.plotdiffs(d,plottitle="%s %s" % (buf,hop))
+				#plotplotdiffs(d)
+				outplot = "_-_".join(("window",mode,"delay-%s" % int(delay),
+					basename(self.datadir) ))
+				for ext in ("png","svg","ps"):
+					self.plotplotdiffs(d,outplot=outplot,extension=ext)
 
-						self.dir_exec()
-						self.dir_eval()
-						self.pretty_print()
-						plotdiffs(self.v,d,plottitle="%s %s" % (buf,hop))
-
-				plotplotdiffs(d)
-				plotplotdiffs(d,outplot=outplot,extension="png")
-				plotplotdiffs(d,outplot=outplot,extension="ps")
-				plotplotdiffs(d,outplot=outplot,extension="svg")
-
-
 if __name__ == "__main__":
 	import sys
 	if len(sys.argv) > 1: datapath = sys.argv[1]
 	else: print "ERR: a path is required"; sys.exit(1)
-	modes = ['complex', 'energy', 'phase', 'specdiff', 'kl', 'mkl', 'dual']
-	#modes = [ 'complex' ]
-	thresholds = [ 0.5]
-	#thresholds = [1.5]
+	modes = ['complex', 'energy', 'phase', 'hfc', 'specdiff', 'kl', 'mkl', 'dual']
+	#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]
+	#modes = [ 'hfc' ]
+	thresholds = [0.5]
 
 	#datapath = "%s%s" % (DATADIR,'/onset/DB/*/')
 	respath = '/var/tmp/DB-testings'
--- a/python/test/bench/onset/benchonset.py
+++ b/python/test/bench/onset/benchonset.py
@@ -46,6 +46,10 @@
 
 		v['mode']      = self.params.onsetmode
 		v['thres']     = self.params.threshold 
+		v['bufsize']   = self.params.bufsize
+		v['hopsize']   = self.params.hopsize
+		v['silence']   = self.params.silence
+		v['mintol']   = self.params.mintol
 
 		v['Torig']     = sum(v['orig'])
 		v['TTm']       = sum(v['Tm'])
@@ -94,6 +98,11 @@
 		self.v['prec']      = self.P
 		self.v['recl']      = self.R
 
+
+	"""
+	Plot functions 
+	"""
+
 	def plotroc(self,d,plottitle=""):
 		import Gnuplot, Gnuplot.funcutils
 		gd = []
@@ -189,6 +198,33 @@
 		#g('set format \"%g\"')
 		g.plot(*d)
 
+	def plotfmeasvar(self,d,var,plottitle=""):
+		import Gnuplot, Gnuplot.funcutils
+		x,y = [],[]
+		for i in self.vlist:
+			x.append(i[var]) 
+			y.append(i['dist']) 
+		d.append(Gnuplot.Data(x, y, with='linespoints', 
+			title="%s %s" % (plottitle,i['mode']) ))
+	
+	def plotplotfmeasvar(self,d,var,outplot="",extension='ps', title="F-measure"):
+		import Gnuplot, Gnuplot.funcutils
+		from sys import exit
+		g = Gnuplot.Gnuplot(debug=0, persist=1)
+		if outplot:
+			if   extension == 'ps':  terminal = 'postscript'
+			elif extension == 'png': terminal = 'png'
+			elif extension == 'svg': terminal = 'svg'
+			else: exit("ERR: unknown plot extension")
+			g('set terminal %s' % terminal)
+			g('set output \'fmeas-%s.%s\'' % (outplot,extension))
+		g.xlabel(var)
+		g.ylabel('F-measure (%)')
+		#g('set xrange [0:1.2]')
+		g('set yrange [0:100]')
+		g.title(basename(self.datadir))
+		g.plot(*d)
+
 	def plotdiffs(self,d,plottitle=""):
 		import Gnuplot, Gnuplot.funcutils
 		v = self.v
@@ -229,7 +265,38 @@
 		g.xlabel('delay to hand-labelled onset (s)')
 		g.ylabel('% number of correct detections / ms ')
 		g('set xrange [-0.05:0.05]')
-		g('set yrange [0:50]')
+		g('set yrange [0:20]')
+		g.plot(*d)
+
+
+	def plothistcat(self,d,plottitle=""):
+		import Gnuplot, Gnuplot.funcutils
+		total = v['Torig']
+		for i in range(len(per)): per[i] /= total/100.
+
+		d.append(Gnuplot.Data(val, per, with='fsteps', 
+			title="%s %s" % (plottitle,v['mode']) ))
+		#d.append('mean=%f,sigma=%f,eps(x) title \"\"'% (mean,smean))
+		#d.append('mean=%f,sigma=%f,eps(x) title \"\"'% (amean,samean))
+
+
+	def plotplothistcat(self,d,outplot=0,extension='ps'):
+		import Gnuplot, Gnuplot.funcutils
+		from sys import exit
+		g = Gnuplot.Gnuplot(debug=0, persist=1)
+		if outplot:
+			if   extension == 'ps':  ext, extension = '.ps' , 'postscript'
+			elif extension == 'png': ext, extension = '.png', 'png'
+			elif extension == 'svg': ext, extension = '.svg', 'svg'
+			else: exit("ERR: unknown plot extension")
+			g('set terminal %s' % extension)
+			g('set output \'diffhist-%s%s\'' % (outplot,ext))
+		g('eps(x) = 1./(sigma*(2.*3.14159)**.5) * exp ( - ( x - mean ) ** 2. / ( 2. * sigma ** 2. ))')
+		g.title(basename(self.datadir))
+		g.xlabel('delay to hand-labelled onset (s)')
+		g.ylabel('% number of correct detections / ms ')
+		g('set xrange [-0.05:0.05]')
+		g('set yrange [0:20]')
 		g.plot(*d)