pymc icon indicating copy to clipboard operation
pymc copied to clipboard

BUG: HSGP making wrong out-of-sample predictions when X domain changes

Open AlexAndorra opened this issue 1 year ago • 0 comments

Describe the issue:

While working on the HSGP tutorial with @bwengals, we discovered out-of-sample predictions are wrong when the range of the X domain changes, because L, the parameter on the boundary condition is computed again the new values of X... but shouldn't. I'll fix that in a PR coming very soon. I'll also make sure the mean-centering of data, necessary to compute L, is done under the hood, instead of requiring the user to do it -- which is the current API but is a sneaky source of error

Reproduceable code example:

x = np.linspace(-5, 5, 100)

with pm.Model() as model:
    # Set mutable data
    X = pm.MutableData("X", x[:, None])

    m = [5]
    c = 5.0

    X_mu = np.mean(x, axis=0)
    Xs = X - X_mu
    
    ### WITH EVAL, NO BUG.  WITHOUT EVAL, BUG
    L = pm.gp.hsgp_approx.set_boundary(Xs, c).eval()
    
    eigvals = pm.gp.hsgp_approx.calc_eigenvalues(L, m, tl=pt)
    phi = pm.gp.hsgp_approx.calc_eigenvectors(Xs, L, eigvals, m, tl=pt)

phi1 = phi.eval()

x_new = np.linspace(-5, 10, 200)

with model:
    pm.set_data({"X": x_new[:, None]})
    
plt.plot(x, phi1, 'k');
plt.plot(x_new, phi.eval(), 'b', alpha=0.5);

Error message:

No response

PyMC version information:

5.12.0

Context for the issue:

No response

AlexAndorra avatar Apr 05 '24 20:04 AlexAndorra