num_init=num_init_points, mask_fail=mask_fail, ) plt.show() # %% [markdown] # We can also plot the mean and variance of the predictive distribution over the search space, first for the objective data and model ... # %% from util.plotting_plotly import plot_gp_plotly, add_bo_points_plotly arg_min_idx = tf.squeeze( tf.argmin(result.datasets[OBJECTIVE].observations, axis=0)) fig = plot_gp_plotly(result.models[OBJECTIVE].model, search_space.lower, search_space.upper, grid_density=50) fig = add_bo_points_plotly( x=result.datasets[OBJECTIVE].query_points[:, 0].numpy(), y=result.datasets[OBJECTIVE].query_points[:, 1].numpy(), z=result.datasets[OBJECTIVE].observations.numpy().flatten(), num_init=num_init_points, idx_best=arg_min_idx, fig=fig, figrow=1, figcol=1, ) fig.show() # %% [markdown]
idx_best=arg_min_idx) ax[0].set_yscale("log") ax[0].set_ylabel("Regret") ax[0].set_ylim(0.001, 100) ax[0].set_xlabel("# evaluations") # %% [markdown] # We can visualise the model over the objective function by plotting the mean and 95% confidence intervals of its predictive distribution. Like with the data before, we can get the model with `.try_get_final_model()`. # %% from util.plotting_plotly import plot_gp_plotly fig = plot_gp_plotly( result.try_get_final_model().model, # type: ignore search_space.lower, search_space.upper, grid_density=30, ) fig = add_bo_points_plotly( x=query_points[:, 0], y=query_points[:, 1], z=observations[:, 0], num_init=num_initial_points, idx_best=arg_min_idx, fig=fig, figrow=1, figcol=1, ) fig.show()
_, ax = plt.subplots(1, 2) plot_regret(observations, ax[0], num_init=num_initial_points, idx_best=arg_min_idx) plot_bo_points( query_points, ax[1], num_init=num_initial_points, idx_best=arg_min_idx ) # %% [markdown] # We can visualise the model over the objective function by plotting the mean and 95% confidence intervals of its predictive distribution. Like with the data before, we can get the model with `.try_get_final_models()` and indexing with `OBJECTIVE`. # %% from util.plotting_plotly import plot_gp_plotly fig = plot_gp_plotly( result.try_get_final_models()[OBJECTIVE].model, search_space.lower, search_space.upper, grid_density=30 ) fig = add_bo_points_plotly( x=query_points[:, 0], y=query_points[:, 1], z=observations[:, 0], num_init=num_initial_points, idx_best=arg_min_idx, fig=fig, figrow=1, figcol=1, ) fig.show()
fig, ax = plot_function_2d(masked_branin, mins, maxs, grid_density=50, contour=True) plot_bo_points( final_data[FAILURE].query_points.numpy(), ax=ax[0, 0], num_init=num_init_points, mask_fail=mask_fail, ) plt.show() # %% [markdown] # We can also plot the mean and variance of the predictive distribution over the search space, first for the objective data and model ... # %% arg_min_idx = tf.squeeze(tf.argmin(final_data[OBJECTIVE].observations, axis=0)) fig = plot_gp_plotly(regression_model, mins, maxs, grid_density=50) fig = add_bo_points_plotly( x=final_data[OBJECTIVE].query_points[:, 0].numpy(), y=final_data[OBJECTIVE].query_points[:, 1].numpy(), z=final_data[OBJECTIVE].observations.numpy().flatten(), num_init=num_init_points, idx_best=arg_min_idx, fig=fig, figrow=1, figcol=1, ) fig.show() # %% [markdown] # ... and then for the failure data and model
# ## Visualising the result # # We can take a look at where we queried the observer, both the original query points (crosses) and new query points (dots), and where they lie with respect to the contours of the Branin. # %% arg_min_idx = tf.squeeze(tf.argmin(dataset.observations, axis=0)) query_points = dataset.query_points.numpy() observations = dataset.observations.numpy() _, ax = plot_function_2d( branin, lower_bound.numpy(), upper_bound.numpy(), grid_density=30, contour=True ) plot_bo_points(query_points, ax[0, 0], num_initial_data_points, arg_min_idx) # %% [markdown] # We can also visualise the observations on a three-dimensional plot of the Branin. We'll add the contours of the mean and variance of the model's predictive distribution as translucent surfaces. # %% fig = plot_gp_plotly(gpr, lower_bound.numpy(), upper_bound.numpy(), grid_density=30) fig = add_bo_points_plotly( x=query_points[:, 0], y=query_points[:, 1], z=observations[:, 0], num_init=num_initial_data_points, idx_best=arg_min_idx, fig=fig, figrow=1, figcol=1, ) fig.show()
_, ax = plt.subplots(1, 2) plot_regret(observations, ax[0], num_init=num_initial_points, idx_best=arg_min_idx) plot_bo_points(query_points, ax[1], num_init=num_initial_points, idx_best=arg_min_idx) # %% [markdown] # We can visualise the model over the objective function by plotting the mean and 95% confidence intervals of its predictive distribution. # %% fig = plot_gp_plotly(model[OBJECTIVE].model, mins, maxs, grid_density=30) fig = add_bo_points_plotly( x=query_points[:, 0], y=query_points[:, 1], z=observations[:, 0], num_init=num_initial_points, idx_best=arg_min_idx, fig=fig, figrow=1, figcol=1, ) fig.show() # %% [markdown]
_, ax = plt.subplots(1, 2) plot_regret(observations, ax[0], num_init=num_initial_points, idx_best=arg_min_idx) plot_bo_points(query_points, ax[1], num_init=num_initial_points, idx_best=arg_min_idx) # %% [markdown] # We can visualise the model over the objective function by plotting the mean and 95% confidence # intervals of its predictive distribution. # %% fig = plot_gp_plotly(gpr, mins, maxs, grid_density=30) fig = add_bo_points_plotly( x=query_points[:, 0], y=query_points[:, 1], z=observations[:, 0], num_init=num_initial_points, idx_best=arg_min_idx, fig=fig, figrow=1, figcol=1, ) fig.show() # %% [markdown]