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 implments

  • CBO (Consensus-Based Optimization) [1],
  • CBS (Consensus-Based Sampling) [2],
  • CBO with memory [3],
  • Batching schemes [4].

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

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-0.1.6.tar.gz (35.6 kB view details)

Uploaded Source

Built Distribution

cbx-0.1.6-py3-none-any.whl (40.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cbx-0.1.6.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for cbx-0.1.6.tar.gz
Algorithm Hash digest
SHA256 6473b26ed1aa3bf0d4e5293b0a42797134206effa134ded74a7dd32c4d4cbcbe
MD5 f08665ebe8145cdf5436304ed771378c
BLAKE2b-256 c6e14d65c06af6c4f8f28ebd97c7bb0657d3ff90a1a729b4486823324068bb03

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cbx-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 40.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for cbx-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ed2abce7d416807ce263e4b6fd2477425f82260a8b90e611234ba7d345e21452
MD5 f6c6d841f97f739ee751b73f9598a62e
BLAKE2b-256 fddfc6a617911e1ab423ce93eaee1f947e85a31cb6694853bce0be2467d91255

See more details on using hashes here.

Supported by

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