PyPop7 黑箱优化 (BBO) 文档

[新闻!] 最近,PyPop7 已被一篇 Nature 论文使用和/或引用:[Veenstra 等人, Nature, 2025] 等。

https://img.shields.io/badge/GitHub-PyPop7-red.svg https://img.shields.io/badge/PyPI-pypop7-yellowgreen.svg https://img.shields.io/badge/license-GNU%20GPL--v3.0-green.svg https://img.shields.io/badge/OS-Linux%20%7C%20Windows%20%7C%20MacOS%20X-orange.svg https://static.pepy.tech/badge/pypop7 https://visitor-badge.laobi.icu/badge?page_id=Evolutionary-Intelligence.pypop https://img.shields.io/badge/arxiv-2212.05652-red https://img.shields.io/badge/JMLR-2024-red https://readthedocs.org/projects/pypop/badge/?version=latest

“进化负责生命世界中的适应、优化和创新,它执行一种简单的多样化和自然选择算法,这种算法在从单个蛋白质分子到整个生态系统的所有复杂性层面上都有效。”—— 摘自加州理工学院弗朗西斯·H·阿诺德的诺贝尔奖演讲

PyPop7 是一个用于单目标、实参数、黑箱问题的纯 Python 基于种群的优化库。其设计目标是为黑箱优化器 (BBO),特别是基于种群的优化器(包括演化算法、基于群体的随机方法和模式搜索),提供统一的接口和一系列优雅的实现,以促进研究的可重复性、BBO 的基准测试,尤其是实际应用。

具体而言,为缓解众所周知的(“臭名昭著的”)BBO 维度灾难问题,PyPop7 的主要重点是尽可能多地涵盖其针对大规模优化 (LSO) 的最先进 (SOTA) 实现,尽管这里也包含了许多它们的中等或小规模版本和变体(一些主要用于理论目的,一些主要用于教育目的,一些主要用于基准测试目的,还有一些主要用于中低维度的应用目的)。

_images/logo.png

注意

这个用于连续 BBO 的开源 Python 库仍在积极维护中。未来,我们计划添加一些新的 BBO 算法和现有 BBO 家族的一些 SOTA 版本,以使该库尽可能保持最新。我们非常欢迎对这个开源 Python 库的任何建议、扩展、改进、使用和测试(甚至是批评)!

如果在您的论文或项目中使用此开源纯 Python 库 PyPop7,我们非常欢迎(但非强制)您引用以下 arXiv 预印本论文:Duan, Q., Zhou, G., Shao, C., Wang, Z., Feng, M., Huang, Y., Tan, Y., Yang, Y., Zhao, Q. and Shi, Y., 2024. PyPop7: A pure-Python library for population-based black-box optimization. arXiv preprint arXiv:2212.05652.(目前这篇 arXiv 论文已提交至 JMLR,并于 2024 年 10 月 11 日星期五在经历了从 2023 年 3 月 28 日星期二到 2023 年 11 月 1 日星期三再到 2024 年 7 月 5 日星期五的三轮评审后被接受。)

快速入门

在许多(虽然不是全部)情况下,通常只需三个步骤即可利用 PyPop7 在 BBO 方面的潜力。

  1. 使用 pip 通过 PyPI 自动安装 pypop7

    $ pip install pypop7
    

有关多种安装方式的详细信息,请参阅此在线文档

  1. 为您手头的复杂优化问题定义/编写您自己的目标(也称为成本或适应度)函数(待最小化

    1>>> import numpy as np  # for numerical computation, which is also the computing engine used by PyPop7
    2>>> def rosenbrock(x):  # one notorious test function in the optimization community
    3...     return 100.0*np.sum(np.square(x[1:] - np.square(x[:-1]))) + np.sum(np.square(x[:-1] - 1.0))
    4>>> ndim_problem = 1000  # problem dimension
    5>>> problem = {'fitness_function': rosenbrock,  # fitness function to be minimized
    6...            'ndim_problem': ndim_problem,  # problem dimension
    7...            'lower_boundary': -5.0*np.ones((ndim_problem,)),  # lower search boundary
    8...            'upper_boundary': 5.0*np.ones((ndim_problem,))}  # upper search boundary
    

有关问题定义的详细信息,请参阅此在线文档。请注意,任何最大化问题都可以通过简单取反轻松转换为最小化问题。

有关 PyPop7 提供的来自不同应用领域的大量基准测试函数,请参阅此在线文档

  1. 在上述优化问题上运行一个或多个来自 PyPop7 的黑箱优化器 (BBO)

     1>>> from pypop7.optimizers.es.lmmaes import LMMAES  # or to choose any black-box optimizer you prefer in PyPop7
     2>>> options = {'fitness_threshold': 1e-10,  # terminate when the best-so-far fitness is lower than 1e-10
     3...            'max_runtime': 3600,  # terminate when the actual runtime exceeds 1 hour (i.e., 3600 seconds)
     4...            'seed_rng': 0,  # seed of random number generation (which should be set for repeatability)
     5...            'x': 4.0*np.ones((ndim_problem,)),  # initial mean of search/mutation/sampling distribution
     6...            'sigma': 3.0,  # initial global step-size of search distribution (to be fine-tuned for optimality)
     7...            'verbose': 500}
     8>>> lmmaes = LMMAES(problem, options)  # initialize the black-box optimizer (a unified interface for all optimizers)
     9>>> results = lmmaes.optimize()  # run its (time-consuming) optimization/evolution/search process
    10>>> # print best-so-far fitness and used function evaluations returned by the used black-box optimizer
    11>>> print(results['best_so_far_y'], results['n_function_evaluations'])
    129.948e-11 2973386
    

有关优化器设置的详细信息,请参阅此在线文档。以下 API 内容主要针对这个似乎日益流行的开源 Python 库中当前所有可用的 BBO。

注意

总共有四个 PyPop7 (PP7) 的扩展版本正在开发或计划中,如下所示:

  • 用于约束优化 (PyCoPop7 as PCP7),

  • 用于噪声优化 (PyNoPop7 as PNP7),

  • 通过并行和分布式优化增强 (PyPop77 as PP77),

  • 通过基于元演化的优化增强 (PyMePop7 as PMP7)。

PyPop7 内容