Below is a very basic toy model of what I want to do
import numpy as np
import pymc as pm
x = np.linspace(-10, 10, 100)
noise = np.random.randn(x.shape[0])
y = x * x / 10 + noise
with pm.Model():
cov_func = gp.cov.Matern32(1, ls=[10])
gp = pm.gp.Marginal(cov_func=cov_func)
f = gp.marginal_likelihood('f', X=x.reshape(-1, 1), y=y, sigma=1)
x_rv = pm.Uniform('x_rv', -10, 10, shape=(1,1)) # Xnew below has to have shape (n, 1) according to docs
pred = f.predict(Xnew=x_rv, diag=True)
...
Ignore what comes after since the code execution hasn’t even made is that far yet, this code spits the error
Cell In[28], line 14
11 f = gp.marginal_likelihood("f", X=x.reshape(-1, 1), y=y, sigma=1)
13 x_rv = pm.Uniform('x_rv', -10, 10, shape=(1,1)) # Xnew below has to have shape (n, 1) according to docs
---> 14 pred = gp.predict(Xnew=x_rv)
16 pm.sample()
File ~/python_venvs/pymc5_venv/lib/python3.10/site-packages/pymc/gp/gp.py:638, in Marginal.predict(self, Xnew, point, diag, pred_noise, given, jitter, model)
636 mu, cov = self._predict_at(Xnew, diag, pred_noise, given, jitter)
637 print(mu, cov)
--> 638 return replace_with_values([mu, cov], replacements=point, model=model)
File ~/python_venvs/pymc5_venv/lib/python3.10/site-packages/pymc/gp/util.py:77, in replace_with_values(vars_needed, replacements, model)
68 fn = compile_pymc(
69 inputs,
70 vars_needed,
(...)
73 on_unused_input="ignore",
74 )
76 # Remove unneeded inputs
---> 77 replacements = {name: val for name, val in replacements.items() if name in input_names}
78 missing = set(input_names) - set(replacements.keys())
80 # Error if more inputs are needed
AttributeError: 'NoneType' object has no attribute 'items'
I have tried to circumvent this problem by using x_rv_arr = pm.floatX(x_rv)
, which as I understand ought to convert a TensorVariable
to a ndarray
, and passing this as Xnew
but it didn’t work. I get the same error.