I am new to pymc3 and gaussian process. I try to do a simple gaussian process with 2D inputs (i.e. X has 2 columns) and 1D output (i.e. y has 1 column). My code is like this:
import pymc3 as pm
import theano
import theano.tensor as tt
import numpy as npimport matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3Dnp.random.seed(123)
nvar = 2
a0 = 2
a1 = 5#define a function
def fxn(x0,x1,a0,a1):
return a0 * x0 + a1 * x1#create the base function
m = 600
x0 = np.random.uniform(0,3,m)
x1 = np.random.uniform(0,5,m)
X = np.vstack([x0,x1])y = (fxn(x0,x1,a0,a1).flatten()+np.random.normal(loc=0,scale=2,size=m))
y_true = fxn(x0,x1,a0,a1)fig = plt.figure()
ax = fig.add_subplot(111, projection=ā3dā)
ax.scatter(x0, x1, y, marker=āoā,color=ākā,label=āTrue Pointsā)
plt.plot(x0, x1, y_true,ār.ā,label=ābase functionā)
plt.legend()
plt.show()y = y.reshape((m,1))
with pm.Model() as surrogate_model:
ls = pm.HalfNormal(ālā,sd=2,shape=nvar)
eta = pm.HalfNormal(āetaā, sd=2, shape=1)
cov = eta**2.*pm.gp.cov.ExpQuad(nvar,ls=ls)
sigma = pm.HalfNormal(āsigmaā,1.0)gp = pm.gp.Marginal(cov_func=cov) y_ = gp.marginal_likelihood('y',X=X,y=y,noise=sigma) trace = pm.sample(1000,tune=1000,njobs=2)
_ = pm.traceplot(trace,priors=[ls.distribution,eta.distribution,sigma.distribution])
summary = pm.summary(trace)l_means = np.array([summary[āmeanā][key] for key in summary[āmeanā].keys() if āl_ā in key]).reshape(1,nvar)
eta_mean = np.array([summary[āmeanā][key] for key in summary[āmeanā].keys() if āetaā in key]).reshape(1,1)
sigma_mean = [summary[āmeanā][key] for key in summary[āmeanā].keys() if āsigmaā in key]mm = 600
xx0 = np.linspace(0,6,mm)
xx1 = np.linspace(0,10,mm)
XX = np.vstack([xx0,xx1])with surrogate_model:
f_pred = gp.conditional(āf_predā,XX)with surrogate_model:
pred_samples = pm.sample_ppc(trace,vars=[f_pred],samples=1000)
It gives me āincompatible dimensionsā error when I tried to do āgp.conditionalā, can someone help me with this?
Thanks in advance.