Hi everyone!
I would like to re-produce the Gaussian Process Regression example from (Rasmussen, Williams (2006): Gaussian Processes for Machine Learning, p.118 ff.) with PyMC3
. In this example, they build a model for the Mauna Loa CO2 dataset.
First they define four covariance functions $(k_1(x,x\prime), …, k_4(x,x\prime))$ with 11 unknown hyperparameters in total ($\theta_1, \theta_2, …, \theta_{11})$.
By substracting the empirical mean and optimizing the marginal likelihood over the parameters (NOT hyperparameters -> level 1 inference, MAP estimate) they estimate the values of the hyperparameters (see page 109 for a general description of level 1, 2 and 3 inference and page 112 for why they use level 1 inference for gaussian process regression).
I tried that in PyMC3
with the pymc3.find_MAP()
function but failed to re-produce the values for the estimated hyperparameters. It is unclear to me how I can avoid assigning probability distributions to the hyperparameters $(\theta_1, \theta_2, …, \theta_{11})$ and declare them as some kind of unknown quantities instead.
I managed to reproduce the example in scikit-learn
and I thought it is possible in PyMC3
as well. At the moment, however, it seems to me that PyMC3
wants me to assign prior distributions on the hyperparameters $(\theta_1, \theta_2, …, \theta_{11})$, and instead of conducting level 1 inference conduct level 2 inference.
Does anyone have an idea how I can avoid this?
Below my code (without prior distributions on the hyperparameters, so running the code results in an error):
from sklearn.datasets import fetch_mldata
data = fetch_mldata('mauna-loa-atmospheric-co2').data
X = data[:, [1]]
y = data[:, 0]
with pm.Model() as model:
# Define unknown parameters (which I did not do since I do not want my parameters to follow a specific distribution)
# Define Kernels
k1 = theta_1 * pm.gp.cov.ExpQuad(1,theta_5) # long term smooth rising trend
k2 = theta_2 * pm.gp.cov.ExpQuad(1,theta_6) * \
pm.gp.cov.WarpedInput(1, cov_func=pm.gp.cov.ExpQuad(1,theta_11),warp_func=mapping) # seasonal component
k3 = theta_3 * pm.gp.cov.RatQuad(1,theta_7, theta_8) # medium term irregularity
k4 = theta_4 * pm.gp.cov.ExpQuad(1, theta_9) + theta_10 * tt.eye(len(X)) # noise terms
# Build final covariance function
f_cov = k1 + k2 + k3 + k4
y_obs = pm.gp.GP('y_obs', cov_func=f_cov, sigma=1, observed={'X':X, 'Y':y})
map_estimate = pm.find_MAP(model=model)