Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -97,6 +97,38 @@ class benchonset(bench): · 96 unmodified lines | ||
| 97 | 97 | if topt == lesst: |
| 98 | 98 | lesst /= 2. |
| 99 | 99 | |
| 100 | + def auto_learn2(self,modes=['dual'],thresholds=[0.1,1.0]): | |
| 101 | + """ simple dichotomia like algorithm to optimise threshold """ | |
| 102 | + self.modes = modes | |
| 103 | + self.pretty_print(self.titles) | |
| 104 | + for mode in self.modes: | |
| 105 | + steps = 10 | |
| 106 | + step = thresholds[1] | |
| 107 | + curt = thresholds[0] | |
| 108 | + self.params.onsetmode = mode | |
| 109 | + | |
| 110 | + self.params.threshold = curt | |
| 111 | + self.dir_exec() | |
| 112 | + self.dir_eval() | |
| 113 | + self.pretty_print(self.values) | |
| 114 | + curexp = self.expc | |
| 115 | + | |
| 116 | + for i in range(steps): | |
| 117 | + if curexp < self.orig: | |
| 118 | + #print "we found at most less onsets than annotated" | |
| 119 | + self.params.threshold -= step | |
| 120 | + step /= 2 | |
| 121 | + elif curexp > self.orig: | |
| 122 | + #print "we found more onsets than annotated" | |
| 123 | + self.params.threshold += step | |
| 124 | + step /= 2 | |
| 125 | + self.dir_exec() | |
| 126 | + self.dir_eval() | |
| 127 | + curexp = self.expc | |
| 128 | + self.pretty_print(self.values) | |
| 129 | + if self.orig == 100.0 or self.orig == self.expc: | |
| 130 | + print "assuming we converged, stopping" | |
| 131 | + break | |
| 100 | 132 | |
| 101 | 133 | if __name__ == "__main__": |
| 102 | 134 | import sys |
| @@ -122,7 +154,7 @@ if __name__ == "__main__": · 19 unmodified lines | ||
| 122 | 154 | "| %6s", "| %6s", "| %6s"] |
| 123 | 155 | |
| 124 | 156 | try: |
| 125 | − benchonset.auto_learn(modes=modes) | |
| 157 | + benchonset.auto_learn2(modes=modes) | |
| 126 | 158 | #benchonset.run_bench(modes=modes) |
| 127 | 159 | except KeyboardInterrupt: |
| 128 | 160 | sys.exit(1) |