def callback(X_next, Y_next, i): global X_sample, Y_sample # Plot samples, surrogate function, noise-free objective and next sampling location #plt.subplot(n_iter, 2, 2 * i + 1) plt.figure() plot_approximation(gpr, X, Y, X_sample, Y_sample, X_next, show_legend=i == 0) plt.title(f'Iteration {i+1}') if save_figures: save_fig('bayes-opt-surrogate-{}.pdf'.format(i + 1)) plt.show() plt.figure() #plt.subplot(n_iter, 2, 2 * i + 2) plot_acquisition(X, expected_improvement(X, X_sample, Y_sample, gpr), X_next, show_legend=i == 0) if save_figures: save_fig('bayes-opt-acquisition-{}.pdf'.format(i + 1)) plt.show() # Add sample to previous samples X_sample = np.append(X_sample, np.atleast_2d(X_next), axis=0) Y_sample = np.append(Y_sample, np.atleast_2d(Y_next), axis=0)
def EI(X, X_sample, Y_sample, surrogate): X = np.atleast_2d(X) return expected_improvement(X, X_sample, Y_sample, surrogate, improvement_thresh=0.01, trust_incumbent=True)