python智能优化算法_scikit-opt——Python中的群体智能优化算法库

安装

pip install scikit-opt

对于当前的开发者版本:

git clone git@github.com:guofei9987/scikit-opt.git

cd scikit-opt

pipinstall .

Genetic Algorithm

第一步:定义你的问题

importnumpy as npdefschaffer(p):'''This function has plenty of local minimum, with strong shocks

global minimum at (0,0) with value 0'''x1, x2=p

x= np.square(x1) +np.square(x2)return 0.5 + (np.sin(x) - 0.5) / np.square(1 + 0.001 * x)

第二步:运行遗传算法

from sko.GA importGA

#2个变量,每代取50个,800次迭代,上下界及精度

ga= GA(func=schaffer, n_dim=2, size_pop=50, max_iter=800, lb=[-1, -1], ub=[1, 1], precision=1e-7)

best_x, best_y=ga.run()print('best_x:', best_x, '\n', 'best_y:', best_y)

第三步:画出结果

importpandas as pdimportmatplotlib.py

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值