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.1.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.1.0-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bonni-1.1.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.1.0.tar.gz
Algorithm Hash digest
SHA256 b501cc24870429a100e7d959d2fcf7d70f29424be0e8da833325abbcc5d29ce5
MD5 89b3a6f7c4263e3709f222a642d1b94b
BLAKE2b-256 7bd1e2aa9c1d2451710532f41a911eb2daf862be2cc249beb261ec43572a08a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for bonni-1.1.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: bonni-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.2 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25dd5dcc6c4896a530037df4d104fee7828eefc54f1530554013ff0905426a20
MD5 8fc6562200056be3b1963c44ee1c563f
BLAKE2b-256 f380965dff7606e8f206d915f8ac4a506473d67722864ba3d9b6c7113d9e9888

See more details on using hashes here.

Provenance

The following attestation bundles were made for bonni-1.1.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