Total Complexity | 2 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import pytest |
||
2 | from tqdm import tqdm |
||
3 | import numpy as np |
||
4 | |||
5 | from ._parametrize import pytest_parameter |
||
6 | |||
7 | |||
8 | @pytest.mark.parametrize(*pytest_parameter) |
||
9 | def test_convex_convergence(Optimizer): |
||
10 | def objective_function(para): |
||
11 | score = -para["x1"] * para["x1"] |
||
12 | return score |
||
13 | |||
14 | search_space = {"x1": np.arange(-100, 100, 1)} |
||
15 | initialize = {"vertices": 2} |
||
16 | |||
17 | n_opts = 33 |
||
18 | |||
19 | scores = [] |
||
20 | for rnd_st in tqdm(range(n_opts)): |
||
21 | opt = Optimizer(search_space) |
||
22 | opt.search( |
||
23 | objective_function, |
||
24 | n_iter=50, |
||
25 | random_state=rnd_st, |
||
26 | memory=False, |
||
27 | verbosity={"print_results": False, "progress_bar": False}, |
||
28 | initialize=initialize, |
||
29 | ) |
||
30 | |||
31 | scores.append(opt.best_score) |
||
32 | score_mean = np.array(scores).mean() |
||
33 | |||
34 | assert -500 < score_mean |
||
35 | |||
36 |