Skip to content

Commit

Permalink
notebook fixes (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
hstojic authored Nov 23, 2021
1 parent 7e4e0ac commit 2c9d545
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/notebooks/active_learning.pct.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# %% [markdown]
# ## Surrogate model
#
# Just like in sequential optimization, we fit a surrogate Gaussian process model as implemented in GPflow to the initial data. The GPflow models cannot be used directly in our Bayesian optimization routines, so we build a GPflow's `GPR` model from and pass it to the `GaussianProcessRegression` wrapper.
# Just like in sequential optimization, we fit a surrogate Gaussian process model as implemented in GPflow to the initial data. The GPflow models cannot be used directly in our Bayesian optimization routines, so we build a GPflow's `GPR` model and pass it to the `GaussianProcessRegression` wrapper.

# %%
import gpflow
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/batch_optimization.pct.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# %% [markdown]
# ## Surrogate model
#
# Just like in purely sequential optimization, we fit a surrogate Gaussian process model to the initial data. The GPflow models cannot be used directly in our Bayesian optimization routines, so we build a GPflow's `GPR` model from and pass it to the `GaussianProcessRegression` wrapper.
# Just like in purely sequential optimization, we fit a surrogate Gaussian process model to the initial data. The GPflow models cannot be used directly in our Bayesian optimization routines, so we build a GPflow's `GPR` model and pass it to the `GaussianProcessRegression` wrapper.

# %%
import gpflow
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/data_transformation.pct.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
# %% [markdown]
# ## Model the objective function
#
# The Bayesian optimization procedure estimates the next best points to query by using a probabilistic model of the objective. We'll use a Gaussian process (GP) model, built using GPflow. The GPflow models cannot be used directly in our Bayesian optimization routines, so we build a GPflow's `GPR` model from and pass it to the `GaussianProcessRegression` wrapper.
# The Bayesian optimization procedure estimates the next best points to query by using a probabilistic model of the objective. We'll use a Gaussian process (GP) model, built using GPflow. The GPflow models cannot be used directly in our Bayesian optimization routines, so we build a GPflow's `GPR` model and pass it to the `GaussianProcessRegression` wrapper.
#
# Here as the first example, we model the objective function using the original data, without performing any data transformation. In the next example we will model it using normalised data. We also put priors on the parameters of our GP model's kernel in order to stabilize model fitting. We found the priors below to be highly effective for objective functions defined over the unit hypercube and with an output normalised to have zero mean and unit variance. Since the non-normalised data from the original objective function comes with different scaling, we rescale the priors based on approximate standard deviation of inputs and outputs.

Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/inequality_constraints.pct.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def observer(query_points):
# %% [markdown]
# ## Modelling the two functions
#
# We'll model the objective and constraint data with their own Gaussian process regression model, as implemented in GPflow. The GPflow models cannot be used directly in our Bayesian optimization routines, so we build a GPflow's `GPR` model from and pass it to the `GaussianProcessRegression` wrapper.
# We'll model the objective and constraint data with their own Gaussian process regression model, as implemented in GPflow. The GPflow models cannot be used directly in our Bayesian optimization routines, so we build a GPflow's `GPR` model and pass it to the `GaussianProcessRegression` wrapper.

# %%
import gpflow
Expand Down
28 changes: 9 additions & 19 deletions docs/notebooks/model_config.pct.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,22 @@ def build_model(data):
# %%
from copy import deepcopy

from trieste.models.gpflux import DeepGaussianProcess, build_vanilla_deep_gp
from gpflow.models import SVGP


def build_gp_model(data):
def build_gpr_model(data):
variance = tf.math.reduce_variance(data.observations)
kernel = gpflow.kernels.Matern52(variance=variance, lengthscales=[0.2, 0.2])
model = GPR(data.astuple(), kernel, noise_variance=1e-5)
return model


def build_dgp_model(data):
def build_svgp_model(data):
inputs = data.query_points
variance = tf.math.reduce_variance(data.observations)
dgp = build_vanilla_deep_gp(data.query_points, num_layers=2, num_inducing=100)
dgp.f_layers[-1].kernel.kernel.variance.assign(variance)
dgp.f_layers[-1].mean_function = gpflow.mean_functions.Constant()
dgp.likelihood_layer.likelihood.variance.assign(1e-5)
return dgp
kernel = gpflow.kernels.Matern52(variance=variance, lengthscales=[0.2, 0.2])
model = SVGP(kernel, gpflow.likelihoods.Gaussian(), inputs[:2], num_data=len(inputs))
return model


def run_experiment(model_config):
Expand All @@ -154,21 +153,12 @@ def run_experiment(model_config):


# configuration shared by all experiments, this is modified by each experiment condition
basic_config = {
"model": gpflow_model,
"model_args": {
"num_kernel_samples": 100,
},
"optimizer": gpflow.optimizers.Scipy(),
"optimizer_args": {
"minimize_args": {"options": dict(maxiter=100)},
},
}
basic_config = {"model": build_gpr_model(initial_data)}

# here we specify our experiments
experiment_conditions = [
{"model_args": {"num_kernel_samples": 50}},
{"model": build_dgp_model(initial_data)},
{"model": build_svgp_model(initial_data)},
]

results = []
Expand Down

0 comments on commit 2c9d545

Please sign in to comment.