遗传算法 Python包 ,粒子群算法 Python包,模拟退火算法 Python包

工具包

在GitHub上找到一个开源的项目,并对其进行了更新,提交了一些小bug,它实现了数学建模中常用的算法包括:

  1. 差分进化算法
  2. 遗传算法
  3. 粒子群算法
  4. 模拟退火算法
  5. 蚁群算法
  6. 免疫优化算法
  7. 人工鱼群算法

项目链接:
https://github.com/zhangxiao123qqq/scikit-opt
原作者链接:
https://github.com/guofei9987/scikit-opt

Github有时候会无法访问,为方便国内小伙伴访问仓库,创建Gitee仓库https://gitee.com/zhangxiaodong123qqq/scikit-opt

黑盒实现,即拿即用!不要太爽!!祝大家建模愉快。

提示:项目中使用等help()命令可直接获得参数说明。

#遗传算法帮助
help(GA)
#模拟退火算法帮助
help(SA)

算法使用方式见:

中文使用文档

Demo演示:

demo_ga

import numpy as np


def schaffer(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.square(np.sin(x)) - 0.5) / np.square(1 + 0.001 * x)


# %%
from sko.GA import GA

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)

# %% Plot the result
import pandas as pd
import matplotlib.pyplot as plt

Y_history = pd.DataFrame(ga.all_history_Y)
fig, ax = plt.subplots(2, 1)
ax[0].plot(Y_history.index, Y_history.values, '.', color='red')
Y_history.min(axis=1).cummin().plot(kind='line')
plt.show()
  • 16
    点赞
  • 201
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值