-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathindex_bayesian.py
More file actions
36 lines (28 loc) · 890 Bytes
/
index_bayesian.py
File metadata and controls
36 lines (28 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Bayesian optimization example for index page.
This snippet demonstrates Bayesian optimization with a more complex
objective function shown on the landing page. It is included in index.rst.
"""
# [start:full_example]
import numpy as np
from hyperactive.opt.gfo import BayesianOptimizer
def complex_objective(params):
x = params["x"]
y = params["y"]
return -((x - 2) ** 2 + (y + 1) ** 2) + np.sin(x * y)
search_space = {
"x": np.linspace(-5, 5, 100),
"y": np.linspace(-5, 5, 100),
}
optimizer = BayesianOptimizer(
search_space=search_space,
n_iter=5,
experiment=complex_objective,
)
best_params = optimizer.solve()
# [end:full_example]
if __name__ == "__main__":
print(f"Best parameters: {best_params}")
# Verify we got valid parameters
assert "x" in best_params
assert "y" in best_params
print("Index Bayesian example passed!")