I’m fitting a simple model but using a custom prior distribution, so my model looks like:
def distprior3(r, rlen):
r, rlen = r.value, rlen.value
if r > 0:
prior = (1/(2*rlen**3) * r**2 * np.exp(-r/rlen))
else:
prior = 0
return prior
def singlestar_distance(w, wsd, star):
with pm.Model() as model:
# Hyperprior on length scale (in pc)
tmp = pm.Uniform('tmp', 0.1, 4000)
# Distance prior
r = pm.DensityDist('r', distprior3,
observed={'r': (1/(w*1e-3)), 'rlen': tmp})
r = r.data['r'].value
# The data likelihood function
loglikelihood = pm.Normal('dist', mu=1/r, sd=(wsd*1e-3) )
trace = pm.sample(sample=1000, tune=1000)
The problem is that when I try to pass the ‘tmp’ hyperprior to ‘r’, the model crashes with the error:
ValueError: Mass matrix contains zeros on the diagonal.
The derivative of RV
tmp_interval__
.ravel()[0] is zero.
When I just pass a number like,
r = pm.DensityDist('r', distprior3,
observed={'r': (1/(w*1e-3)), 'rlen': 1000})
It runs fine. Any suggestions of what might be going wrong?