2d classification with GP, problem

Hi. GP creation is falling when I try to make it with not-1d input space:

import pymc3 as pm
import numpy as np
from sklearn.datasets.samples_generator import make_moons

X, Y = make_moons(noise=0.2, random_state=0, n_samples=15)
with pm.Model() as GP:
    l = np.array([0.2, 1.0])
    K = pm.gp.cov.ExpQuad(input_dim=2, lengthscales=l)
    M = pm.gp.mean.Zero()
    s = pm.HalfCauchy('s', 2.5)
    y_obs = pm.gp.GP('y_obs', mean_func=M, cov_func=K, sigma=s, observed={'X': X, 'Y': Y})

The error is happening in the last line:

log_thunk_trace: There was a problem executing an Op.
Traceback (most recent call last):
File “C:/Users/neuro/PycharmProjects/share_spec/gaussian_process.py”, line 13, in
y_obs = pm.gp.GP(‘y_obs’, mean_func=M, cov_func=K, sigma=s, observed={‘X’: X, ‘Y’: Y})
File “C:\Users\neuro\Anaconda2\lib\site-packages\pymc3\distributions\distribution.py”, line 39, in new
return model.Var(name, dist, data, total_size)
File “C:\Users\neuro\Anaconda2\lib\site-packages\pymc3\model.py”, line 534, in Var
total_size=total_size, model=self)
File “C:\Users\neuro\Anaconda2\lib\site-packages\pymc3\model.py”, line 1018, in init
self.logp_elemwiset = distribution.logp(**self.data)
File “C:\Users\neuro\Anaconda2\lib\site-packages\pymc3\gp\gp.py”, line 76, in logp
return MvNormal.dist(mu, Sigma).logp(Y)
File “C:\Users\neuro\Anaconda2\lib\site-packages\pymc3\distributions\multivariate.py”, line 200, in logp
delta = value - mu
File “C:\Users\neuro\Anaconda2\lib\site-packages\theano\tensor\var.py”, line 147, in sub
return theano.tensor.basic.sub(self, other)
File “C:\Users\neuro\Anaconda2\lib\site-packages\theano\gof\op.py”, line 674, in call
required = thunk()
File “C:\Users\neuro\Anaconda2\lib\site-packages\theano\gof\op.py”, line 843, in rval
File “C:\Users\neuro\Anaconda2\lib\site-packages\theano\gof\cc.py”, line 1698, in call
reraise(exc_type, exc_value, exc_trace)
File “”, line 2, in reraise
ValueError: Input dimension mis-match. (input[0].shape[1] = 15, input[1].shape[1] = 2)

Am I doing smth wrong?

Thanks for reporting! There is a bug in the gp.mean that the fix is still waiting to merge.

Currently, a workaround is to use pm.MvNormal directly:

Sigma = K(X) + tt.eye(X.shape[0])*s**2
y_obs = pm.MvNormal('y_obs', mu=0, cov=Sigma, observed=Y)
1 Like

@Namenaro The fix is just merge - if you upgrade to master your code will work now :wink:

1 Like