| Conditions | 2 |
| Total Lines | 28 |
| Code Lines | 22 |
| Lines | 28 |
| Ratio | 100 % |
| Changes | 0 | ||
| 1 | import pytest |
||
| 38 | View Code Duplication | @pytest.mark.parametrize(*optimizers_SBOM) |
|
| 39 | def test_convex_convergence_SBOM(Optimizer): |
||
| 40 | def objective_function(para): |
||
| 41 | score = -para["x1"] * para["x1"] |
||
| 42 | return score |
||
| 43 | |||
| 44 | search_space = {"x1": np.arange(-33, 33, 1)} |
||
| 45 | initialize = {"vertices": 2} |
||
| 46 | |||
| 47 | n_opts = 10 |
||
| 48 | |||
| 49 | scores = [] |
||
| 50 | for rnd_st in tqdm(range(n_opts)): |
||
| 51 | opt = Optimizer(search_space) |
||
| 52 | opt.search( |
||
| 53 | objective_function, |
||
| 54 | n_iter=30, |
||
| 55 | random_state=rnd_st, |
||
| 56 | memory=False, |
||
| 57 | verbosity={"print_results": False, "progress_bar": False}, |
||
| 58 | initialize=initialize, |
||
| 59 | ) |
||
| 60 | |||
| 61 | scores.append(opt.best_score) |
||
| 62 | score_mean = np.array(scores).mean() |
||
| 63 | print("scores", scores) |
||
| 64 | |||
| 65 | assert -500 < score_mean |
||
| 66 | |||
| 67 |