Skip to content

Commit

Permalink
add ReadMe and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
TimRoith committed Oct 13, 2023
1 parent 435c8a8 commit 182e75b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
41 changes: 32 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@

![cbx](https://github.com/PdIPS/CBXpy/assets/44805883/65e7f1b2-e858-4b8d-af37-8eeaea15214c)

# What is CBXPy?
A python package for consensus-based particle dynamics, focusing on **optimization** and **sampling**.

```CBXPy``` is a python package for consensus-based particle dynamics, focusing on **optimization** and **sampling**. Minimizing a function using CBXPy can be done as follows
# How to use CBXPy?

Minimizing a function using CBXPy can be done as follows

```python
from cbx.dynamics import CBO
from cbx.dynamics import CBO # import the CBO class

f = lambda x: x[0]**2 + x[1]**2
dyn = CBO(f, d=2)
x = dyn.optimize()
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 is available at [https://pdips.github.io/CBXpy](https://pdips.github.io/CBXpy)
A documentation together with more examples and usage instructions is available at [https://pdips.github.io/CBXpy](https://pdips.github.io/CBXpy).


# Installation

Currently ```CBXPy``` can only be installed from PyPI with pip

```bash
pip install cbx
```



# What is CBX?
Expand All @@ -31,7 +38,7 @@ $$
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
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 variables. The core element is the consensus point
Expand All @@ -45,6 +52,22 @@ $$
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]](#CBO),
* CBS (Consensus Based Sampling) [[2]](#CBS),
* CBO with memory [[3]](#CBOMemory),
* Batching schemes [[4]](#Batching).


## References

<a name="CBO">[1]</a> 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

<a name="CBS">[2]</a> Consensus-based sampling, Carrillo, J.A., Hoffmann, F., Stuart, A.M., and Vaes, U, Studies in Applied Mathematics 2022

<a name="CBOMemory">[3]</a> Leveraging Memory Effects and Gradient Information in Consensus-Based Optimization: On Global Convergence in Mean-Field Law, Riedl, K., 2022

# Usage examples
<a name="Batching">[4]</a> 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
16 changes: 10 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name="cbx"
version="0.1.0"
version="0.1.1"
authors = [
{name = "Tim Roith", email = "tim.roith@fau.de"},
{name = "Tim Roith", email = "tim.roith@desy.de"},
]
description="CBXpy"
dependencies = [
Expand All @@ -11,23 +15,23 @@ dependencies = [
'scikit-learn',
'matplotlib'
]
readme = "README.rst"
readme = "README.md"
requires-python = ">3.5.2"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent"
]

[tool.setuptools.packages]
find = {} # Scan the project directory with the default parameters

[project.optional-dependencies] # Optional dependencies
test = [
'pytest',
'torch'
]

[tool.setuptools]
packages = ['cbx', 'cbx.dynamics', 'cbx.utils']


[tool.ruff]
# Enable flake8-bugbear (`B`) rules.
Expand Down

0 comments on commit 182e75b

Please sign in to comment.