2d Gaussian process IndexError

#1

This is an example similar to an example for applying 2d gaussian process by @fonnesbeck. X_.shape=(10970, 2) and Y_.shape = (10970,). After running it I get this error at the line related to posterior predictive:

if samples.shape[0] == 1 and size == 1:

IndexError: tuple index out of range

Wondering if you could help me to resolve it?thanks!

#%%
X_shared=th.shared(X_)
Y_shared=th.shared(Y_)
#%%
nd = 30
z1, z2 = np.meshgrid(np.linspace(X_[:,0].min(), X_[:,0].max(), nd), np.linspace(X_[:,1].min(), X_[:,1].max(), nd))
Z = np.concatenate([z1.reshape(nd*nd, 1), z2.reshape(nd*nd, 1)], 1)

nd = 15
xu1, xu2 = np.meshgrid(np.linspace(X_[:,0].min(), X_[:,0].max(), nd), np.linspace(X_[:,1].min(), X_[:,1].max(), nd))
Xu = np.concatenate([xu1.reshape(nd*nd, 1), xu2.reshape(nd*nd, 1)], 1)
#%%
with pm.Model() as spatial_model:
    
    l = pm.HalfCauchy("l", beta=3, shape=(2,))
    sf2 = pm.HalfCauchy("sf2", beta=3)
    sn2 = pm.HalfCauchy("sn2", beta=3)

#    K = pm.gp.cov.ExpQuad(2, l) * sf2**2
    K = pm.gp.cov.Matern32(2,l) * sf2**2
    
    gp_spatial = pm.gp.MarginalSparse(cov_func=K, approx="FITC")
    obs = gp_spatial.marginal_likelihood("obs", X=X_shared, Xu=Xu, y=Y_shared, noise=sn2)

    trace = pm.sample(cores=1)
#%%

with spatial_model:
    f_pred = gp_spatial.conditional('f_pred2', Z)
    samples = pm.sample_posterior_predictive([trace], vars=[f_pred], samples=100)
#%%
#2

To add more to this question here is what I get after running the code:
1_pic

#3

You would really have to post where your data comes from so anyone that wants to help could actually run your code.

#4

@Gon_FThank you for the message, but the problem should not be the data, I explained the data shape in my explanation. To explain more, X_ , input is longitude and altitude, and output is a measurement for each of them. You can assume a grid that y is 2X_[:,0]+3X_[:,1]+noise. If it really matters I would be happy to share the actual data as well.

#5

I just mentioned it because it gives me peace of mind to know the error is not coming from the data : P , and it allows me to work along with the code and run it, instead of just abstractly analyzing it.

1 Like
#6

data.csv (1.5 MB)
@Gon_F here is the data, there are some missing values and I used (pandas dropna) to discard them.
Thanks!

#7

I am wondering if the code looks good? or there is an error in it that I couldn’t fine? What is the reason for the error?

#8

The model does run on my system, using current master (macOS and Python 3.7.3). Can you try that (or the release candidate that was just pushed)?