Passed
Push — master ( af4dfb...a5ea26 )
by Simon
01:48
created

rosenbrock_example.rosen()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nop 3
1
import numpy as np
2
from hyperactive import Hyperactive
3
4
5
def rosen(para, X, y):
6
    """The Rosenbrock function"""
7
    x = np.array([para["x1"], para["x2"], para["x3"], para["x4"]])
8
    y = np.array([para["x0"], para["x1"], para["x2"], para["x3"]])
9
10
    return -sum(100.0 * (x - y ** 2.0) ** 2.0 + (1 - y) ** 2.0)
11
12
13
x_range = np.arange(0, 3, 0.1)
14
15
search_config = {
16
    rosen: {"x0": x_range, "x1": x_range, "x2": x_range, "x3": x_range, "x4": x_range}
17
}
18
19
opt = Hyperactive(search_config, n_iter=1000000)
20
opt.search(0, 0)
21