Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with the prediction of variance derivatives in GPX #625

Closed
MaelTremouille opened this issue Jul 15, 2024 · 1 comment
Closed

Error with the prediction of variance derivatives in GPX #625

MaelTremouille opened this issue Jul 15, 2024 · 1 comment

Comments

@MaelTremouille
Copy link
Contributor

There is an issue with the computation of the predicted variance derivatives in GPX. Actually, the values differ significantly between the computation with KRG and GPX.
Here are some commands to show how different they are:

import numpy as np
from smt.sampling_methods import LHS
from smt.surrogate_models import GPX, KRG


def target_fun(x):
    return np.cos(5 * x)


def pb(x):
    # sin + linear trend
    y = (
        np.atleast_2d(np.sin(x[:, 0])).T
        + np.atleast_2d(2 * x[:, 0] + 5 * x[:, 1]).T
        + 10
    )  # + linear trend
    return y


xlimits = np.array([[-5, 10], [-5, 10]])
sampling = LHS(xlimits=xlimits, random_state=42)
xt = sampling(12)
yt = pb(xt)
trends = ["constant", "linear"]
kernels = [
    "pow_exp",
    "squar_exp",
    "abs_exp",
    "matern32",
    "matern52",
    "squar_sin_exp",
]

sm_gpx = GPX(
    theta0=[0.01],
    print_global=False,
    poly="constant",
    corr="abs_exp",
    seed=42,
)
sm_krg = KRG(
    theta0=[0.01],
    print_global=False,
    poly="constant",
    corr="abs_exp",
    random_state=42,
)
# train
sm_gpx.set_training_values(xt, yt)
sm_gpx.train()
sm_krg.set_training_values(xt, yt)
sm_krg.train()

# Predicted
e = 5e-6
xa = -1.3
xb = 2.5
x_valid = np.array([[xa, xb], [xa + e, xb], [xa - e, xb], [xa, xb + e], [xa, xb - e]])
y_predicted_gpx = sm_gpx.predict_variances(x_valid)
y_predicted_krg = sm_krg.predict_variances(x_valid)
x = np.atleast_2d(x_valid[0])

# diff
diff_g_gpx = (y_predicted_gpx[1, 0] - y_predicted_gpx[2, 0]) / (2 * e)
diff_d_gpx = (y_predicted_gpx[3, 0] - y_predicted_gpx[4, 0]) / (2 * e)
diff_g_krg = (y_predicted_krg[1, 0] - y_predicted_krg[2, 0]) / (2 * e)
diff_d_krg = (y_predicted_krg[3, 0] - y_predicted_krg[4, 0]) / (2 * e)

deriv_gpx = np.array(
    [
        sm_gpx.predict_variance_derivatives(x, 0)[0],
        sm_gpx.predict_variance_derivatives(x, 1)[0],
    ]
).T

deriv_krg = np.array(
    [
        sm_krg.predict_variance_derivatives(x, 0)[0],
        sm_krg.predict_variance_derivatives(x, 1)[0],
    ]
).T
print("deriv_gpx", deriv_gpx)
print("[diff_g_gpx,diff_d_gpx]", [diff_g_gpx, diff_d_gpx])
print("deriv_krg", deriv_krg)
print("[diff_g_krg,diff_d_krg]", [diff_g_gpx, diff_d_gpx])
@relf
Copy link
Member

relf commented Aug 19, 2024

Good catch, thanks! This issue is fixed with egobox 0.21.1.

@relf relf closed this as completed Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants