Passed
Push — master ( c33d71...2e7b09 )
by Simon
01:22 queued 11s
created

hillclimbing   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 18
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A get_score() 0 4 1
1
import numpy as np
2
from gradient_free_optimizers import HillClimbingOptimizer
3
4
5
n_iter = 10
6
7
8
def get_score(pos_new):
9
    x1 = pos_new[0]
10
11
    return -x1 * x1
12
13
14
space_dim = np.array([100])
15
init_positions = [np.array([10])]
16
17
18
opt = HillClimbingOptimizer(init_positions, space_dim, opt_para={})
19
20
for nth_init in range(len(init_positions)):
21
    pos_new = opt.init_pos(nth_init)
22
    score_new = get_score(pos_new)
23
    opt.evaluate(score_new)
24
25
26
for nth_iter in range(len(init_positions), n_iter):
27
    pos_new = opt.iterate(nth_iter)
28
    score_new = get_score(pos_new)
29
    opt.evaluate(score_new)
30