bayesian-optimization

repository·master·Indexed 26 days ago

https://github.com/bayesian-optimization/bayesianoptimization

A pure Python implementation of Bayesian global optimization using Gaussian processes, designed for constrained optimization of high-cost functions. Version 3.3.0 provides tools to find maximum values in few iterations using acquisition functions such as UpperConfidenceBound, ExpectedImprovement, and ProbabilityOfImprovement. It includes the BayesianOptimization class for the primary interface, ConstraintModel for incorporating constraints, and SequentialDomainReductionTransformer for narrowing search spaces.

Tokens
1.4K
Snippets
2
Records
15
Agent score
92%

What's inside bayesian-optimization

  1. Overview of Bayesian Optimization capabilities

    master
    The bayesian-optimization package is a pure Python implementation of constrained global optimization using Gaussian processes. It is designed to find the maximum value of an unknown, high-cost function in as few iterations as possible by balancing exploration and exploitation using acquisition functions (like UCB or EI).
  2. Initialize BayesianOptimization and run maximize

    master

    To perform Bayesian optimization, you must define a function to maximize and a dictionary of parameter bounds (pbounds).

    1. Define the function: The function f must take a known set of parameters and return a real number.
    2. Define bounds: Provide a dictionary where keys are parameter names and values are tuples representing the (min, max) range.
    3. Instantiate BayesianOptimization: Pass the function, bounds, and an optional random_state.
    4. Call maximize: Use the maximize method to run the optimization process.

    Key maximize parameters:

    • init_points: Number of initial random exploration steps.
    • n_iter: Number of steps of bayesian optimization to perform.
    from bayes_opt import BayesianOptimization
    
    # 1. Define the function to be optimized
    def black_box_function(x, y):
        return -x ** 2 - (y - 1) ** 2 + 1
    
    # 2. Define the bounded region of parameter space
    pbounds = {'x': (2, 4), 'y': (-3, 3)}
    
    # 3. Instantiate the optimizer
    optimizer = BayesianOptimization(
        f=black_box_function,
        pbounds=pbounds,
        random_state=1,
    )
    
    # 4. Run the optimization
    optimizer.maximize(
        init_points=2,
        n_iter=3,
    )
  3. Use SequentialDomainReductionTransformer for domain reduction

    master
    The bayes_opt.SequentialDomainReductionTransformer class allows you to perform sequential domain reduction during the optimization process. This is useful for narrowing down the search space of your parameters as the optimization progresses. For a complete implementation guide, refer to the Sequential Domain Reduction notebook in the project documentation.
  4. Use ConstraintModel for constrained optimization

    master

    The bayes_opt.ConstraintModel class allows you to incorporate constraints into the Bayesian Optimization process. This is used when the objective function must satisfy certain conditions within the parameter space.

    For a complete implementation guide and practical application, refer to the Constrained Optimization notebook in the documentation.

  5. Use acquisition functions in bayesian-optimization

    master

    The bayes_opt.acquisition module provides various acquisition functions used to decide which point in the parameter space to sample next during the Bayesian Optimization process. You can use these classes to implement different exploration-exploitation strategies.

    Available acquisition function implementations include:

    • UpperConfidenceBound (UCB)
    • ProbabilityOfImprovement (PI)
    • ExpectedImprovement (EI)
    • GPHedge
    • ConstantLiar