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

tests.test_optimizer_parameter.test_Bayesian   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 33.33 %

Importance

Changes 0
Metric Value
eloc 28
dl 15
loc 45
rs 10
c 0
b 0
f 0
wmc 8

4 Functions

Rating   Name   Duplication   Size   Complexity  
A test_max_sample_size() 0 4 2
A test_warm_start_smbo() 15 15 3
A test_skip_retrain() 0 4 2
A get_score() 0 2 1

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
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
import numpy as np
6
7
from gradient_free_optimizers import BayesianOptimizer
8
from ._base_test import _base_test
9
10
n_iter = 33
11
opt = BayesianOptimizer
12
13
14
def get_score(para):
15
    return -(para["x1"] * para["x1"])
16
17
18
def test_skip_retrain():
19
    for skip_retrain in ["many", "some", "few", "never"]:
20
        opt_para = {"skip_retrain": skip_retrain}
21
        _base_test(opt, n_iter, opt_para=opt_para)
22
23
24 View Code Duplication
def test_warm_start_smbo():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
25
    gpr_X, gpr_y = [], []
26
    for _ in range(10):
27
        pos_ = np.random.randint(0, high=9)
28
        pos = np.array([pos_])
29
30
        para = {
31
            "x1": pos_,
32
        }
33
        gpr_X.append(pos)
34
        gpr_y.append(get_score(para))
35
36
    for warm_start_smbo in [None, (gpr_X, gpr_y)]:
37
        opt_para = {"warm_start_smbo": warm_start_smbo}
38
        _base_test(opt, n_iter, opt_para=opt_para)
39
40
41
def test_max_sample_size():
42
    for max_sample_size in [10, 100, 10000, 10000000000]:
43
        opt_para = {"max_sample_size": max_sample_size}
44
        _base_test(opt, n_iter, opt_para=opt_para)
45