Skip to main content

BONNI: Bayesian Optimization via Neural Network surrogates and Interior Point Optimization

Project description

title image

Documentation PyPI version

BONNI: Bayesian Optimization via Neural Network surrogates and Interior Point Optimization

BONNI optimizes any black box function WITH gradient information. Especially in optimizations with many degree of freedom, gradient-information increases optimization speed. In the image, the surrogate fits the function almost perfectly with few observations.

surrogate image

Installation

You can install BONNI simply via

pip install bonni

We recommend installing also the GPU-acceleration from JAX, which will massively increase speed:

pip install jax[cuda]

Usage

BONNI provides a nice optimization wrapper similar to the scipy.minimize API:

from bonni import optimize_bonni
from pathlib import Path
import numpy as np

def fn(x: np.ndarray):
    # Input function should return function value and gradient
    value = x[0] ** 2 + x[1]
    grad = np.asarray([2 * x[0], 1])
    return value, grad

xs, ys, gs = optimize_bonni(
    fn=fn,
    bounds=np.asarray([[-1, 1], [0, 1]], dtype=float),
    # BO requires some samples before iterations start. You can either explicitly provide 
    # previous fn evals via `xs=..., ys=..., gs=... or specify a number of random samples. 
    num_bonni_iterations=5,
    num_random_samples=2,
    direction="minimize",
    save_path=Path.cwd(), # save data as npz here
    seed=42,
)

Additionally, BONNI includes a convenient wrapper for IPOPT. The standard IPOPT package can be difficult to install/use, so we created a convenient wrapper shown below:

from bonni import optimize_ipopt
xs, ys, gs = optimize_ipopt(
    fn=fn,
    x0=np.asarray([0.5, 0.5]),  # startpoint of optimization
    bounds=np.asarray([[-1, 1], [0, 1]], dtype=float),
    # IPOPT performs line search each iteration, such that the number 
    # of iterations and fn_eval may not be the same
    max_fn_eval=5,
    max_iterations=3,
    direction="maximize",
    save_path=Path.cwd(),
)

Documentation

You can find the full extensive documentation of BONNI here.

Citation

If you find this repository helpful for your research, please consider citing:

TODO insert citation as soon as paper online.

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

bonni-1.0.0.tar.gz (2.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bonni-1.0.0-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file bonni-1.0.0.tar.gz.

File metadata

  • Download URL: bonni-1.0.0.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bonni-1.0.0.tar.gz
Algorithm Hash digest
SHA256 09302e2a0c5fe7844cb321bf607abc9f1456b5b28073e289d84072c757924a82
MD5 87e2e9e27accece7bc42bc5e070dc2a4
BLAKE2b-256 33076f09fbb172a6c230b847aff304ddca8ed7700a1e4cf07bdc087ac344550a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bonni-1.0.0.tar.gz:

Publisher: publish.yml on ymahlau/bonni

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bonni-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: bonni-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bonni-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba7997b6f2803ddc70170febd702ad21898b8618cec30f0f2552818707ab98e7
MD5 9df629ae05c473a582b05d8f4cac4271
BLAKE2b-256 30194407db4b8aea8a1ede361afdd1c9dfda4927ca00d335a07d70266c46df3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for bonni-1.0.0-py3-none-any.whl:

Publisher: publish.yml on ymahlau/bonni

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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