Hello,
I’m looking to build on the technique demonstrated in the “Updating Priors” notebook in the PyMC3 documentation. I have an initial model parameter which has a shape argument passed to indicate that it’s vector-valued.
Once I do an initial run of the model, is it possible to create, in a new model, an Interpolated parameter from the trace of my vector-valued parameter such that the shape is preserved from the original parameter? I tried doing a crude edit of the from_posterior
function from the above notebook like so:
def from_posterior_multi(param, samples):
smin, smax = np.min(samples, axis=0), np.max(samples, axis=0)
width = smax - smin
x = []
y = []
for i in range(width.shape[0]):
x_i = np.linspace(smin[i], smax[i], 100)
y_i = stats.gaussian_kde(samples[:,i])(x_i)
# what was never sampled should have a small probability but not 0,
# so we'll extend the domain and use linear approximation of density on it
x.append(np.concatenate([[x_i[0] - 3 * width[i]], x_i, [x_i[-1] + 3 * width[i]]]))
y.append(np.concatenate([[0], y_i, [0]]))
return pm.Interpolated(param, x, y, shape=width.shape[0])
but I got the following error when I tried to create an Interpolated parameter this way:
error: failed in converting 2nd argument `y' of dfitpack.fpcurf0 to C/Fortran array
Am I trying to force pm.Interpolated
to do something it doesn’t want to in terms of shape?
Apologies if I’ve missed the answer lurking somewhere here or in the docs!
Thanks,
Johannes