History

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

Paul Brossier committed 20 years ago

Commit af445db1 parent 27f2c081 file · +33 −1Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/bench-onset+33−1
@@ -97,6 +97,38 @@ class benchonset(bench): · 96 unmodified lines
97 if topt == lesst:97 if topt == lesst:
98 lesst /= 2.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
101if __name__ == "__main__":133if __name__ == "__main__":
102 import sys134 import sys
@@ -122,7 +154,7 @@ if __name__ == "__main__": · 19 unmodified lines
122 "| %6s", "| %6s", "| %6s"] 154 "| %6s", "| %6s", "| %6s"]
123 155
124 try:156 try:
125 benchonset.auto_learn(modes=modes)157 benchonset.auto_learn2(modes=modes)
126 #benchonset.run_bench(modes=modes)158 #benchonset.run_bench(modes=modes)
127 except KeyboardInterrupt:159 except KeyboardInterrupt:
128 sys.exit(1)160 sys.exit(1)

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