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

non_convex_function.ackley_function()   A

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
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