# Mesh the input space for evaluations of the real function, the prediction and
# its MSE
x = np.atleast_2d(np.linspace(-2, 2, 1000)).T

# Instanciate one Gaussian Process model for the stationary Matern kernel and
# one for the non-stationary one
gp_stationary = \
    GaussianProcess(corr='matern_1.5', theta0=1e0, thetaL=1e-2, thetaU=1e+2,
                    random_start=100)
gp_non_stationary = \
    GaussianProcess(corr=NonStationaryCorrelation(),
                    theta0=1e0, thetaL=1e-2, thetaU=1e+2,
                    random_start=100)

# Fit to data using Maximum Likelihood Estimation of the parameters
gp_stationary.fit(X, y)
gp_non_stationary.fit(X, y)
print("Theta:\n\tStationary: {:.3f} \t Non-stationary: {:.3f}"
      .format(gp_stationary.theta_[0], gp_non_stationary.theta_[0]))
print("Posterior probability (negative, average, log):\n\t"
      "Stationary: {:.5f} \t Non-stationary: {:.5f}"
      .format(gp_stationary.posterior_function_value_,
              gp_non_stationary.posterior_function_value_))

# Plot predictions
for title, gp in [("stationary", gp_stationary),
                  ("non-stationary", gp_non_stationary)]:
    # Make the prediction on the meshed x-axis (ask for MSE as well)
    y_pred, MSE = gp.predict(x, eval_MSE=True)
    sigma = np.sqrt(MSE)
Пример #2
0
# Mesh the input space for evaluations of the real function, the prediction and
# its MSE
x = np.atleast_2d(np.linspace(-2, 2, 1000)).T

# Instanciate one Gaussian Process model for the stationary Matern kernel and
# one for the non-stationary one
gp_stationary = \
    GaussianProcess(corr='matern_1.5', theta0=1e0, thetaL=1e-2, thetaU=1e+2,
                    random_start=100)
gp_non_stationary = \
    GaussianProcess(corr=NonStationaryCorrelation(),
                    theta0=1e0, thetaL=1e-2, thetaU=1e+2,
                    random_start=100)

# Fit to data using Maximum Likelihood Estimation of the parameters
gp_stationary.fit(X, y)
gp_non_stationary.fit(X, y)
print("Theta:\n\tStationary: {:.3f} \t Non-stationary: {:.3f}".format(
    gp_stationary.theta_[0], gp_non_stationary.theta_[0]))
print("Posterior probability (negative, average, log):\n\t"
      "Stationary: {:.5f} \t Non-stationary: {:.5f}".format(
          gp_stationary.posterior_function_value_,
          gp_non_stationary.posterior_function_value_))

# Plot predictions
for title, gp in [("stationary", gp_stationary),
                  ("non-stationary", gp_non_stationary)]:
    # Make the prediction on the meshed x-axis (ask for MSE as well)
    y_pred, MSE = gp.predict(x, eval_MSE=True)
    sigma = np.sqrt(MSE)