Skip to main content

CBXpy

Project description

cbx

status tests codecov License: MIT Doc

A Python package for consensus-based particle dynamics, focusing on optimization and sampling.

How to use CBXPy?

Minimizing a function using CBXPy can be done as follows:

   from cbx.dynamics import CBO        # import the CBO class

   f = lambda x: x[0]**2 + x[1]**2     # define the function to minimize
   x = CBO(f, d=2).optimize()          # run the optimization

A documentation together with more examples and usage instructions is available at https://pdips.github.io/CBXpy.

Installation

Currently CBXPy can only be installed from PyPI with pip.

   pip install cbx

What is CBX?

Originally designed for optimization problems of the form

$$ \min_{x \in \mathbb{R}^n} f(x), $$

the scheme was introduced as CBO (Consensus-Based Optimization). Given an ensemble of points $x = (x_1, \ldots, x_N)$, the update reads

$$ x_i \gets x_i - \lambda\ dt\ (x_i - c(x)) + \sigma\ \sqrt{dt} |x_i - c(x)|\ \xi_i $$

where $\xi_i$ are i.i.d. standard normal random vectors. The core element is the consensus point

$$ \begin{align*} c(x) = \left(\sum_{i=1}^{N} x_i\ \exp(-\alpha\ f(x_i))\right)\bigg/\left(\sum_{i=1}^N \exp(-\alpha\ f(x_i))\right) \end{align*} $$

with a parameter $\alpha>0$. The scheme can be extended to sampling problems known as CBS, clustering problems and opinion dynamics, which motivates the acronym CBX, indicating the flexibility of the scheme.

Functionality

Among others, CBXPy currently implements

  • CBO (Consensus-Based Optimization) [1]
  • CBS (Consensus-Based Sampling) [2]
  • CBO with memory [3]
  • Batching schemes [4]
  • Polarized CBO [5]
  • Mirror CBO [6]
  • Adamized CBO [7]
  • Constrained CBO methods, including
    • Drift Correction [8]
    • Regularization [9]
    • Hypersurface CBO [10]

How to cite

If you use CBXPy please cite it as follows:

@article{bailo2024cbx,
  title={CBX: Python and Julia packages for consensus-based interacting particle methods},
  author={Bailo, Rafael and Barbaro, Alethea and Gomes, Susana and Riedl, Konstantin and Roith, Tim and Totzeck, Claudia and Vaes, Urbain},
  journal={Journal of Open Source Software},
  volume={9},
  number={98},
  pages={6611},
  year={2024}
}

References

[1] A consensus-based model for global optimization and its mean-field limit, Pinnau, R., Totzeck, C., Tse, O. and Martin, S., Mathematical Models and Methods in Applied Sciences 2017

[2] Consensus-based sampling, Carrillo, J.A., Hoffmann, F., Stuart, A.M., and Vaes, U., Studies in Applied Mathematics 2022

[3] Leveraging Memory Effects and Gradient Information in Consensus-Based Optimization: On Global Convergence in Mean-Field Law, Riedl, K., 2022

[4] A consensus-based global optimization method for high dimensional machine learning problems, Carrillo, J.A., Jin, S., Li, L. and Zhu, Y., ESAIM: Control, Optimisation and Calculus of Variations 2021

[5] Bungert, L., Roith, T., & Wacker, P. (2024). Polarized consensus-based dynamics for optimization and sampling. Mathematical Programming, 1-31.

[6] Bungert, L., Hoffmann, F., Kim, D. Y., & Roith, T. (2025). MirrorCBO: A consensus-based optimization method in the spirit of mirror descent. arXiv preprint arXiv:2501.12189.

[7] Chen, J., Jin, S., & Lyu, L. (2020). A consensus-based global optimization method with adaptive momentum estimation. arXiv preprint arXiv:2012.04827.

[8] Carrillo, J. A., Jin, S., Zhang, H., & Zhu, Y. (2024). An interacting particle consensus method for constrained global optimization. arXiv preprint arXiv:2405.00891.

[9] Borghi, G., Herty, M., & Pareschi, L. (2023). Constrained consensus-based optimization. SIAM Journal on Optimization, 33(1), 211-236.

[10] Fornasier, M., Huang, H., Pareschi, L., & Sünnen, P. (2020). Consensus-based optimization on hypersurfaces: Well-posedness and mean-field limit. Mathematical Models and Methods in Applied Sciences, 30(14), 2725-2751.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cbx-1.0.3.tar.gz (49.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cbx-1.0.3-py3-none-any.whl (56.0 kB view details)

Uploaded Python 3

File details

Details for the file cbx-1.0.3.tar.gz.

File metadata

  • Download URL: cbx-1.0.3.tar.gz
  • Upload date:
  • Size: 49.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for cbx-1.0.3.tar.gz
Algorithm Hash digest
SHA256 d062e38c12f5b9d8066c837d062a9d630d7138409d3e14bd8f545819c86b22ec
MD5 39f20f4be23fd3ae7328e8a30f31fd96
BLAKE2b-256 6b874b2791c826e5bd99db06bf219e671ec5c8f9b31acc06ab8c66221a886bc3

See more details on using hashes here.

File details

Details for the file cbx-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: cbx-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 56.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for cbx-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7a2d5db0bafe3a74ad1caca0b217908cfa99e57c6738a27b9f68029d282cf9c1
MD5 84a06524ffd8461928b25e327d898ea0
BLAKE2b-256 276851edd63a97aafc1bb794f1c7d5cd1bc842eaf2eb96a14834d33c626810f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page