Passed
Push — master ( 44bd28...268666 )
by Simon
03:57
created

tests.test_optimizers.test_convex_convergence   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A test_convex_convergence() 0 27 2
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