Passed
Push — master ( d03f6d...d5da96 )
by Simon
01:24
created

rosenbrock_function_example   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 12
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A rosen() 0 6 1
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(0, 0, memory=None)
20
opt.search(search_config, n_iter=1000000)
21