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

non_convex_function   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A ackley_function() 0 8 1
1
import numpy as np
2
from gradient_free_optimizers import RandomSearchOptimizer
3
4
5
def ackley_function(pos_new):
6
    x = pos_new["x1"]
7
    y = pos_new["x2"]
8
9
    a1 = -20 * np.exp(-0.2 * np.sqrt(0.5 * (x * x + y * y)))
10
    a2 = -np.exp(0.5 * (np.cos(2 * np.pi * x) + np.cos(2 * np.pi * y)))
11
    score = a1 + a2 + 20
12
    return -score
13
14
15
search_space = {
16
    "x1": np.arange(-100, 101, 0.1),
17
    "x2": np.arange(-100, 101, 0.1),
18
}
19
20
opt = RandomSearchOptimizer(search_space)
21
opt.search(ackley_function, n_iter=30000)
22