-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathBraninProblem.py
More file actions
56 lines (40 loc) · 1.42 KB
/
BraninProblem.py
File metadata and controls
56 lines (40 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Implementation of the Branin problem
min f(x_1, x_2) = \left( x_2 - \frac{5.1}{4\pi^2} x_1^2 + \frac{5}{\pi} x_1 - 6 \right)^2 + 10 \left(1 - \frac{1}{8\pi}\right) \cos(x_1) + 10.
s.t x_1 \in [-5, 10], \quad x_2 \in [0, 15].
It has three global minima at:
(x_1, x_2) = (-\pi, 12.275)
(\pi, 2.275)
(9.42478, 2.475)
and the optimal objective 0.3979
Authors: Tucker Hartland <[email protected]>
Nai-Yuan Chiang <[email protected]>
"""
import numpy as np
from .problem import Problem
from numpy.random import uniform
# define the Branin problem class
class BraninProblem(Problem):
def __init__(self):
ndim = 2
xlimits = np.array([[-5.0, 10], [0.0, 15]])
name = 'Branin'
super().__init__(ndim, xlimits, name=name)
def _evaluate(self, x: np.ndarray) -> np.ndarray:
ne, nx = x.shape
assert nx == self.ndim
y = np.zeros((ne, 1), complex)
b = 5.1 / (4.0 * (np.pi) ** 2)
c = 5.0 / np.pi
r = 6.0
s = 10.0
t = 1.0 / (8.0 * np.pi)
arg1 = (x[:,1] - b * x[:,0]**2 + c * x[:,0] - r)
y[:,0] = arg1**2 + s * (1 - t) * np.cos(x[:,0]) + s
'''
# compute derivatives
dy_dx0 = 2*arg1*(-2*b*x[:,0]+c) - s*(1-t)*np.sin(x[:,0])
dy_dx1 = 2*arg1
dy_dx = np.array([dy_dx0, dy_dx1])
'''
return y