Manually sampling from prior predictive

I would like to sample from prior predictive manually. I’m referring to the documentation in the section Using PyMC Distributions without a Model of this tutorial, but I get an error:

y = pm.Binomial.dist(n=10, p=0.5)
y.random(size=3)

AttributeError: The rv.random() method was removed. Instead use rv.eval().`

I’m using 4.0.1 and see that the doc is for version 3, so is there a different syntax for 4?

The updated documentation is here.

I think this is what you are looking for: pymc.draw — PyMC dev documentation

The updated doc is the same as for version 3. With the pm.draw syntax, how would I sample from prior predictive when my likelihood is a mixture model?

with pm.Model() as model_mix:
    mu1 = pm.Normal('mu1', mu = 1.73, sigma = 0.035)
    sigma1 = pm.HalfNormal('sigma1', .03)
    mu3 = pm.Normal('mu3', mu=1.85, sigma = 0.025)
    sigma3 = pm.HalfNormal('sigma3', .02)

    norm1 = pm.Normal.dist(mu=mu1, sigma = sigma1)
    norm3 = pm.Normal.dist(mu=mu3, sigma = sigma3)

    w = pm.Dirichlet('w', a=np.array([1, 1]))

    like = pm.Mixture('like', w=w, comp_dists = [norm1, norm3], observed=obs_array)

    trace_mix = pm.sample()

Have you seen pymc.sample_prior_predictive — PyMC dev documentation ?

I’ve checked it out, but it’s a little too complex . Was hoping there would be a simpler way to recreate samplie_prior_predictive by sampling the parameters separately.

You can call pm.draw on a likelihood (or any other model variables)

So pm.draw works well to sample either from the separate priors (mu1, norm1, sigma1, sigma3) or from the likelihood. So that’s good. However, how would I sample from the full prior distribution (basically specifying the mixture model but without conditioning the data on the belief).

I don’t understand what you mean with

I want to replicate sample_prior_predictive manually. How would I do that with pm.draw?

You call pm.draw on all model variables


with pm.Model() as m:
  x = ...
  y = ...
  z = ...

pm.draw([x, y, z], draws=500)
# or
pm.draw(m.basic_RVs, draws=500)