def main(): str_acq = 'ei' num_iter = 10 X_train = np.array([ [-5], [-1], [1], [2], ]) num_init = X_train.shape[0] model_bo = bo.BO(np.array([[-6., 6.]]), str_acq=str_acq) X_test = np.linspace(-6, 6, 400) X_test = np.reshape(X_test, (400, 1)) for ind_ in range(1, num_iter + 1): Y_train = fun_target(X_train) next_x, dict_info = model_bo.optimize(X_train, fun_target(X_train), str_initial_method_ao='uniform') cov_X_X = dict_info['cov_X_X'] inv_cov_X_X = dict_info['inv_cov_X_X'] hyps = dict_info['hyps'] mu_test, sigma_test, Sigma_test = gp.predict_test_( X_train, Y_train, X_test, cov_X_X, inv_cov_X_X, hyps) acq_test = acquisition.ei(mu_test.flatten(), sigma_test.flatten(), Y_train) acq_test = np.expand_dims(acq_test, axis=1) X_train = np.vstack((X_train, next_x)) Y_train = fun_target(X_train) utils_plotting.plot_bo_step(X_train, Y_train, X_test, fun_target(X_test), mu_test, sigma_test, path_save=PATH_SAVE, str_postfix='bo_{}_'.format(str_acq) + str(ind_), int_init=num_init) utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, fun_target(X_test), mu_test, sigma_test, acq_test, path_save=PATH_SAVE, str_postfix='bo_{}_'.format(str_acq) + str(ind_), int_init=num_init)
def main(): num_iter = 10 X_train = np.array([ [-5], [-1], [1], [2], ]) num_init = X_train.shape[0] model_bo = bo.BO(np.array([[-6., 6.]])) X_test = np.linspace(-6, 6, 400) X_test = np.reshape(X_test, (400, 1)) for ind_ in range(1, num_iter + 1): Y_train = fun_target(X_train) next_x, _, _, cov_X_X, inv_cov_X_X, hyps = model_bo.optimize( X_train, fun_target(X_train), str_initial_method='uniform') mu_test, sigma_test = gp.predict_test_(X_train, Y_train, X_test, cov_X_X, inv_cov_X_X, hyps) acq_test = acquisition.ei(mu_test.flatten(), sigma_test.flatten(), Y_train) acq_test = np.expand_dims(acq_test, axis=1) X_train = np.vstack((X_train, next_x)) Y_train = fun_target(X_train) utils_plotting.plot_bo_step(X_train, Y_train, X_test, fun_target(X_test), mu_test, sigma_test, path_save=PATH_SAVE, str_postfix='basics_bo_' + str(ind_), int_init=num_init) utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, fun_target(X_test), mu_test, sigma_test, acq_test, path_save=PATH_SAVE, str_postfix='basics_bo_' + str(ind_), int_init=num_init, is_acq_axis_small=True)
def test_plot_bo_step_acq(): num_dim_X = 1 num_dim_Y = 1 num_train = 5 num_test = 10 X_train = np.ones((num_train, num_dim_X)) Y_train = np.ones((num_train, num_dim_Y)) X_test = np.ones((num_test, num_dim_X)) Y_test = np.ones((num_test, num_dim_Y)) mean_test = np.ones((num_test, num_dim_Y)) std_test = np.ones((num_test, num_dim_Y)) acq_test = np.ones((num_test, num_dim_Y)) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(np.arange(0, 10), Y_train, X_test, Y_test, mean_test, std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, np.arange(0, 10), X_test, Y_test, mean_test, std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, np.arange(0, 10), Y_test, mean_test, std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, np.arange(0, 10), mean_test, std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, np.arange(0, 10), std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, np.arange(0, 10), acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, np.arange(0, 10)) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(np.ones( (num_train, 2)), Y_train, X_test, Y_test, mean_test, std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, np.ones( (num_test, 2)), Y_test, mean_test, std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, np.ones( (num_train, 2)), X_test, Y_test, mean_test, std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, np.ones((num_test, 2)), mean_test, std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, np.ones( (num_test, 2)), Y_test, mean_test, std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(np.ones( (30, num_dim_X)), Y_train, X_test, Y_test, mean_test, std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, np.ones( (30, num_dim_Y)), X_test, Y_test, mean_test, std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, np.ones((num_test, 2)), std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, np.ones((num_test, 2)), acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, np.ones((num_test, 2))) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, np.ones((30, num_dim_X)), Y_test, mean_test, std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, np.ones((30, num_dim_Y))) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, np.ones((30, num_dim_Y)), acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, np.ones((30, num_dim_Y)), std_test, acq_test) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, acq_test, int_init=30) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, acq_test, path_save=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, acq_test, str_postfix=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, acq_test, str_x_axis=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, acq_test, str_y_axis=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, acq_test, str_acq_axis=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, acq_test, int_init='abc') with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, acq_test, is_tex='abc') with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, acq_test, is_zero_axis='abc') with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, acq_test, is_acq_axis_small='abc') with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, acq_test, time_pause='abc') with pytest.raises(AssertionError) as error: utils_plotting.plot_bo_step_acq(X_train, Y_train, X_test, Y_test, mean_test, std_test, acq_test, range_shade='abc')