Hi pymc Comunity,
I’d like to do posterior predictive checks on a DensityDist.
I’m implementing a random method for the custom DensityDist distribution, however, the ‘random’ values produced are conditional on other observed data. How can I get this data into the random() method? Maybe something to do with the point input?
I have a simplified version on my code below, where a value (next_epoch) is sampled categorically, conditioned on another value (current_epoch)
with pm.Model() as model:
BoundedNormal = pm.Bound(pm.Normal, lower=0, upper=1)
trans_baserate = BoundedNormal('trans_baserate', mu=0.5,
sd=1e5, shape=(nstages, nstages))
def logp(current_epoch, next_epoch):
current_idx = tt.cast(current_epoch, 'int16')
next_idx = tt.cast(next_epoch, 'int16')
cat = pm.Categorical.dist(p=trans_baserate[current_idx, :])
return cat.logp(next_idx)
def random(point=None, size=None):
trans_baserate_ = pm.distributions.multivariate.draw_values([trans_baserate], point=point, size=size)
def _random(point, trans_baserate, size=None):
trans_p = trans_baserate[point['current_epoch'], :] #Complains here :frowning:
return pm.distributions.dist_math.random_choice(p=trans_p, size=size)
return pm.distributions.multivariate.generate_samples(_random,
point=point,
trans_baserate=trans_baserate_,
size=size)
next_epoch = pm.DensityDist('next_epoch', logp,
observed={'current_epoch': data['current_epoch'],
'next_epoch': data['next_epoch']},
random=random)
The low response rate here makes me wonder if this is even possible? Maybe shared theano variables could help?