| @@ 292-342 (lines=51) @@ | ||
| 289 | assert n_performed_iter == n_iter |
|
| 290 | ||
| 291 | ||
| 292 | def test_early_stop_7(): |
|
| 293 | """Test early stopping with relative tolerance where early stop occurs.""" |
|
| 294 | ||
| 295 | def objective_function(para): |
|
| 296 | return para["x1"] |
|
| 297 | ||
| 298 | search_space = { |
|
| 299 | "x1": list(np.arange(0, 100, 0.01)), |
|
| 300 | } |
|
| 301 | ||
| 302 | n_iter_no_change = 5 |
|
| 303 | early_stopping = { |
|
| 304 | "n_iter_no_change": n_iter_no_change, |
|
| 305 | "tol_abs": None, |
|
| 306 | "tol_rel": 10, |
|
| 307 | } |
|
| 308 | ||
| 309 | start1 = {"x1": 1} |
|
| 310 | start2 = {"x1": 1.09} |
|
| 311 | start3 = {"x1": 1.20} |
|
| 312 | ||
| 313 | warm_start_l = [ |
|
| 314 | start1, |
|
| 315 | start1, |
|
| 316 | start1, |
|
| 317 | start1, |
|
| 318 | start1, |
|
| 319 | start2, |
|
| 320 | start2, |
|
| 321 | start2, |
|
| 322 | start3, |
|
| 323 | start3, |
|
| 324 | start3, |
|
| 325 | ] |
|
| 326 | n_iter = len(warm_start_l) |
|
| 327 | ||
| 328 | hyper = Hyperactive() |
|
| 329 | hyper.add_search( |
|
| 330 | objective_function, |
|
| 331 | search_space, |
|
| 332 | n_iter=n_iter, |
|
| 333 | initialize={"warm_start": warm_start_l}, |
|
| 334 | early_stopping=early_stopping, |
|
| 335 | ) |
|
| 336 | hyper.run() |
|
| 337 | ||
| 338 | search_data = hyper.search_data(objective_function) |
|
| 339 | n_performed_iter = len(search_data) |
|
| 340 | ||
| 341 | print("\n n_performed_iter \n", n_performed_iter) |
|
| 342 | print("\n n_iter_no_change \n", n_iter_no_change) |
|
| 343 | ||
| 344 | assert n_performed_iter == (n_iter_no_change + 1) |
|
| 345 | ||
| @@ 174-224 (lines=51) @@ | ||
| 171 | assert n_performed_iter == n_iter |
|
| 172 | ||
| 173 | ||
| 174 | def test_early_stop_5(): |
|
| 175 | """Test early stopping with absolute tolerance where early stop occurs.""" |
|
| 176 | ||
| 177 | def objective_function(para): |
|
| 178 | return para["x1"] |
|
| 179 | ||
| 180 | search_space = { |
|
| 181 | "x1": list(np.arange(0, 100, 0.01)), |
|
| 182 | } |
|
| 183 | ||
| 184 | n_iter_no_change = 5 |
|
| 185 | early_stopping = { |
|
| 186 | "n_iter_no_change": n_iter_no_change, |
|
| 187 | "tol_abs": 0.1, |
|
| 188 | "tol_rel": None, |
|
| 189 | } |
|
| 190 | ||
| 191 | start1 = {"x1": 0} |
|
| 192 | start2 = {"x1": 0.09} |
|
| 193 | start3 = {"x1": 0.20} |
|
| 194 | ||
| 195 | warm_start_l = [ |
|
| 196 | start1, |
|
| 197 | start1, |
|
| 198 | start1, |
|
| 199 | start1, |
|
| 200 | start1, |
|
| 201 | start2, |
|
| 202 | start2, |
|
| 203 | start2, |
|
| 204 | start3, |
|
| 205 | start3, |
|
| 206 | start3, |
|
| 207 | ] |
|
| 208 | n_iter = len(warm_start_l) |
|
| 209 | ||
| 210 | hyper = Hyperactive() |
|
| 211 | hyper.add_search( |
|
| 212 | objective_function, |
|
| 213 | search_space, |
|
| 214 | n_iter=n_iter, |
|
| 215 | initialize={"warm_start": warm_start_l}, |
|
| 216 | early_stopping=early_stopping, |
|
| 217 | ) |
|
| 218 | hyper.run() |
|
| 219 | ||
| 220 | search_data = hyper.search_data(objective_function) |
|
| 221 | n_performed_iter = len(search_data) |
|
| 222 | ||
| 223 | print("\n n_performed_iter \n", n_performed_iter) |
|
| 224 | print("\n n_iter_no_change \n", n_iter_no_change) |
|
| 225 | ||
| 226 | assert n_performed_iter == (n_iter_no_change + 1) |
|
| 227 | ||