https://github.com/pdips/consensusbasedx.jl
A Julia package for consensus-based optimisation
https://github.com/pdips/consensusbasedx.jl
consensus-based-optimisation julia optimisation particle-swarm-optimisation
Last synced: 3 months ago
JSON representation
A Julia package for consensus-based optimisation
- Host: GitHub
- URL: https://github.com/pdips/consensusbasedx.jl
- Owner: PdIPS
- License: mit
- Created: 2023-03-16T15:57:44.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-08-25T12:41:08.000Z (5 months ago)
- Last Synced: 2025-10-05T00:47:08.005Z (4 months ago)
- Topics: consensus-based-optimisation, julia, optimisation, particle-swarm-optimisation
- Language: Julia
- Homepage: https://pdips.github.io/ConsensusBasedX.jl/
- Size: 1.11 MB
- Stars: 15
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Citation: citation.cff
Awesome Lists containing this project
README

# ConsensusBasedX.jl: Consensus-Based Optimisation in Julia
[](https://joss.theoj.org/papers/008799348e8232eb9fe8180712e2dfb8)
[](https://PdIPS.github.io/ConsensusBasedX.jl/stable/)
[](https://PdIPS.github.io/ConsensusBasedX.jl/dev/)
[](https://github.com/PdIPS/ConsensusBasedX.jl/actions/workflows/CI.yml?query=branch%3Amain)
[](https://codecov.io/gh/PdIPS/ConsensusBasedX.jl)
[](https://github.com/JuliaTesting/Aqua.jl)
[](https://opensource.org/licenses/MIT)
**ConsensusBasedX.jl** is a gradient-free stochastic optimisation package for Julia, born out of [Consensus.jl](https://github.com/rafaelbailo/Consensus.jl) and [CBXpy](https://github.com/PdIPS/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)][1]. 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)][2].
## How to install and use
To install ConsensusBasedX.jl, simply run
```julia
using Pkg; Pkg.add("ConsensusBasedX")
```
in the Julia REPL. You can then load the package in a script or in the REPL by running
```julia
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:
```julia
minimise(f, D = 2)
```
Your full code might look like this:
```julia
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:
```julia
out = sample(f, D = 2, extended_output=true)
out.sample
```
For more detailed explanations and full-code examples, see the [documentation](https://PdIPS.github.io/ConsensusBasedX.jl/stable/).
## Bug reports, feature requests, and contributions
See [the contribution guidelines](https://github.com/PdIPS/ConsensusBasedX.jl/blob/main/CONTRIBUTING.md).
[1]: http://dx.doi.org/10.1142/S0218202517400061
[2]: https://onlinelibrary.wiley.com/doi/10.1111/sapm.12470
*Copyright © 2024 [Dr Rafael Bailo](https://rafaelbailo.com/) and [Purpose-Driven Interacting Particle Systems Group](https://github.com/PdIPS). [MIT License](https://github.com/PdIPS/ConsensusBasedX.jl/blob/main/LICENSE).*