Bayesian optimization
How Bayesian optimization uses a probabilistic surrogate and an acquisition function to find the best settings of an expensive experiment or simulation with as few evaluations as possible.
What it is
Bayesian optimization (BO) is a strategy for finding the maximum or minimum of a function that is expensive to evaluate, has no known formula or gradient, and may be noisy, a so-called black-box function. Each evaluation might be a laboratory experiment that takes a day, a simulation that runs for hours, or the training of a neural network. BO builds a statistical surrogate model of the function from the evaluations made so far, most often a Gaussian process (see Gaussian processes), and uses it to choose the most promising next point to test, balancing exploration of uncertain regions against exploitation of regions already known to be good. It now drives self-driving laboratories, materials and molecule discovery, process optimization and engineering design.
It answers questions such as: Which temperature, concentration and time give the highest yield, after only 30 experiments instead of 3,000? Which hyperparameters make this model most accurate? Which composition has the best property? Where should the next, costly measurement be placed? BO is most useful when the budget is tens to hundreds of evaluations and dimensions are fewer than about 20.
Fundamentals
The loop: surrogate, acquisition, evaluate, update
Bayesian optimization repeats four steps. (1) Start with a small initial design (random, Latin hypercube or Sobol points, about 5 to 10 points per dimension, or existing data). (2) Fit a probabilistic surrogate to all observed pairs (xi, yi); it returns for any new point x a predicted mean μ(x) and an uncertainty σ(x). (3) Maximize an acquisition function α(x), a cheap function derived from μ and σ that scores how useful it would be to evaluate x next, to select the next experiment. (4) Run the expensive evaluation at that point, add the result to the data, and repeat until the budget is spent or improvement stalls. Because the surrogate and acquisition function are cheap, the extra computation per iteration is small compared to the cost of one real evaluation.
Acquisition functions
- Expected improvement (EI) (for maximization, with f* the best value so far): EI(x) = (μ − f* − ξ)Φ(Z) + σφ(Z), with Z = (μ − f* − ξ)/σ, where Φ and φ are the standard normal distribution and density functions, and ξ ≥ 0 a small exploration parameter. It is the most common default and has a closed form.
- Upper confidence bound (UCB): α = μ + κσ, with κ (often 1 to 3) controlling exploration; for minimization the lower confidence bound.
- Probability of improvement (PI): the chance of beating the current best, which tends to over-exploit.
- Thompson sampling: draw one random function from the surrogate and optimize it; well suited to parallel batches.
All balance exploitation (high μ) and exploration (high σ). Maximizing α is itself a small optimization problem, solved by multistart gradient methods or evolutionary search.
Surrogates, kernels and extensions
The default surrogate is a Gaussian process with a Matérn 5/2 kernel and automatic relevance determination length scales, with inputs scaled to the unit cube and outputs standardized; hyperparameters are fitted by maximum likelihood or marginal likelihood. Because exact GPs cost O(n3), they suit up to a few thousand points. Alternatives: random forests (SMAC) and tree-structured Parzen estimators (TPE) (Hyperopt, Optuna), which handle categorical, conditional and mixed variables well, and Bayesian neural networks. Extensions cover many realistic needs: batch BO (q-EI) to run several experiments in parallel; constrained BO (modeling constraints with their own surrogates, for example safety or feasibility); multi-objective BO (expected hypervolume improvement, finding a Pareto front); multi-fidelity BO (combining cheap approximate and costly accurate evaluations); noisy evaluations; high-dimensional BO (trust regions as in TuRBO, random embeddings, sparse priors); transfer and meta-learning across related tasks; and human-in-the-loop approaches that include expert knowledge as priors.
Practical considerations and limits
BO works best when the response surface is smooth and the dimension is modest. Define the search space carefully (bounds, log scales for parameters spanning orders of magnitude, categorical choices, constraints between variables); a bad space limits the result more than any algorithm choice. Check the surrogate: plot or cross-validate it, since a poor model leads to poor suggestions. The noise level of experiments should be modeled (repeat measurements if needed), and the best observed value is not necessarily the true optimum when noise is large. Compare against baselines such as random search and Latin hypercube sampling with the same budget, because on rough, high-dimensional or very cheap problems random or evolutionary search may do as well (see genetic algorithms and particle swarm optimization). BO finds good solutions, not guaranteed global optima.
Software, typical applications and limits
Applications: tuning chemical reactions in automated platforms, searching for materials with target properties, optimizing battery electrolytes and alloy compositions, calibrating simulation models, designing aerodynamic shapes, and machine-learning hyperparameters (see AutoML). Limits: poor scaling to hundreds of dimensions, sensitivity to the quality of the surrogate, sequential nature (reduced by batching), and difficulty with discontinuous or very noisy functions.
Basic operation
- Define the objective and search space. Set the measure to optimize, parameters with bounds and any constraints.
- Choose an initial design. Run a space-filling set of experiments, or use existing data.
- Fit the surrogate. Train a Gaussian process or other model on the results.
- Maximize the acquisition function. Pick the next point, or a batch of points, to evaluate.
- Run the experiment or simulation. Record the result and any noise estimate.
- Update and repeat. Refit the surrogate and continue until the budget is used.
- Verify the best result. Repeat the best settings and compare with a baseline.
- Collect the output. You obtain the best settings and the convergence history; acquisition tuning and batch strategies are covered in the video.
Good practice
- Compare with random search. Same budget, same space.
- Scale inputs and outputs. Use log scales where appropriate.
- Check the surrogate. Validate it before trusting suggestions.
- Model noise. Repeat the best experiments to confirm.
- Keep a record. Save every evaluation and the random seeds.
- Constrain unsafe regions. In automated labs, encode safety limits as hard constraints and keep a human able to stop the loop, so that suggested experiments cannot create hazardous conditions.
Key terms
- Black-box function — a function that can be evaluated but has no known formula or gradient.
- Surrogate model — a cheap statistical model of the expensive function.
- Acquisition function — a score that decides which point to evaluate next.
- Expected improvement — the expected gain over the best value found so far.
- Exploration vs. exploitation — sampling uncertain regions versus refining promising ones.
- Pareto front — the set of best trade-offs in multi-objective problems.
- Multi-fidelity — combining cheap approximate evaluations with accurate costly ones.
Video coming soon
About five minutes on Bayesian optimization: how it works in detail, how the data is acquired, and how it is analyzed.
More in 4.3 AI and Machine Learning
- Regularized linear models
- Decision trees and random forests
- Gradient boosting (XGBoost)
- Support vector machines
- k-NN
- k-means
- Gaussian processes
- Neural networks
- CNNs
- RNN/LSTM
- Transformers
- Autoencoders
- GANs
- Diffusion models
- Graph neural networks
- Reinforcement learning
- Transfer learning
- Federated learning
- Explainable AI (SHAP, LIME)
- Physics-informed neural networks
- Bayesian optimization
- Active learning
- Symbolic regression
- Genetic algorithms and particle swarm optimization
- Dimensionality reduction (t-SNE, UMAP)
- NLP and large language models
- Retrieval-augmented generation
- Computer vision (detection, segmentation)
- Anomaly detection
- Machine-learned interatomic potentials
- AutoML
