| @@ 79-109 (lines=31) @@ | ||
| 76 | hyper.run() |
|
| 77 | ||
| 78 | ||
| 79 | def test_early_stop_3(): |
|
| 80 | def objective_function(para): |
|
| 81 | score = -para["x1"] * para["x1"] |
|
| 82 | return score |
|
| 83 | ||
| 84 | search_space = { |
|
| 85 | "x1": list(np.arange(0, 100, 0.1)), |
|
| 86 | } |
|
| 87 | ||
| 88 | n_iter_no_change = 5 |
|
| 89 | early_stopping = { |
|
| 90 | "n_iter_no_change": n_iter_no_change, |
|
| 91 | } |
|
| 92 | ||
| 93 | hyper = Hyperactive() |
|
| 94 | hyper.add_search( |
|
| 95 | objective_function, |
|
| 96 | search_space, |
|
| 97 | n_iter=100000, |
|
| 98 | initialize={"warm_start": [{"x1": 0}]}, |
|
| 99 | early_stopping=early_stopping, |
|
| 100 | ) |
|
| 101 | hyper.run() |
|
| 102 | ||
| 103 | search_data = hyper.search_data(objective_function) |
|
| 104 | n_performed_iter = len(search_data) |
|
| 105 | ||
| 106 | print("\n n_performed_iter \n", n_performed_iter) |
|
| 107 | print("\n n_iter_no_change \n", n_iter_no_change) |
|
| 108 | ||
| 109 | assert n_performed_iter == (n_iter_no_change + 1) |
|
| 110 | ||
| 111 | ||
| 112 | def test_early_stop_4(): |
|
| @@ 71-101 (lines=31) @@ | ||
| 68 | hyper.run() |
|
| 69 | ||
| 70 | ||
| 71 | def test_early_stop_3(): |
|
| 72 | def objective_function(para): |
|
| 73 | score = -para["x0"] * para["x0"] |
|
| 74 | return score |
|
| 75 | ||
| 76 | search_space = { |
|
| 77 | "x0": list(np.arange(0, 100, 0.1)), |
|
| 78 | } |
|
| 79 | ||
| 80 | n_iter_no_change = 5 |
|
| 81 | early_stopping = { |
|
| 82 | "n_iter_no_change": n_iter_no_change, |
|
| 83 | } |
|
| 84 | ||
| 85 | hyper = RandomSearchOptimizer() |
|
| 86 | hyper.add_search( |
|
| 87 | experiment, |
|
| 88 | search_config, |
|
| 89 | n_iter=100000, |
|
| 90 | initialize={"warm_start": [{"x0": 0}]}, |
|
| 91 | early_stopping=early_stopping, |
|
| 92 | ) |
|
| 93 | hyper.run() |
|
| 94 | ||
| 95 | search_data = hyper.search_data(experiment) |
|
| 96 | n_performed_iter = len(search_data) |
|
| 97 | ||
| 98 | print("\n n_performed_iter \n", n_performed_iter) |
|
| 99 | print("\n n_iter_no_change \n", n_iter_no_change) |
|
| 100 | ||
| 101 | assert n_performed_iter == (n_iter_no_change + 1) |
|
| 102 | ||
| 103 | ||
| 104 | def test_early_stop_4(): |
|