Python library for Bayesian Optimization.
Project description
BOlib
A python library for Bayesian Optimization.
Setup BOlib
-
Create and activate venv
python3 -m venv .env source .env/bin/activate
-
Upgrade pip
python -m pip install --upgrade pip
-
Install BOlib package
python -m pip install bolib
-
Matplotlib requires to install a backend to work interactively
(See https://matplotlib.org/faq/virtualenv_faq.html). The easiest solution is to install the Tk framework, which can be found as python-tk (or python3-tk) on certain Linux distributions.
Use BOlib
-
Import BOlib to use it in your python script.
import bolib
-
Some well-known objetive functions have been included.
of = bolib.ofs.Branin() of.evaluate([1.0, 1.0]) # 27.702905548512433
-
To use Bayesian Optimization we need a probabilistic model. In this example we will use Gaussian Processes.
import gplib model = gplib.GP( mean_function=gplib.mea.Fixed(), covariance_function=gplib.ker.SquaredExponential(ls=([1.] * of.d)) ) metric = gplib.me.LML() fitting_method = gplib.fit.MultiStart( obj_fun=metric.fold_measure, max_fun_call=300, nested_fit_method=gplib.fit.LocalSearch( obj_fun=metric.fold_measure, max_fun_call=75, method='Powell' ) ) validation = gplib.vm.Full()
-
Bayesian Optimization also needs an acquisition function.
af = bolib.afs.ExpectedImprovement()
-
Finally, we can initialize our optimization model and start the optimization process.
bo = bolib.methods.BayesianOptimization( model, fitting_method, validation, af ) bo.set_seed(seed=1) x0 = bo.random_sample(of.get_bounds(), batch_size=10) bo.minimize( of.evaluate, x0, bounds=of.get_bounds(), tol=1e-5, maxiter=of.get_max_eval(), disp=True )
-
BOlib is also Scipy compatible.
import scipy.optimize as spo bo.set_seed(seed=1) x0 = bo.random_sample(of.get_bounds(), batch_size=1)[0] result = spo.minimize( of.evaluate, x0, bounds=of.get_bounds(), method=bo.minimize, tol=1e-5, options={ 'maxiter': of.get_max_eval(), 'disp': True } )
-
There are more examples in examples/ directory. Check them out!
Develop BOlib
-
Update API documentation
source ./.env/bin/activate pip install Sphinx cd docs/ sphinx-apidoc -f -o ./ ../bolib
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bolib-0.22.0.tar.gz.
File metadata
- Download URL: bolib-0.22.0.tar.gz
- Upload date:
- Size: 32.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a32df64dad9840b938e37317e34c851409c8d4bd0a09b2137fc2f8415679f6ca
|
|
| MD5 |
c6ba5c6f055a688e735e6f93499827ef
|
|
| BLAKE2b-256 |
b74e4d0acd95c0ed14dd2c9c6829deb8e1be31951575430ee52dae6e0f56131e
|
File details
Details for the file bolib-0.22.0-py3-none-any.whl.
File metadata
- Download URL: bolib-0.22.0-py3-none-any.whl
- Upload date:
- Size: 46.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d15cd156168a07976d5607ffc9d967c2a1b573c664694357b0605d2c4a1fca27
|
|
| MD5 |
2a43f144ff85f07557ba75f903e5ba37
|
|
| BLAKE2b-256 |
7c84566c138efd076166c710a18c16a4a943656b5be687b8ffab3a339fc5f118
|