Skip to main content
Help improve PyPI by participating in a 5-minute user interface survey!

Python library for Bayesian Optimization.

Project Description

Build Status Documentation Status

BOlib

A python library for Bayesian Optimization.

Setup BOlib

  • The following packages must be installed before installing BOlib
# for ptyhon3
apt-get install python3-tk
# or for python2
apt-get install python-tk
  • Create and activate virtualenv (for python2) or venv (for ptyhon3)
# for ptyhon3
python3 -m venv --system-site-packages .env
# or for python2
virtualenv --system-site-packages .env

source .env/bin/activate
  • Upgrade pip
# for ptyhon3
python3 -m pip install --upgrade pip
# or for python2
python -m pip install --upgrade pip
  • Install GPlib package
python -m pip install bolib

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
import numpy as np

# We initialize data before the first evaluation.

data = {
    'X': np.zeros((2, len(of.get_bounds()))),
    'Y': np.array([[-1.0], [1.0]])
}

model = gplib.GP(
    mean_function=gplib.mea.Constant(data),
    covariance_function=gplib.cov.Sum([
        gplib.cov.SquaredExponential(data, is_ard=True),
        gplib.cov.WhiteNoise(data)
    ]),
    likelihood_function=gplib.lik.Gaussian(),
    inference_method=gplib.inf.ExactGaussian(),
    fitting_method=gplib.fit.HparamOptimization(
        ls_method="Powell",
        save_opt=True
    )
)
  • Bayesian Optimization also needs an acquisition function.
af = bolib.afs.ExpectedImprovement()
  • Finally, we can initialize our optimization model and start the optimization process.
# We get a random sample within the bounds of the objective function
seed = 1
bo = bolib.methods.BayesianOptimization(model, af, seed)

x0 = bolib.util.random_sample(of.get_bounds(), batch_size=10)

bo.minimize(
    of.evaluate, x0,
    bounds=of.get_bounds(),
    tol=1e-7,
    maxiter=of.get_max_eval(),
    disp=True
)
  • BOlib is also Scipy compatible.
import scipy.optimize as spo

result = spo.minimize(
    of.evaluate,
    x0,
    bounds=of.get_bounds(),
    method=bo.minimize,
    tol=1e-7,
    options={
        'maxiter': of.get_max_eval(),
        'disp': True
    }
)
  • There are more examples in examples/ directory. Check them out!

Develop BOlib

  • Download the repository using git
git clone https://github.com/ibaidev/bolib.git
cd bolib
git config user.email 'MAIL'
git config user.name 'NAME'
git config credential.helper 'cache --timeout=300'
git config push.default simple
  • Update API documentation
source ./.env/bin/activate
pip install Sphinx
cd docs/
sphinx-apidoc -f -o ./ ../bolib

Release history Release notifications

This version
History Node

0.19.15

History Node

0.19.14

History Node

0.19.13

History Node

0.19.12

History Node

0.19.11

History Node

0.19.10

History Node

0.19.7

History Node

0.19.5

History Node

0.19.4

History Node

0.19.3

History Node

0.19.2

History Node

0.19.1

History Node

0.19.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
bolib-0.19.15-py2.py3-none-any.whl (22.9 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Apr 4, 2018
bolib-0.19.15.tar.gz (22.7 kB) Copy SHA256 hash SHA256 Source None Apr 4, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page