用 Python 進(jìn)行差分進(jìn)化全局優(yōu)化

差分進(jìn)化優(yōu)化是一種進(jìn)化算法,旨在與實(shí)值候選解一起使用。 如何在python中使用差異進(jìn)化優(yōu)化算法API。 使用差異演化解決具有多個(gè)最優(yōu)解的全局優(yōu)化問題的示例。
差異進(jìn)化 差分進(jìn)化API 差分進(jìn)化的工作實(shí)例
DE / x / y / zDE / best / 1 / bin和DE / best / 2 / bin是受歡迎的配置,因?yàn)樗鼈冊谠S多目標(biāo)功能上表現(xiàn)良好。既然我們已經(jīng)熟悉了差分進(jìn)化算法,那么讓我們看一下如何使用SciPy API實(shí)現(xiàn)。differential_evolution()SciPy函數(shù)使用差分演化全局優(yōu)化算法。該函數(shù)將目標(biāo)函數(shù)的名稱和每個(gè)輸入變量的界限作為搜索的最小參數(shù)。# perform the differential evolution search
result = differential_evolution(objective, bounds)
“ best1bin”(DE / best / 1 / bin),對于大多數(shù)問題而言,這是一個(gè)很好的配置。它通過從總體中選擇隨機(jī)解,從另一個(gè)中減去一個(gè),然后將差異的縮放版本添加到總體中的最佳候選解中,來創(chuàng)建新的候選解。new = best + (mutation * (rand1 – r and2))
# ackley multimodal function
from numpy import arange
from numpy import exp
from numpy import sqrt
from numpy import cos
from numpy import e
from numpy import pi
from numpy import meshgrid
from matplotlib import pyplot
from mpl_toolkits.mplot3d import Axes3D
# objective function
def objective(x, y):
return -20.0 * exp(-0.2 * sqrt(0.5 * (x**2 + y**2))) - exp(0.5 * (cos(2 * pi * x) + cos(2 * pi * y))) + e + 20
# define range for input
r_min, r_max = -5.0, 5.0
# sample input range uniformly at 0.1 increments
xaxis = arange(r_min, r_max, 0.1)
yaxis = arange(r_min, r_max, 0.1)
# create a mesh from the axis
x, y = meshgrid(xaxis, yaxis)
# compute targets
results = objective(x, y)
# create a surface plot with the jet color scheme
figure = pyplot.figure()
axis = figure.gca(projection='3d')
axis.plot_surface(x, y, results, cmap='jet')
# show the plot
pyplot.show()
# define the bounds on the search
bounds = [[r_min, r_max], [r_min, r_max]]
# perform the differential evolution search
result = differential_evolution(objective, bounds)
# summarize the result
print('Status : %s' % result['message'])
print('Total Evaluations: %d' % result['nfev'])
# evaluate solution
solution = result['x']
evaluation = objective(solution)
print('Solution: f(%s) = %.5f' % (solution, evaluation))
# differential evolution global optimization for the ackley multimodal objective function
from scipy.optimize import differential_evolution
from numpy.random import rand
from numpy import exp
from numpy import sqrt
from numpy import cos
from numpy import e
from numpy import pi
# objective function
def objective(v):
x, y = v
return -20.0 * exp(-0.2 * sqrt(0.5 * (x**2 + y**2))) - exp(0.5 * (cos(2 * pi * x) + cos(2 * pi * y))) + e + 20
# define range for input
r_min, r_max = -5.0, 5.0
# define the bounds on the search
bounds = [[r_min, r_max], [r_min, r_max]]
# perform the differential evolution search
result = differential_evolution(objective, bounds)
# summarize the result
print('Status : %s' % result['message'])
print('Total Evaluations: %d' % result['nfev'])
# evaluate solution
solution = result['x']
evaluation = objective(solution)
print('Solution: f(%s) = %.5f' % (solution, evaluation))
Status: Optimization terminated successfully.
Total Evaluations: 3063
Solution: f([0. 0.]) = 0.00000
作者:沂水寒城,CSDN博客專家,個(gè)人研究方向:機(jī)器學(xué)習(xí)、深度學(xué)習(xí)、NLP、CV
Blog: http://yishuihancheng.blog.csdn.net
贊 賞 作 者

更多閱讀
特別推薦

點(diǎn)擊下方閱讀原文加入社區(qū)會員
評論
圖片
表情
