| Conditions | 2 |
| Total Lines | 35 |
| Code Lines | 25 |
| Lines | 35 |
| Ratio | 100 % |
| Changes | 0 | ||
| 1 | import pytest |
||
| 7 | View Code Duplication | @pytest.mark.parametrize(*optimizers_local) |
|
|
|
|||
| 8 | def test_convex_convergence_singleOpt(Optimizer): |
||
| 9 | def objective_function(para): |
||
| 10 | score = -(para["x1"] * para["x1"]) |
||
| 11 | return score |
||
| 12 | |||
| 13 | search_space = { |
||
| 14 | "x1": np.arange(-1000, 1, 1), |
||
| 15 | } |
||
| 16 | |||
| 17 | init1 = { |
||
| 18 | "x1": -1000, |
||
| 19 | } |
||
| 20 | initialize = {"warm_start": [init1]} |
||
| 21 | |||
| 22 | n_opts = 33 |
||
| 23 | |||
| 24 | scores = [] |
||
| 25 | for rnd_st in range(n_opts): |
||
| 26 | opt = Optimizer(search_space, rand_rest_p=1) |
||
| 27 | opt.search( |
||
| 28 | objective_function, |
||
| 29 | n_iter=30, |
||
| 30 | random_state=rnd_st, |
||
| 31 | memory=False, |
||
| 32 | verbosity=False, |
||
| 33 | initialize=initialize, |
||
| 34 | ) |
||
| 35 | |||
| 36 | scores.append(opt.best_score) |
||
| 37 | score_mean = np.array(scores).mean() |
||
| 38 | |||
| 39 | print("score_mean", score_mean) |
||
| 40 | |||
| 41 | assert score_mean > -10000 |
||
| 42 | |||
| 43 |