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

tests.test_optimizers.test_random_restart   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 83.33 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A test_convex_convergence_singleOpt() 35 35 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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