πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
Search courses…
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Bayesian Optimization: Sequential Model-Based Optimization

Machine LearningBayesian Optimization: Sequential Model-Based Optimization🟒 Free Lesson

Advertisement

Bayesian Optimization: Sequential Model-Based Optimization

Module: Machine Learning | Difficulty: Advanced

Optimization Problem

where is a black-box function.

Gaussian Process Surrogate

Expected Improvement (EI)

where

Upper Confidence Bound (UCB)

Knowledge Gradient

import numpy as np
from scipy.optimize import minimize as sp_minimize

class BayesianOptimizer:
    def __init__(self, bounds, n_initial=5):
        self.bounds = np.array(bounds)
        self.n_initial = n_initial
        self.X_observed = []
        self.y_observed = []
    def _expected_improvement(self, X, y_best, gp):
        mu, var = gp.predict(X)
        sigma = np.sqrt(var + 1e-9)
        z = (mu - y_best) / sigma
        ei = (mu - y_best) * norm.cdf(z) + sigma * norm.pdf(z)
        return ei
    def suggest(self, gp):
        if len(self.X_observed) < self.n_initial:
            return np.random.uniform(self.bounds[:,0], self.bounds[:,1])
        y_best = max(self.y_observed)
        result = sp_minimize(lambda x: -self._expected_improvement(x.reshape(1,-1), y_best, gp),
                           x0=np.random.uniform(self.bounds[:,0], self.bounds[:,1]),
                           bounds=self.bounds)
        return result.x

Research Insight: Bayesian optimization is most sample-efficient when the function is expensive to evaluate (e.g., neural network hyperparameters). The EI acquisition function is optimal under the assumption that the GP model is correct.

Need Expert Machine Learning Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement