def main(): np.random.seed(42) X_train = np.array([ [-3], [-1], [3], [1], [2], ]) 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) hyps = { 'signal': 0.5, 'lengthscales': 0.5, 'noise': 0.02, } mu, sigma = gp.predict_optimized(X_train, Y_train, X_test, str_cov=STR_COV, 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(): X_train = np.array([ [-3], [-1], [1], [2], ]) Y_train = np.cos(X_train) + np.random.randn(X_train.shape[0], 1) * 0.1 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) hyps = { 'signal': 0.5, 'lengthscales': 0.5, 'noise': 0.02, } mu, sigma, Sigma = gp.predict_test(X_train, Y_train, X_test, hyps) utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, Y_test_truth, path_save=PATH_SAVE, str_postfix='cos')
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 = 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(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(): X_train = np.array([ [-3.0], [-2.0], [-1.0], [2.0], [1.2], [1.1], ]) Y_train = np.cos(X_train) * 0.01 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) * 0.01 mu, sigma = gp.predict_optimized(X_train, Y_train, X_test, is_fixed_noise=True) utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, Y_test_truth, PATH_SAVE, 'test_optimized_large_y')
def main(): X_train = np.array([ [-3.0], [-2.0], [-1.0], [2.0], [1.2], [1.1], ]) Y_train = np.cos(X_train) + 10.0 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) + 10.0 mu, sigma = gp.predict_optimized(X_train, Y_train, X_test) utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, Y_test_truth, PATH_SAVE, 'optimized')
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(): 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 prior_mu = cosine mu, sigma = gp.predict_optimized(X_train, Y_train, X_test, prior_mu=prior_mu) utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, Y_test_truth, PATH_SAVE, 'optimized_prior_cosine')
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_plot_gp(): dim_X = 1 dim_Y = 1 num_train = 5 num_test = 10 X_train = np.zeros((num_train, dim_X)) Y_train = np.ones((num_train, dim_Y)) X_test = np.zeros((num_test, dim_X)) mu = np.zeros((num_test, dim_Y)) sigma = np.zeros((num_test, dim_Y)) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, 1) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, np.arange(0, num_test)) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, 1, sigma) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, np.arange(0, num_test), sigma) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, 1, mu, sigma) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, np.arange(0, num_test), mu, sigma) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, 1, X_test, mu, sigma) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, np.arange(0, num_train), X_test, mu, sigma) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(1, Y_train, X_test, mu, sigma) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(np.arange(0, num_test), Y_train, X_test, mu, sigma) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(np.zeros((num_train, 2)), Y_train, X_test, mu, sigma) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, np.zeros((num_train, 2)), mu, sigma) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, np.ones((num_train, 2)), X_test, mu, sigma) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, np.ones((10, 1)), X_test, mu, sigma) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, np.zeros( (num_test, 2)), sigma) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, np.zeros((num_test, 2))) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, np.zeros((11, 1))) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, np.zeros((11, 1)), sigma) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, Y_test_truth=np.arange(0, num_test)) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, Y_test_truth=np.zeros((num_test, 2))) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, Y_test_truth=np.zeros((20, 1))) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, Y_test_truth=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, path_save=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, str_postfix=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, str_x_axis=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, str_y_axis=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, is_tex=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, is_zero_axis=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, time_pause='abc') with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, range_shade='abc') with pytest.raises(AssertionError) as error: utils_plotting.plot_gp(X_train, Y_train, X_test, mu, sigma, colors='abc')