| @@ 51-78 (lines=28) @@ | ||
| 48 | assert -100 > opt.best_score > max_score |
|
| 49 | ||
| 50 | ||
| 51 | @pytest.mark.parametrize(*optimizers) |
|
| 52 | def test_max_score_1(Optimizer): |
|
| 53 | def objective_function(para): |
|
| 54 | score = -para["x1"] * para["x1"] |
|
| 55 | time.sleep(0.01) |
|
| 56 | return score |
|
| 57 | ||
| 58 | search_space = { |
|
| 59 | "x1": np.arange(0, 100, 0.1), |
|
| 60 | } |
|
| 61 | ||
| 62 | max_score = -9999 |
|
| 63 | ||
| 64 | c_time = time.time() |
|
| 65 | opt = Optimizer(search_space, initialize={"warm_start": [{"x1": 99}]}) |
|
| 66 | opt.search( |
|
| 67 | objective_function, |
|
| 68 | n_iter=100000, |
|
| 69 | max_score=max_score, |
|
| 70 | ) |
|
| 71 | diff_time = time.time() - c_time |
|
| 72 | ||
| 73 | print("\n Results head \n", opt.results.head()) |
|
| 74 | print("\n Results tail \n", opt.results.tail()) |
|
| 75 | ||
| 76 | print("\nN iter:", len(opt.results)) |
|
| 77 | ||
| 78 | assert diff_time < 1 |
|
| 79 | ||
| @@ 21-48 (lines=28) @@ | ||
| 18 | } |
|
| 19 | ||
| 20 | ||
| 21 | @pytest.mark.parametrize(*optimizers) |
|
| 22 | def test_max_score_0(Optimizer): |
|
| 23 | def objective_function(para): |
|
| 24 | score = -para["x1"] * para["x1"] |
|
| 25 | return score |
|
| 26 | ||
| 27 | search_space = { |
|
| 28 | "x1": np.arange(0, 100, 0.1), |
|
| 29 | } |
|
| 30 | ||
| 31 | max_score = -9999 |
|
| 32 | ||
| 33 | opt = Optimizer( |
|
| 34 | search_space, |
|
| 35 | initialize={"warm_start": [{"x1": 99}]}, |
|
| 36 | ) |
|
| 37 | opt.search( |
|
| 38 | objective_function, |
|
| 39 | n_iter=100, |
|
| 40 | max_score=max_score, |
|
| 41 | ) |
|
| 42 | ||
| 43 | print("\n Results head \n", opt.results.head()) |
|
| 44 | print("\n Results tail \n", opt.results.tail()) |
|
| 45 | ||
| 46 | print("\nN iter:", len(opt.results)) |
|
| 47 | ||
| 48 | assert -100 > opt.best_score > max_score |
|
| 49 | ||
| 50 | ||
| 51 | @pytest.mark.parametrize(*optimizers) |
|