今天分享一个群智能优化算法Python宝----MEALPY(地址:https://github.com/thieu1995/mealpy)。
MEALPY库是最大的群智能优化算法python库。
自由软件:GNU通用公共许可证(GPL) V3许可证
算法总数:目前有175个(102个原始算法,46个官方变体,27个开发变体).
按分类有基于生物的bio_based,进化的evolutionary_based,人类的human_based,数学的math_based,音乐的music_based,物理的physics_based,群体的swarm_based,系统的system_based。
支持Python版本:3.7,3.8.x,3.9.x,3.10.x,3.11.x
支持项:numpy, scipy, pandas, matplotlib
使用pip安装:
pip install mealpy==2.5.3
从源代码安装
如果你想直接从源代码安装,使用:
git clone https://github.com/thieu1995/mealpy.git
cd mealpy
python setup.py install
安装完成后,您可以像导入任何其他Python模块一样导入Mealpy:
import mealpy
import numpy as np
from mealpy.swarm_based.PSO import OriginalPSO
# 定义函数
def fitness_function(solution):
return np.sum(solution**2)
# 参数
problem_dict1 = {
"fit_func": fitness_function,
"lb": [-10, -15, -4, -2, -8],
"ub": [10, 15, 12, 8, 20],
"minmax": "min",
}
# PSO参数
epoch = 1000
pop_size = 50
c1 = 2.05
c2 = 2.05
w_min = 0.4
w_max = 0.9
model = OriginalPSO(epoch, pop_size, c1, c2, w_min, w_max)
best_position, best_fitness = model.solve(problem_dict1)
print(f"Solution: {best_position}, Fitness: {best_fitness}")
此外还提供了:求解约束基准函数,多目标基准函数。
可视化:
全局和局部对比
探索阶段和开发阶段对比
运用:
Mealpy +神经网络(取代梯度下降优化器)
Mealpy +神经网络(优化神经网络超参数)
其他应用:
-
解决背包问题(离散问题)
-
优化支持向量机SVM (SVC)模型
-
优化线性回归模型
-
解决旅行商(Travelling Salesman Problem,TSP)问题
-
解决特征选择问题
视频教程:
https://mealpy.readthedocs.io/en/latest/pages/general/video_tutorials.html
请引用:
@article{van2023mealpy,
title={MEALPY: An open-source library for latest meta-heuristic algorithms in Python},
author={Van Thieu, Nguyen and Mirjalili, Seyedali},
journal={Journal of Systems Architecture},
year={2023},
publisher={Elsevier},
doi={10.1016/j.sysarc.2023.102871}
}
@article{van2023groundwater,
title={Groundwater level modeling using Augmented Artificial Ecosystem Optimization},
author={Van Thieu, Nguyen and Barma, Surajit Deb and Van Lam, To and Kisi, Ozgur and Mahesha, Amai},
journal={Journal of Hydrology},
volume={617},
pages={129034},
year={2023},
publisher={Elsevier},
doi={10.1016/j.jhydrol.2022.129034}
}
总结:
算法很多,应用丰富,可视化简单