Passed
Push — master ( b0b7f3...e3d174 )
by Simon
04:31
created

test_convex_convergence_singleOpt()   A

Complexity

Conditions 2

Size

Total Lines 35
Code Lines 25

Duplication

Lines 35
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 25
nop 1
dl 35
loc 35
rs 9.28
c 0
b 0
f 0
1
import pytest
2
import numpy as np
3
4
from ._parametrize import optimizers_local
5
6
7 View Code Duplication
@pytest.mark.parametrize(*optimizers_local)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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