新闻  |   论坛  |   博客  |   在线研讨会
蚁群优化算法、免疫算法、人工鱼群算法、差分进化……)
数据派THU | 2023-07-12 21:47:18    阅读:106   发布文章

这个库总共封装了遗传算法(GA)、粒子群算法(PSO)、蚁群算法(ACA)、模拟退火算法(SA)、免疫优化算法(IA)、人工鱼群算法(AFSA)。


开源地址:https://github.com/guofei9987/scikit-opt
装好Python后,在命令行输入以下指令即可安装:

pip install scikit-opt

粒子群算法为例
第一步,定义问题-> Demo code: examples/demo_pso.py#s1
def demo_func(x):x1, x2, x3 = xreturn x1 ** 2 + (x2 - 0.05) ** 2 + x3 ** 2

第二步,做粒子群算法-> Demo code: examples/demo_pso.py#s2
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)

第三步,画出结果-> Demo code: examples/demo_pso.py#s3
import matplotlib.pyplot as plt
plt.plot(pso.gbest_y_hist)plt.show()
图片图片


*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客