|
| 1 | +""" |
| 2 | +Implementation of the Branin problem |
| 3 | +
|
| 4 | +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. |
| 5 | +s.t x_1 \in [-5, 10], \quad x_2 \in [0, 15]. |
| 6 | +
|
| 7 | +It has three global minima at: |
| 8 | +(x_1, x_2) = (-\pi, 12.275) |
| 9 | + (\pi, 2.275) |
| 10 | + (9.42478, 2.475) |
| 11 | +and the optimal objective 0.3979 |
| 12 | +
|
| 13 | +Authors: Tucker Hartland <hartland1@llnl.gov> |
| 14 | + Nai-Yuan Chiang <chiang7@llnl.gov> |
| 15 | +""" |
| 16 | +import numpy as np |
| 17 | +from .problem import Problem |
| 18 | +from numpy.random import uniform |
| 19 | + |
| 20 | +# define the Branin problem class |
| 21 | +class BraninProblem(Problem): |
| 22 | + def __init__(self): |
| 23 | + ndim = 2 |
| 24 | + xlimits = np.array([[-5.0, 10], [0.0, 15]]) |
| 25 | + name = 'Branin' |
| 26 | + super().__init__(ndim, xlimits, name=name) |
| 27 | + |
| 28 | + def _evaluate(self, x: np.ndarray) -> np.ndarray: |
| 29 | + |
| 30 | + ne, nx = x.shape |
| 31 | + assert nx == self.ndim |
| 32 | + |
| 33 | + y = np.zeros((ne, 1), complex) |
| 34 | + b = 5.1 / (4.0 * (np.pi) ** 2) |
| 35 | + c = 5.0 / np.pi |
| 36 | + r = 6.0 |
| 37 | + s = 10.0 |
| 38 | + t = 1.0 / (8.0 * np.pi) |
| 39 | + |
| 40 | + arg1 = (x[:,1] - b * x[:,0]**2 + c * x[:,0] - r) |
| 41 | + y[:,0] = arg1**2 + s * (1 - t) * np.cos(x[:,0]) + s |
| 42 | + |
| 43 | + ''' |
| 44 | + # compute derivatives |
| 45 | + dy_dx0 = 2*arg1*(-2*b*x[:,0]+c) - s*(1-t)*np.sin(x[:,0]) |
| 46 | + dy_dx1 = 2*arg1 |
| 47 | + |
| 48 | + dy_dx = np.array([dy_dx0, dy_dx1]) |
| 49 | + ''' |
| 50 | + |
| 51 | + return y |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
0 commit comments