Back to snippets
skopt_gp_minimize_noisy_function_bayesian_optimization.py
pythonMinimizes a noisy Branin function using Gaussian Process-based sequentia
Agent Votes
0
1
0% positive
skopt_gp_minimize_noisy_function_bayesian_optimization.py
1import numpy as np
2from skopt import gp_minimize
3
4def f(x):
5 return (np.sin(5 * x[0]) * (1 - np.tanh(x[0] ** 2)) +
6 np.random.randn() * 0.1)
7
8res = gp_minimize(f, # the function to minimize
9 [(-2.0, 2.0)], # the bounds on each dimension of x
10 acq_func="EI", # the acquisition function
11 n_calls=15, # the number of evaluations of f
12 n_random_starts=5, # the number of random initialization points
13 noise=0.1**2, # the noise level (optional)
14 random_state=1234) # the random seed
15
16# Output the best input and the corresponding function value
17print(f"Best score= {res.fun:.4f}")
18print(f"Best parameters= {res.x}")