ConsensusBasedX.jl: Consensus-Based Optimisation in Julia

ConsensusBasedX.jl is a gradient-free stochastic optimisation package for Julia, born out of Consensus.jl and CBXpy. It uses Consensus-Based Optimisation (CBO), a flavour of Particle Swarm Optimisation (PSO) first introduced by R. Pinnau, C. Totzeck, O. Tse, and S. Martin (2017). This is a method of global optimisation particularly suited for rough functions, where gradient descent would fail. It is useful for optimisation in higher dimensions. It also implements Consensus-Based Sampling (CBS), as introduced in J. A. Carrillo, F. Hoffmann, A. M. Stuart, and U. Vaes (2022).

Static Badge Build Status Coverage Aqua License: MIT

How to install and use

To install ConsensusBasedX.jl, simply run

using Pkg; Pkg.add("ConsensusBasedX")

in the Julia REPL. You can then load the package in a script or in the REPL by running

using ConsensusBasedX

Basic minimisation

The main functionality of ConsensusBasedX.jl is function minimisation via CBO. It assumes you have defined a function f(x::AbstractVector) that takes a single vector argument x of length D = length(x).

For instance, if D = 2, you can minimise f by running:

minimise(f, D = 2)

Your full code might look like this:

using ConsensusBasedX
f(x) = x[1]^2 + x[2]^2
x = minimise(f, D = 2)

Basic sampling

ConsensusBasedX.jl also provides CBS. The package exports sample, which has the same syntax as minimise.

For instance, if D = 2, you can sample exp(-αf) by running:

out = sample(f, D = 2, extended_output=true)
out.sample

Bug reports, feature requests, and contributions

See the contribution guidelines.