def main(): num_train = 200 num_test = 1000 X_train = np.random.randn(num_train, 1) * 5.0 Y_train = np.cos(X_train) + 10.0 X_test = np.linspace(-10, 10, num_test) X_test = X_test.reshape((num_test, 1)) Y_test_truth = np.cos(X_test) + 10.0 mu, sigma, Sigma = gp.predict_optimized(X_train, Y_train, X_test, debug=True) utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, Y_test_truth, 'test_optimized_many_points')
def main(): num_points = 100 is_fixed_noise = False bounds = obj_fun.get_bounds() model_bo = bo.BO(bounds, debug=True) X_init = model_bo.get_initial('uniform', fun_objective=fun_target, int_samples=num_points) X_test = bo.get_grids(bounds, 50) mu, sigma, Sigma = gp.predict_optimized(X_init, fun_target(X_init), X_test, is_fixed_noise=is_fixed_noise, debug=True)
def main(scale, str_postfix): X_train = np.array([ [-3.0], [-2.0], [-1.0], [2.0], [1.2], [1.1], ]) Y_train = np.cos(X_train) * scale num_test = 200 X_test = np.linspace(-3, 3, num_test) X_test = X_test.reshape((num_test, 1)) Y_test_truth = np.cos(X_test) * scale mu, sigma, Sigma = gp.predict_optimized(X_train, Y_train, X_test, is_fixed_noise=False) utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, Y_test_truth, PATH_SAVE, 'test_optimized_{}_y'.format(str_postfix))
def main(str_cov): np.random.seed(42) X_train = np.array([ [-3.0], [-1.0], [3.0], [1.0], [2.0], ]) Y_train = np.cos(X_train) + np.random.randn(X_train.shape[0], 1) * 0.2 num_test = 200 X_test = np.linspace(-3, 3, num_test) X_test = X_test.reshape((num_test, 1)) Y_test_truth = np.cos(X_test) mu, sigma, Sigma = gp.predict_optimized(X_train, Y_train, X_test, str_cov=str_cov, is_fixed_noise=False, debug=True) utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, Y_test_truth, path_save=PATH_SAVE, str_postfix='cos_' + str_cov)
def main(fun_prior, str_prior): X_train = np.array([ [-3.0], [-2.0], [-1.0], ]) Y_train = np.cos(X_train) + 2.0 num_test = 200 X_test = np.linspace(-3, 6, num_test) X_test = X_test.reshape((num_test, 1)) Y_test_truth = np.cos(X_test) + 2.0 mu, sigma, Sigma = gp.predict_optimized(X_train, Y_train, X_test, prior_mu=fun_prior) utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, Y_test_truth, PATH_SAVE, 'optimized_prior_{}'.format(str_prior))
def test_predict_optimized(): np.random.seed(42) dim_X = 2 num_X = 5 num_X_test = 20 X = np.random.randn(num_X, dim_X) Y = np.random.randn(num_X, 1) X_test = np.random.randn(num_X_test, dim_X) prior_mu = None with pytest.raises(AssertionError) as error: gp.predict_optimized(X, Y, X_test, str_cov='se', prior_mu='abc') with pytest.raises(AssertionError) as error: gp.predict_optimized(X, Y, X_test, str_cov=1, prior_mu=prior_mu) with pytest.raises(AssertionError) as error: gp.predict_optimized(X, Y, 1, str_cov='se', prior_mu=prior_mu) with pytest.raises(AssertionError) as error: gp.predict_optimized(X, 1, X_test, str_cov='se', prior_mu=prior_mu) with pytest.raises(AssertionError) as error: gp.predict_optimized(1, Y, X_test, str_cov='se', prior_mu=prior_mu) with pytest.raises(AssertionError) as error: gp.predict_optimized(np.random.randn(num_X, 1), Y, X_test, str_cov='se', prior_mu=prior_mu) with pytest.raises(AssertionError) as error: gp.predict_optimized(np.random.randn(10, dim_X), Y, X_test, str_cov='se', prior_mu=prior_mu) with pytest.raises(AssertionError) as error: gp.predict_optimized(X, np.random.randn(10, 1), X_test, str_cov='se', prior_mu=prior_mu) with pytest.raises(AssertionError) as error: gp.predict_optimized(X, Y, X_test, is_fixed_noise=1) with pytest.raises(AssertionError) as error: gp.predict_optimized(X, Y, X_test, debug=1) mu_Xs, sigma_Xs, Sigma_Xs = gp.predict_optimized(X, Y, X_test) print(mu_Xs) print(sigma_Xs) print(Sigma_Xs)