In order to better understand this process, you will start simple with Branin function which has 3 global minima:
The following code snippet shows you the minimization of the Branin function:
import numpy as np
def branin(x):
# Branin function has 2 dimensions and it has 3 global mimima
x1 = x[0]
x2 = x[1]
# Global minimum is f(x*)=0.397887 at points (-pi, 12.275), (pi,2.275) and (9.42478, 2.475)
# Recommended values of a, b, c, r, s and t for Branin function
a = 1
b = 5.1 / (4 * np.pi**2)
c = 5. / np.pi
r = 6.
s = 10.
t = 1 / (8 * np.pi)
# Calculating separate parts of the function first for verbosity
p1 = a * (x2 - (b * x1**2) + (c * x1) - r)**2
p2 = s * (1-t) * np.cos(x1)
p3 = s
# Calculating result
ret = p1 + p2 + p3
return ret
# minimize function from scipy.optimize will minimize a scalar function with one...