I’m writing up a report on some coding I have done and I just want to check what I am saying is correct and I have the right context for what the code below does
I run a Matern32 covariance function, which has parameter l defining the length scale which is a Gamma kernel, and then the noise is modelled as a Half Cauchy (because the noise is always positive) function and is used as a scalar for the covariance function.
I have swapped to the pm.sample and using this to estimate parameters instead of the MAP function, but I am not exactly sure what the sample function does.
I am a bit unsure what the parameter s represents so any input on this would be good, I believe it models the noise on the data training points supplied to the model.
If anyone can just help explain the process of what these parameters mean and how they are being estimated that would be very helpful as I’m currently getting confused.
# new x values for inferring the data in that range
# linspace(start,stop,num)
X_new = numpy.linspace(-50, 50, 100)[:, None]
with pm.Model() as model:
#shape
l = pm.Gamma("l", alpha=2, beta=1)
#Noise
n = pm.HalfCauchy("n",beta=5)
#Covariance
cov = n ** 2 * pm.gp.cov.Matern32(1,l)
#Specify the GP, the default mean function is zero in this case as not specified
gp = pm.gp.Marginal(cov_func=cov)
s = pm.HalfCauchy("s",beta=5)
#Marginal likelihood method fits the model
y_ = gp.marginal_likelihood("y",X=x,y=y, noise=s)
#Find the parameters that best fit the data
#mp = pm.find_MAP()
trace = pm.sample()
#.conditional distribition for predictions given the X_new values
f_pred = gp.conditional("f_pred",X_new)
#Predict the distribution of samples on the new x values
pred_samples = pm.sample_posterior_predictive(trace, var_names= ['f_pred'],samples=2000)