Posterior values in factored pdf

I have a question on how we can use the posterior sampled values on a subsequent sample call. To expand, for the following pseudo-code

with pm.Model() as m1:
   mu1 = pm.Normal('mu1',mu=0,sigma=1)
   trace1 = pm.sample() # contains posterior for mu1 based on some likelihood fn

with pm.Model() as m2:
    mu2 = pm.Normal('mu2',mu=mu1,sigma=2)
    trace2 = pm.sample() # contains posterior for mu2 based on a different likelihood fn

Here mu2 uses mu1 as prior. If there was a joint pdf, we will have a single model with mu1 and mu2 posteriors computed together in a single sample call. Instead, lets say we have computed mu1’s posterior using a likelihood fn, and i want to use the posterior of that mu1 as the prior for mu2.

In the above code will the 2nd trace be based on prior of mu1 or posterior of mu1 (since a sample call was made)? If its based on the prior, how should i ensure that the posterior is used (e.g. fit a KDE to trace1 or use a different sample_xxx function etc.)

This notebook may help Updating priors — PyMC example gallery

You can also check out the new functionality in pymc-experimental.

1 Like

When using the prior_from_idata experimental feature as illustrated in the sample docs here, I get an error “numpy.linalg.LinAlgError: 0-dimensional array given. Array must be at least two-dimensional

Here is a super-simple code:

with pymc.Model(coords=dict(test=range(4), options=range(3))) as model1:
        a = pymc.Normal("a")
        trace = pymc.sample(progressbar=False)

with pymc.Model(coords=dict(test=range(4), options=range(3))) as model2:
        priors = pymc_experimental.prior_from_idata(trace, var_names=["a"])
        trace1 = pymc.sample_prior_predictive(100)

The error occurs in the chol decomposition in _mean_chol() See the source file here

What am i missing from the documentation?

I tried passing in an explicit shape parameter i.e. pymc.Normal(“a”, shape=1) and …var_names=[“a”], a=dict(shape=1)) but that didn’t help.

An example with explicit chain arguments and shape would help. TIA.

@ferrine ?

Seems like a bug

will be fixed soon fix unitary case by ferrine · Pull Request #67 · pymc-devs/pymc-experimental · GitHub


@raj47212 this is now fixed in master