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.2.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.2-py3-none-any.whl (29.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bonni-1.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 26d2946684710f61d2e59b6d500507f617d771f6e13a0b890926e972f9db2616
MD5 5400a1923268e4b4cb4dd417263fb67b
BLAKE2b-256 ac12de0b2e8287374dc7a893814497856eda55f16d87b427543ba9b104b02761

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: bonni-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 29.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.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ec47861d7e9d93f1352cdb865631c2258d5e2014b3e55aecf780bd7e6113a783
MD5 cef7ee0555f202ac6f045572cc621f14
BLAKE2b-256 512927f8d550bc0383205826bb38f5800f5f5ee0321dddaeb278a950a4a9ca95

See more details on using hashes here.

Provenance

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