GP.conditional.Input dimension mis-match

Hi.im new to pymc3 and gpr. when trying to do a simple GP on some 2D data using the following code and I’m getting the error that I can’t use the conditional method on a marginal gp model because the Xnew(the shape is 453) data is a different size to the X_train data(the shape is553).
here is my code

data=np.array([[1,1,22190],[1,2,60834],[1,3,85104],[1,4,100151],[1,5,108812],[1,6,114967],[1,7,118790],[1,8,121558],[1,9,123492],[1,10,125049],
[2,1,26542],[2,2,77798],[2,3,106407],[2,4,122422],[2,5,133359],
[2,6,138599],[2,7,143029],[2,8,145712],[2,9,147358],[3,1,32977],
[3,2,100494],[3,3,134886],[3,4,157758],[3,5,168991],[3,6,178065],
[3,7,182787],[3,8,187760],[4,1,38604],[4,2,114428],[4,3,157103],
[4,4,181322],[4,5,197411],[4,6,208804],[4,7,213396],[5,1,42466],
[5,2,125820],[5,3,164776],[5,4,189045],[5,5,204377],[5,6,213904],
[6,1,46447],[6,2,116764],[6,3,154897],[6,4,179419],[6,5,193676],
[7,1,41368],[7,2,100344],[7,3,132021],[7,4,151081],[8,1,35719],
[8,2,83216],[8,3,111268],[9,1,28746],[9,2,66033],[10,1,25265]])

x=data[:,:2]
x_test=data[:,:2]
x=np.insert(x, 2, values=1, axis=1)
for i in np.arange(55):
    x[i,2]=x[i,0]+x[i,1]
    
X_new = np.array([[2,10],[3,9],[3,10],[4,8],[4,9],[4,10],[5,7],[5,8],[5,9],[5,10],[6,6],[6,7],[6,8],[6,9],[6,10],[7,5],[7,6],[7,7],[7,8],[7,9],[7,10],[8,4],[8,5],[8,6],[8,7],[8,8],[8,9],[8,10],[9,3],[9,4],[9,5],[9,6],[9,7],[9,8],[9,9],[9,10],[10,2],[10,3],[10,4],[10,5],[10,6],[10,7],[10,8],[10,9],[10,10]])
X_new=np.insert(X_new, 2, values=1, axis=1)
for i in np.arange(45):
    X_new[i,2]=X_new[i,0]+X_new[i,1]

with pm.Model() as model_reg:
    # hyperprior for lengthscale kernel parameter
    ℓ1 = pm.Gamma('ℓ1', 4, 4)
    ℓ2 = pm.Gamma('ℓ2', 4, 4)
    ℓ3 = pm.Gamma('ℓ3', 4, 4)
    # instantiate a covariance function
    cov = pm.gp.cov.ExpQuad(3, ls=[ℓ1,ℓ2 ,ℓ3])
    # instantiate a GP prior
    gp = pm.gp.Marginal(cov_func=cov)
    # prior
    ϵ = pm.HalfNormal('ϵ', 25)
    y_pred = gp.marginal_likelihood('y_pred', X=x,y=y, noise=ϵ)
    start=pm.find_MAP()
    trace_reg=pm.sample(init="adapt_diag",start=start)
with model_reg:
    f_pred = gp.conditional('f_pred', X_new)

and i get this

ValueError: Input dimension mis-match. (input[0].shape[1] = 45, input[1].shape[1] = 55)

if you can help me or have the same question ,replay please.thank you.

what by chance are the dimensions of your y variable?

1D,y.shape is (55,1)

maybe try y.flatten()? so that y.shape is (55, )

1 Like

Yes,it works.Thanks