Saving prior values for each sample as deterministic RVs

I’d like to save values of each prior in my model for each sample as a deterministic RV. At the moment, I’m doing it like this:

a = pm.Normal('a', mu=0., sd=1., testval=0.5.)
logp_a = pm.Deterministic('logp_a',
            pm.Normal.dist(mu=0., sd=1.).logp(a))

Is there an easier way to do this so I don’t have type in the parameters of the distribution every time I want save the value of the log prior for a given RV?

Did you ever figure out a solution to this? I have the exact question!

Similar idea, but here’s one way to do it that doesn’t require re-typing your parameter values. In my use-case, I needed to generate samples from the prior and store their values:

import pymc3 as pm
from pymc3.distributions import draw_values

with pm.Model() as model:
    x = pm.Uniform('x', 1, 5)
    y = pm.Normal('y', 0., 2.)
    log_prior = [
        pm.Deterministic('x_val', x.distribution.logp(x)),
        pm.Deterministic('y_val', y.distribution.logp(y)),
samples_values = draw_values([x, y] + log_prior, 
1 Like

No I never did figure it out. Your solution works great, thanks a lot!