scipy 如何得到差分进化算法的多个可能解?

kqlmhetl  于 2023-03-30  发布在  其他
关注(0)|答案(2)|浏览(137)

来自SCIPY的教程仅示出了差分进化的一种可能的解决方案(https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.differential_evolution.html)。
我怎么能得到多个解决方案?如果不是,是因为scipy实现还是差分进化算法只是这样设计的?

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
jum4pzuy

jum4pzuy1#

有几个超参数可以让进化算法发散。
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.differential_evolution.html
例如:

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)
在边界中具有较大的方差

但由于罗森函数是公式化的,因此边界的方差需要足够大,才能看到结果的显著变化。

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)
8fq7wneg

8fq7wneg2#

rosen函数中只有一个全局最小值。不清楚为什么你期望有多个解。differential_evolution被设计成有更大的概率找到全局最小值。如果你有一个具有多个最小值的解,并且你想记录它们,那么shgo可能是你最好的选择。或者你可以跟踪微分的进度_进化群体以识别能量表面中的不同最小值。

相关问题