Skip to main content

Python library for Bayesian Optimization.

Project description

BOlib

A python library for Bayesian Optimization.

Setup BOlib

  • Create and activate virtualenv (for python2) or venv (for python3)
  # for python3
  python3 -m venv .env
  # or for python2
  python2 -m virtualenv .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.dm.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=5)

  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


Download files

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

Source Distribution

bolib-0.21.0.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

bolib-0.21.0-py2.py3-none-any.whl (34.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file bolib-0.21.0.tar.gz.

File metadata

  • Download URL: bolib-0.21.0.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for bolib-0.21.0.tar.gz
Algorithm Hash digest
SHA256 c6f5b2c4026376bb84f305f8bbd806d98ebd53dfda9d4d2e31b55062af2ed715
MD5 8f095fadf51356f7833af5bbc026b143
BLAKE2b-256 9aa840da6e5fbd45a59e6eeec2133817885059b36faf5733bf0ed7024180b7ff

See more details on using hashes here.

File details

Details for the file bolib-0.21.0-py2.py3-none-any.whl.

File metadata

  • Download URL: bolib-0.21.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 34.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for bolib-0.21.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 dd881606dc9073cc40c25231499b6c74b9451332e7658712d36016f8fb662dde
MD5 da36cabea3d4b07ab4ab13cc8e8427d0
BLAKE2b-256 008c8060c0a13e54a50c73d682627753e2dec066ace837676cdd18f8c9cfb6b6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page