Skip to content

Bayesian Optimizer

Probabilistic

Bayesian Optimization (BO) using Gaussian Process surrogates.

Algorithm Overview

This module implements Bayesian Optimization, a probabilistic optimization technique using Gaussian Process surrogate models.

The algorithm builds a probabilistic model of the objective function and uses it to select promising points to evaluate.

Usage

python
from opt.probabilistic.bayesian_optimizer import BayesianOptimizer
from opt.benchmark.functions import sphere

optimizer = BayesianOptimizer(
    func=sphere,
    lower_bound=-5.12,
    upper_bound=5.12,
    dim=10,
    max_iter=500,
)

best_solution, best_fitness = optimizer.search()
print(f"Best solution: {best_solution}")
print(f"Best fitness: {best_fitness:.6e}")

Parameters

ParameterTypeDefaultDescription
funcCallableRequiredObjective function to minimize.
lower_boundfloatRequiredLower bound of search space.
upper_boundfloatRequiredUpper bound of search space.
dimintRequiredProblem dimensionality.
n_initialint10Number of initial random samples to build GP surrogate.
max_iterint50Maximum Bayesian optimization iterations after initial sampling.
xifloat0.01Exploration parameter for Expected Improvement acquisition.
seedint | NoneNoneRandom seed for reproducibility.

Algorithm Metadata

PropertyValue
Algorithm NameBayesian Optimization
AcronymBO
Year Introduced2012
AuthorsSnoek, Jasper; Larochelle, Hugo; Adams, Ryan P.
Algorithm ClassProbabilistic
ComplexityO(n³) per iteration (GP regression)
PropertiesStochastic, Adaptive
ImplementationPython 3.10+
COCO CompatibleYes

Mathematical Formulation

Bayesian Optimization models the objective function using a Gaussian Process (GP) posterior:

f(x)GP(μ(x),k(x,x))

where:

  • μ(x) is the posterior mean function
  • k(x,x) is the covariance kernel (RBF/squared exponential)
  • f(x) is the unknown objective function

Acquisition Function (Expected Improvement):

EI(x)=E[max(fbestf(x),0)]EI(x)=(μ(x)fbestξ)Φ(Z)+σ(x)ϕ(Z)

where:

  • Φ is the standard normal CDF
  • ϕ is the standard normal PDF
  • Z=μ(x)fbestξσ(x)
  • ξ is the exploration parameter
  • σ(x) is the posterior standard deviation

Constraint handling:

  • Boundary conditions: Clamping to bounds during optimization
  • Feasibility enforcement: Bounds enforced in acquisition function optimization

Hyperparameters

ParameterDefaultBBOB RecommendedDescription
n_initial102*dimInitial random samples
max_iter50100-500Maximum BO iterations
xi0.010.01-0.1Exploration-exploitation param

Sensitivity Analysis:

  • n_initial: High impact - More initial samples improve GP accuracy
  • max_iter: Medium impact - BO converges quickly with good surrogate
  • xi: Medium impact - Balances exploration vs exploitation
  • Recommended tuning ranges: ξ[0.001,0.1], ninitial[2d,5d]

COCO/BBOB Benchmark Settings

Search Space:

  • Dimensions tested: 2, 3, 5, 10, 20, 40
  • Bounds: Function-specific (typically [-5, 5] or [-100, 100])
  • Instances: 15 per function (BBOB standard)

Evaluation Budget:

  • Budget: dim×10000 function evaluations
  • Independent runs: 15 (for statistical significance)
  • Seeds: 0-14 (reproducibility requirement)

Performance Metrics:

  • Target precision: 1e-8 (BBOB default)
  • Success rate at precision thresholds: [1e-8, 1e-6, 1e-4, 1e-2]
  • Expected Running Time (ERT) tracking

Raises

ValueError: If search space is invalid or function evaluation fails.

Notes

  • Uses self.seed for all random number generation
  • BBOB: Returns final best solution after max_iter evaluations
  • GP regression may fail for ill-conditioned data

Computational Complexity:

  • Time per iteration: O(n3) for GP regression with n observations
  • Space complexity: O(n2) for covariance matrix storage
  • BBOB budget usage: Typically 10-30% of dim*10000 budget due to expensive GP updates

BBOB Performance Characteristics:

  • Best function classes: Smooth unimodal functions (Sphere, Ellipsoid, Rosenbrock)
  • Weak function classes: High-dimensional multimodal, discontinuous functions
  • Typical success rate at 1e-8 precision: 40-60% (dim=5)
  • Expected Running Time (ERT): Competitive on smooth functions, poor on rugged landscapes

Convergence Properties:

  • Convergence rate: Problem-dependent, typically sub-linear to linear
  • Local vs Global: Global search capability via acquisition function
  • Premature convergence risk: Low - EI balances exploration/exploitation

Probabilistic Concepts:

  • Prior: Gaussian Process with RBF kernel as function prior
  • Likelihood: Gaussian observation model with noise variance
  • Posterior: GP posterior updated with observed data (xi,f(xi))
  • Acquisition: Expected Improvement quantifies value of evaluating point

Reproducibility:

  • Deterministic: Yes - Same seed guarantees identical results
  • BBOB compliance: seed parameter required for 15 independent runs
  • Initialization: Uniform random sampling in [lower_bound, upper_bound]
  • RNG usage: numpy.random.default_rng(self.seed) throughout

Implementation Details:

  • Parallelization: Not supported (sequential acquisition)
  • Constraint handling: Clamping to bounds in acquisition optimization
  • Numerical stability: Cholesky decomposition with fallback to mean/std defaults
  • Kernel: RBF (squared exponential) with length_scale=1.0

Known Limitations:

  • Computational cost scales poorly with evaluation count (O(n3))
  • GP regression may fail for near-duplicate points (add jitter if needed)
  • Not suitable for high-dimensional problems (dim > 20)
  • BBOB known issues: Slow convergence on ill-conditioned problems

Version History:

  • v0.1.0: Initial implementation
  • v0.1.2: Current version with BBOB compliance

References

[1] Snoek, J., Larochelle, H., & Adams, R. P. (2012). "Practical Bayesian Optimization of Machine Learning Algorithms." Advances in Neural Information Processing Systems 25 (NIPS 2012). https://papers.nips.cc/paper/2012/hash/05311655a15b75fab86956663e1819cd-Abstract.html

[2] Hansen, N., Auger, A., Ros, R., Mersmann, O., Tušar, T., Brockhoff, D. (2021). "COCO: A platform for comparing continuous optimizers in a black-box setting." Optimization Methods and Software, 36(1), 114-144. https://doi.org/10.1080/10556788.2020.1808977

COCO Data Archive:

Implementation:

  • Original paper code: Not publicly available
  • This implementation: Based on [1] with RBF kernel and EI acquisition

See Also

SequentialMonteCarloOptimizer: Population-based probabilistic method BBOB Comparison: SMC more robust on multimodal, BO faster on smooth unimodal

ParzenTreeEstimator: Tree-structured Parzen estimator (TPE) for hyperparameter optimization BBOB Comparison: TPE similar convergence, less computational cost than BO

AbstractOptimizer: Base class for all optimizers opt.benchmark.functions: BBOB-compatible test functions

Related BBOB Algorithm Classes:

  • Probabilistic: AdaptiveMetropolisOptimizer, SequentialMonteCarloOptimizer
  • Gradient: AdamW, SGDMomentum
  • Metaheuristic: SimulatedAnnealing, HarmonySearch

Benchmark Performance

Interactive fitness landscape of a representative multimodal benchmark function (drag to rotate, scroll to zoom):

Run-based charts

Convergence, distribution and ECDF charts appear here once this optimizer is included in the benchmark suite.


Source Code

View the implementation: bayesian_optimizer.py

Released under the MIT License.