@@ 226-284 (lines=59) @@ | ||
223 | assert n_performed_iter == (n_iter_no_change + 1) |
|
224 | ||
225 | ||
226 | def test_early_stop_6(): |
|
227 | def objective_function(para): |
|
228 | return para["x1"] |
|
229 | ||
230 | search_space = { |
|
231 | "x1": list(np.arange(0, 100, 0.01)), |
|
232 | } |
|
233 | ||
234 | n_iter_no_change = 5 |
|
235 | early_stopping = { |
|
236 | "n_iter_no_change": 5, |
|
237 | "tol_abs": None, |
|
238 | "tol_rel": 10, |
|
239 | } |
|
240 | ||
241 | start1 = {"x1": 1} |
|
242 | start2 = {"x1": 1.1} |
|
243 | start3 = {"x1": 1.22} |
|
244 | start4 = {"x1": 1.35} |
|
245 | start5 = {"x1": 1.48} |
|
246 | ||
247 | warm_start_l = [ |
|
248 | start1, |
|
249 | start1, |
|
250 | start1, |
|
251 | start1, |
|
252 | start1, |
|
253 | start2, |
|
254 | start2, |
|
255 | start2, |
|
256 | start3, |
|
257 | start3, |
|
258 | start3, |
|
259 | start4, |
|
260 | start4, |
|
261 | start4, |
|
262 | start5, |
|
263 | start5, |
|
264 | start5, |
|
265 | ] |
|
266 | n_iter = len(warm_start_l) |
|
267 | ||
268 | hyper = Hyperactive() |
|
269 | hyper.add_search( |
|
270 | objective_function, |
|
271 | search_space, |
|
272 | n_iter=n_iter, |
|
273 | initialize={"warm_start": warm_start_l}, |
|
274 | early_stopping=early_stopping, |
|
275 | ) |
|
276 | hyper.run() |
|
277 | ||
278 | search_data = hyper.search_data(objective_function) |
|
279 | n_performed_iter = len(search_data) |
|
280 | ||
281 | print("\n n_performed_iter \n", n_performed_iter) |
|
282 | print("\n n_iter_no_change \n", n_iter_no_change) |
|
283 | ||
284 | assert n_performed_iter == n_iter |
|
285 | ||
286 | ||
287 | def test_early_stop_7(): |
|
@@ 112-170 (lines=59) @@ | ||
109 | assert n_performed_iter == (n_iter_no_change + 1) |
|
110 | ||
111 | ||
112 | def test_early_stop_4(): |
|
113 | def objective_function(para): |
|
114 | return para["x1"] |
|
115 | ||
116 | search_space = { |
|
117 | "x1": list(np.arange(0, 100, 0.1)), |
|
118 | } |
|
119 | ||
120 | n_iter_no_change = 5 |
|
121 | early_stopping = { |
|
122 | "n_iter_no_change": 5, |
|
123 | "tol_abs": 0.1, |
|
124 | "tol_rel": None, |
|
125 | } |
|
126 | ||
127 | start1 = {"x1": 0} |
|
128 | start2 = {"x1": 0.1} |
|
129 | start3 = {"x1": 0.2} |
|
130 | start4 = {"x1": 0.3} |
|
131 | start5 = {"x1": 0.4} |
|
132 | ||
133 | warm_start_l = [ |
|
134 | start1, |
|
135 | start1, |
|
136 | start1, |
|
137 | start1, |
|
138 | start1, |
|
139 | start2, |
|
140 | start2, |
|
141 | start2, |
|
142 | start3, |
|
143 | start3, |
|
144 | start3, |
|
145 | start4, |
|
146 | start4, |
|
147 | start4, |
|
148 | start5, |
|
149 | start5, |
|
150 | start5, |
|
151 | ] |
|
152 | n_iter = len(warm_start_l) |
|
153 | ||
154 | hyper = Hyperactive() |
|
155 | hyper.add_search( |
|
156 | objective_function, |
|
157 | search_space, |
|
158 | n_iter=n_iter, |
|
159 | initialize={"warm_start": warm_start_l}, |
|
160 | early_stopping=early_stopping, |
|
161 | ) |
|
162 | hyper.run() |
|
163 | ||
164 | search_data = hyper.search_data(objective_function) |
|
165 | n_performed_iter = len(search_data) |
|
166 | ||
167 | print("\n n_performed_iter \n", n_performed_iter) |
|
168 | print("\n n_iter_no_change \n", n_iter_no_change) |
|
169 | ||
170 | assert n_performed_iter == n_iter |
|
171 | ||
172 | ||
173 | def test_early_stop_5(): |