Python实现粒子群算法PSO

来源:互联网 发布:客户信息记录软件 编辑:程序博客网 时间:2024/06/05 12:45

去github上吧scikit-opt这个库下载下来,
https://github.com/guofei9987/scikit-opt
如果不想下载整个库,也可以只下载pso.py这个文件

PSO

def demo_func2(p):    # Sphere函数    out_put = 0    for i in p:        out_put += i ** 2    return out_put
from pso import PSOmy_pso = PSO(func=demo_func2, pop=30, dim=5, max_iter=100)fitness = my_pso.fit()print(my_pso.gbest_x)print(my_pso.gbest_y)my_pso.plot_history()

Figure_1-1

原创粉丝点击