Emukit

raw JSON →
0.5.1 verified Fri May 01 auth: no python

A Python toolkit for decision-making under uncertainty, including Bayesian optimization, experimental design, and quadrature. Current version 0.5.1, requires Python >=3.10. Released approximately twice per year since 2018.

pip install emukit
error ModuleNotFoundError: No module named 'emukit.bayesian_optimization'
cause Import path is wrong; the correct import is from emukit.bayesian_optimization.loops.
fix
Use: from emukit.bayesian_optimization.loops import BayesianOptimizationLoop
error AttributeError: module 'emukit' has no attribute 'model_wrappers'
cause Misspelled 'emukit' or installed the wrong package; also GPy may be missing.
fix
pip install emukit[gpy] or pip install emukit[sklearn] for sklearn wrapper.
error ValueError: The number of points in X and Y must be the same
cause Passed X and Y arrays with mismatched first dimension.
fix
Ensure X.shape[0] == Y.shape[0]; both must be 2D arrays (n_samples, n_dims).
error ImportError: cannot import name 'GPyModel' from 'emukit.model_wrappers'
cause Incorrect class name; should be GPyModelWrapper.
fix
Use: from emukit.model_wrappers import GPyModelWrapper
breaking Emukit 0.5.0 dropped support for Python <3.10. Also, numpy>=2.0 compatibility now requires using emukit core without GPy (GPy is pinned to numpy<2.0).
fix Upgrade to Python >=3.10. For numpy>=2.0, install emukit without gpy extra and use sklearn GP wrapper instead.
gotcha The GPy model wrapper in emukit.model_wrappers.GPyModel expects X and Y arrays; do not pass GPy objects directly.
fix Use from emukit.model_wrappers import GPyModelWrapper and pass numpy arrays.
gotcha BayesianOptimizationLoop requires the 'get_next_points' method to receive a list of (X, Y) tuples, not just the model.
fix Pass loop.get_next_points([X, Y]) with X and Y as 2D arrays.
pip install emukit[gpy]
pip install emukit[sklearn]

Minimal Bayesian optimization loop using Emukit with a GPy model.

import numpy as np
from emukit.core import ContinuousParameter, ParameterSpace
from emukit.model_wrappers import GPyModelWrapper
from emukit.bayesian_optimization.loops import BayesianOptimizationLoop
from emukit.core.acquisition import ExpectedImprovement

# Define a simple objective
def objective(x):
    return x**2

# Parameter space
space = ParameterSpace([ContinuousParameter('x', -5, 5)])

# Initial data
X_init = np.random.uniform(-5, 5, (3, 1))
Y_init = objective(X_init)

# Model
gpy_model = GPyModelWrapper(X_init, Y_init)

# Acquisition function
ei = ExpectedImprovement()

# Optimization loop
loop = BayesianOptimizationLoop(space, gpy_model, acquisition=ei)

# Run one iteration
new_x = loop.get_next_points([X_init, Y_init])
print('Suggested next point:', new_x)