Reputation: 33
the tutorial from scipy only shows one possible solution for differential evolution (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.differential_evolution.html).
How can i get multiple solutions? And if not, is it because of scipy implementation or are differential evolutions algorithm just designed that way?
import numpy as np
from scipy.optimize import rosen, differential_evolution
bounds = [(0,2), (0, 2), (0, 2), (0, 2), (0, 2)]
result = differential_evolution(rosen, bounds)
result.x, result.fun
Upvotes: 1
Views: 713
Reputation: 585
There is only one global minimum in the rosen
function. It's not clear why you expect there to be multiple solutions. differential_evolution
is designed to have a greater probability of finding that global minimum.
If you have a solution with multiple minima and you want to record them all then shgo
might be your best option. Alternatively you could track the progress of the differential_evolution population to identify different minima in the energy surface.
Upvotes: 0
Reputation: 122240
There are several hyperparameters that you can set for the evolution algorithm to diverge.
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.differential_evolution.html
E.g.
import numpy as np
from scipy.optimize import rosen, differential_evolution
bounds = [(0,2), (1, 3), (1, 2), (4, 7), (500, 900)]
result = differential_evolution(rosen, bounds, seed=234)
print(result.x, result.fun)
result = differential_evolution(rosen, bounds, seed=42)
print(result.x, result.fun)
result = differential_evolution(rosen, bounds, seed=42)
print(result.x, result.fun)
result = differential_evolution(rosen, bounds, seed=23, mutation=(0.9, 1), recombination=0.8)
print(result.x, result.fun)
result = differential_evolution(rosen, bounds, seed=23, maxiter=2, mutation=(0.9, 1), recombination=0.8)
print(result.x, result.fun)
result = differential_evolution(rosen, bounds, seed=23, maxiter=2, mutation=(0.9, 1), recombination=0.8)
print(result.x, result.fun)
[out]:
(array([ 1.1880044 , 1.41300298, 2. , 7. ,
500. ]),
20341037.207360283)
(array([ 1.18838044, 1.41362179, 2. , 7. ,
500. ]),
20341037.207038924)
(array([ 1.18891057, 1.41438122, 2. , 7. ,
500. ]),
20341037.207497682)
(array([ 1.1885353 , 1.41414795, 2. , 7. ,
500. ]),
20341037.207302164)
But since rosen function is formulaic, the variance in the bounds needs to be large enough to see significant changes in the results.
import numpy as np
from scipy.optimize import rosen, differential_evolution
bounds = [(0,221529234), (123121, 31231232), (1231, 291231235), (30434, 1232317), (500, 900)]
result = differential_evolution(rosen, bounds, seed=234)
print(result.x, result.fun)
result = differential_evolution(rosen, bounds, seed=42)
print(result.x, result.fun)
[out]:
(array([ 8141.41766062, 123121. , 1231. , 30434. ,
813.59702423]),
2.3065086995396433e+22)
(array([ 0. , 123121. , 3838.30391681, 30434. ,
881.09558529]),
2.30646627657552e+22)
Upvotes: 0