shithub: aubio

Download patch

ref: af445db9b2ca0a315b5f9659e018397735499d18
parent: 27f2c08efb7176c7f9417c1be3d17a8d3fe3fd6f
author: Paul Brossier <piem@altern.org>
date: Thu Dec 22 11:39:02 EST 2005

add auto_learn2 method, which converges
add auto_learn2 method, which converges


--- a/python/bench-onset
+++ b/python/bench-onset
@@ -97,7 +97,39 @@
 				if topt == lesst:
 					lesst /= 2.
 
+	def auto_learn2(self,modes=['dual'],thresholds=[0.1,1.0]):
+		""" simple dichotomia like algorithm to optimise threshold """
+		self.modes = modes
+		self.pretty_print(self.titles)
+		for mode in self.modes:
+			steps = 10 
+			step = thresholds[1]
+			curt = thresholds[0] 
+			self.params.onsetmode = mode
 
+			self.params.threshold = curt 
+			self.dir_exec()
+			self.dir_eval()
+			self.pretty_print(self.values)
+			curexp = self.expc
+
+			for i in range(steps):
+				if curexp < self.orig:
+					#print "we found at most less onsets than annotated"
+					self.params.threshold -= step 
+					step /= 2
+				elif curexp > self.orig:
+					#print "we found more onsets than annotated"
+					self.params.threshold += step 
+					step /= 2
+				self.dir_exec()
+				self.dir_eval()
+				curexp = self.expc
+				self.pretty_print(self.values)
+				if self.orig == 100.0 or self.orig == self.expc: 
+					print "assuming we converged, stopping" 
+					break
+
 if __name__ == "__main__":
 	import sys
 	if len(sys.argv) > 1: datapath = sys.argv[1]
@@ -122,7 +154,7 @@
 	"| %6s", "| %6s", "| %6s"] 
 
 	try:
-		benchonset.auto_learn(modes=modes)
+		benchonset.auto_learn2(modes=modes)
 		#benchonset.run_bench(modes=modes)
 	except KeyboardInterrupt:
 		sys.exit(1)