Search code examples
bayesiansimulationpymc

How to simulate from priors with pymc3


I'd like to simulate y from the prior (not from the posterior) with pymc3.

I first defined the model:

import pymc3 as pm

with pm.Model() as m:
    mu = pm.Normal('mu', mu=0, sd=10)
    sigma = pm.Uniform('sigma', lower=0, upper=10)
    y = pm.Normal('y', mu=mu, sd=sigma)
    trace = pm.sample(1000, tune=1000)

Then I tried to get 10 simulated y from the model with:

y_pred = pm.sample_ppc(trace, 10, m, size=10)

But result comes out empty. I searched through the documentation but I didn't find a relevant example. Is it possible to do it with pymc3?


Solution

  • The trace contains the sample from the prior when no observed is associated with the model definition. However, this could fail sometimes. We are currently working on a sample_prior function that would make this process easier and more straightforward: https://github.com/pymc-devs/pymc3/pull/2876