vkv
October 19, 2020, 9:12pm
1
I am trying to write model in pymc3 and use jax and tensorflow probabilty for inference using this notebook by junpenglao .
The code for the model is as follows:
y = np.random.rand(10,1)
A = np.log(np.random.rand(10,10))
m,n= np.shape(A)
mc = np.shape(y)[1]
with pm.Model() as model:
q = pm.Uniform('scale', 4, 5)
lsd = pm.Uniform('lsd', 1, 2, shape=n)
beta = [pm.Bound(pm.Laplace, lower=1, upper=10).dist('beta', mu=5.0, b=lsd[i]) for i in range(n)]
mu = pmmath.logsumexp(A - beta / q, axis=0)
mu = np.tile(mu, (mc,1)).T
noise_sigma = pm.Bound(pm.Normal, lower=0).dist('noise_sigma', mu=0, sigma=1)
y_rv = pm.MvNormal('y', mu = mu, chol = noise_sigma * np.eye(mc), shape=(m,mc), observed=y)
I’m getting the following error when I execute the model cell.
TypeError: Unsupported dtype for TensorType: object
This is due to beta
variable is of type object
.
I’m also facing similar error on the last line y_rv
, where noise_sigma is of type _ContinuousBounded
.
How to resolve these errors? Please excuse me, this is my first time using the pymc3.
vkv
October 20, 2020, 5:17am
2
This started working after I’ve changed the code to following, atleast the code executes without any errors.
y = np.random.rand(10,1)
A = np.log(np.random.rand(10,10))
m,n= np.shape(A)
mc = np.shape(y)[1]
with pm.Model() as model:
q = pm.Uniform('scale', 4, 5)
lsd = pm.Uniform('lsd', 1, 2, shape=n)
u = pm.Bound(pm.Laplace, lower=1, upper=10)('u', mu=5.0, b=lsd, shape=n)
mu = pmmath.logsumexp(A - u / q, axis=0)
noise_sigma = pm.Bound(pm.Normal, lower=0)('noise_sigma', mu=0, sigma=1)
y_rv = pm.MvNormal('y', mu=tt.tile(mu, (mc,1)).T, chol=noise_sigma * tt.eye(mc), shape=(m,mc), observed=y)
But when I try running it with jax, I get the following error: https://pastebin.com/yL85rCL1
Is the model definition correct?
I have seen similar error when trying to write a mixture model, but have not yet pin down where is the bug yet - could you open an issue on Theano-pymc?
My guess is that some Theano Ops are just itself represented as a list - might need to assign an identity Ops to them or something.
2 Likes
vkv
October 20, 2020, 8:44am
4
I’ve opened the issue on Theano-pymc
1 Like