Conditions | 2 |
Total Lines | 29 |
Code Lines | 22 |
Lines | 29 |
Ratio | 100 % |
Changes | 0 |
1 | import pytest |
||
24 | View Code Duplication | @pytest.mark.parametrize(*opt_local_l) |
|
|
|||
25 | def test_local_perf(Optimizer): |
||
26 | def objective_function(para): |
||
27 | score = -para["x1"] * para["x1"] |
||
28 | return score |
||
29 | |||
30 | search_space = {"x1": np.arange(-100, 101, 1)} |
||
31 | initialize = {"vertices": 2} |
||
32 | |||
33 | n_opts = 33 |
||
34 | n_iter = 100 |
||
35 | |||
36 | scores = [] |
||
37 | for rnd_st in tqdm(range(n_opts)): |
||
38 | opt = Optimizer(search_space, initialize=initialize) |
||
39 | opt.search( |
||
40 | objective_function, |
||
41 | n_iter=n_iter, |
||
42 | random_state=rnd_st, |
||
43 | memory=False, |
||
44 | verbosity=False, |
||
45 | ) |
||
46 | |||
47 | scores.append(opt.best_score) |
||
48 | score_mean = np.array(scores).mean() |
||
49 | |||
50 | print("\n score_mean", score_mean) |
||
51 | |||
52 | assert score_mean > -5 |
||
53 |