tests.test_optimizers.test_parameter._base_para_test   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

2 Functions

Rating   Name   Duplication   Size   Complexity  
A objective_function() 0 3 1
A _base_para_test_func() 0 13 1
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
import numpy as np
6
7
8
def objective_function(para):
9
    score = -para["x1"] * para["x1"]
10
    return score
11
12
13
search_space = {"x1": np.arange(-100, 101, 1)}
14
15
16
def _base_para_test_func(opt_para, optimizer):
17
    opt = optimizer(search_space, initialize={"vertices": 1}, **opt_para)
18
    opt.search(
19
        objective_function,
20
        n_iter=30,
21
        memory=False,
22
        verbosity=False,
23
    )
24
25
    para_key = list(opt_para.keys())[0]
26
    para_value = getattr(opt, para_key)
27
28
    assert para_value is opt_para[para_key]
29