"); //-->
开源地址:https://github.com/guofei9987/scikit-opt
装好Python后,在命令行输入以下指令即可安装:
pip install scikit-opt
def demo_func(x):x1, x2, x3 = xreturn x1 ** 2 + (x2 - 0.05) ** 2 + x3 ** 2
from sko.PSO import PSO
pso = PSO(func=demo_func, n_dim=3, pop=40, max_iter=150, lb=[0, -1, 0.5], ub=[1, 1, 1], w=0.8, c1=0.5, c2=0.5)pso.run()print('best_x is ', pso.gbest_x, 'best_y is', pso.gbest_y)
import matplotlib.pyplot as plt
plt.plot(pso.gbest_y_hist)plt.show()
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。