You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: v/latest/files/closed_loop_botorch_only.py
+40-37Lines changed: 40 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
#!/usr/bin/env python3
2
2
# coding: utf-8
3
3
4
-
# ## Closed-loop batch, constrained BO in BoTorch with qEI and qNEI
4
+
# ## Closed-loop batch, constrained BO in BoTorch with qLogEI and qLogNEI
5
5
#
6
6
# In this tutorial, we illustrate how to implement a simple Bayesian Optimization (BO) closed loop in BoTorch.
7
7
#
@@ -10,7 +10,7 @@
10
10
# However, you may want to do things that are not easily supported in Ax at this time (like running high-dimensional BO using a VAE+GP model that you jointly train on high-dimensional input data). If you find yourself in such a situation, you will need to write your own optimization loop, as we do in this tutorial.
11
11
#
12
12
#
13
-
# We use the batch Expected Improvement (qEI) and batch Noisy Expected Improvement (qNEI) acquisition functions to optimize a constrained version of the synthetic Hartmann6 test function. The standard problem is
13
+
# We use the batch Log Expected Improvement (`qLogEI`) and batch Noisy Expected Improvement (`qLogNEI`) acquisition functions to optimize a constrained version of the synthetic Hartmann6 test function. The standard problem is
# Since botorch assumes a maximization problem, we will attempt to maximize $-f(x)$ to achieve $\max_{x} -f(x) = 3.32237$.
22
22
23
-
# In[1]:
23
+
# In[14]:
24
24
25
25
26
26
importos
@@ -37,7 +37,7 @@
37
37
#
38
38
# First, we define the constraint used in the example in `outcome_constraint`. The second function `weighted_obj` is a "feasibility-weighted objective," which returns zero when not feasible.
39
39
40
-
# In[2]:
40
+
# In[15]:
41
41
42
42
43
43
frombotorch.test_functionsimportHartmann
@@ -62,13 +62,14 @@ def weighted_obj(X):
62
62
#
63
63
# Each component is a `FixedNoiseGP`. The models are initialized with 10 points drawn randomly from $[0,1]^6$.
# #### Define a construct to extract the objective and constraint from the GP
104
111
# The methods below take the outputs of the GP and return the objective and the constraint. In general, these can be any `Callable`, but here we simply need to index the correct output.
# #### Define a helper function that performs the essential BO step
128
130
# The helper function below takes an acquisition function as an argument, optimizes it, and returns the batch $\{x_1, x_2, \ldots x_q\}$ along with the observed function values. For this example, we'll use a small batch of $q=3$. The function `optimize_acqf` optimizes the $q$ points jointly. A simple initialization heuristic is used to select the 10 restart initial locations from a set of 50 random points.
# The plot below shows the best objective value observed at each step of the optimization for each of the algorithms. The confidence intervals represent the variance at that step in the optimization across the trial runs. The variance across optimization runs is quite high, so in order to get a better estimate of the average performance one would have to run a much larger number of trials `N_TRIALS` (we avoid this here to limit the runtime of this tutorial).
0 commit comments