python实现粒子群优化算法(pso)

下面使用python实现优化的一个简单例子
下载和安装pyswarm包
from pyswarm import pso
def banana(x):
x1 = x[0]
x2 = x[1]
return x14 - 2x2x12 + x22 + x12 - 2x1 + 5
def con(x):
x1 = x[0]
x2 = x[1]
return [-(x1 + 0.25)**2 + 0.75
x2]
lb = [-3, -1]
ub = [2, 6]
xopt, fopt = pso(banana, lb, ub, f_ieqcons=con)
pso返回的两个值分别是:优化的参数值和最终的适应度值

你可能感兴趣的:(深度学习,python,pso)