CBXPy: Consensus Based Particle Dynamics in Python#

CBXPy is a python package implementing consensus based particle schemes. Originally designed for optimization problems

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

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

\[x^i \gets x^i - \lambda\, dt\, (x_i - c_\alpha(x)) + \sigma\, \sqrt{dt} |x^i - c_\alpha(x)| \xi^i\]

where \(\xi_i\) are i.i.d. standard normal random variables. The core element is the consensus point

\[c_\alpha(x) = \frac{\sum_{i=1}^N x^i\, \exp(-\alpha\, f(x^i))}{\sum_{i=1}^N \exp(-\alpha\, f(x^i))}.\]

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.

Installation#

The package can be installed via pip

pip install cbx

Simple Usage Example#

The following example shows how to minimize a function using CBXPy

from cbx.dynamics import CBO

f = lambda x: x[0]**2 + x[1]**2
dyn = CBO(f, d=2)
x = dyn.optimize()

More Examples#

Documentation#

The functionality of the package is documented in the user guide. For a specifics about the implementation, we refer to the API.

References#

Indices and tables#