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():
    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_grid(bounds, 50)
    mu, sigma = gp.predict_optimized(X_init, fun_target(X_init), X_test, is_fixed_noise=is_fixed_noise, debug=True)
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():
    num_points = 100
    is_fixed_noise = False
    model_bo = bo.BO(INFO_TARGET.get('bounds'), debug=True)
    X_init = model_bo.get_initial('uniform',
                                  fun_objective=fun_target,
                                  int_samples=num_points)
    X_test = bo.get_grid(INFO_TARGET.get('bounds'), 50)
    mu, sigma = gp.predict_optimized(X_init,
                                     np.expand_dims(fun_target(X_init),
                                                    axis=1),
                                     X_test,
                                     is_fixed_noise=is_fixed_noise,
                                     debug=True)
Ejemplo n.º 5
0
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')
Ejemplo n.º 6
0
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')
Ejemplo n.º 7
0
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')
Ejemplo n.º 8
0
    X_train = np.array([
        [2.],
        [3.],
        [5.],
        [7.],
        [9.],
    ]) / 10.0
    Y_train = np.array([
        [-0.2],
        [-0.25],
        [0.05],
        [-0.1],
        [0.1],
    ]) * 1.0

    mu, sigma = gp.predict_optimized(X_train, Y_train, X_test, str_cov='matern52')
    mu = np.squeeze(mu)
    sigma = np.squeeze(sigma)

    fig = plt.figure(figsize=(4, 3))
    ax = fig.gca()

    ax.plot(X_test.flatten(), mu, color=(255./255., 179./255., 0./255.), linewidth=8)

    '''
    range_shade = 4.0
    ax.fill_between(
        X_test.flatten(),
        mu - range_shade * sigma,
        mu + range_shade * sigma,
        color=(102./255., 102./255., 92./255.),
Ejemplo n.º 9
0
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 = gp.predict_optimized(X, Y, X_test)
    print(mu_Xs)
    print(sigma_Xs)