Understanding how Predictive works for generating predictions

Hello devs. I have some doubts about using Predictive from numpyro.infer, specifically the observation site posterior returned by it.

Suppose I’m using it to generate predictions at x which is of length 50.

predictive = Predictive(self._model, posterior_samples=posterior_samples)
predictions = predictive(key, x=x)

Now, predictions is a dictionary with observation site named “obs”. I’m trying to understand how predictions[“obs”] is obtained.

Firstly, predictions[“obs”] is of shape (\text{num_posterior_samples}, 50).

Suppose, the observation distribution of my model is a standard normal parametrized by mean a(x), which depends on x.

Now, predictions will also have a key called “a” containing the posterior predictive samples of the mean parameter.

Two options are:

  1. Sample from \mathcal{N}(\bar{a}(x), 1) num_posterior_samples times where \bar{a}(x) is the average of posterior predictive samples predictions[“a”].mean(axis=0)


  1. First select one a(x) from predictions[“a”], call it a'(x), then sample one observation from \mathcal{N}(a'(x), 1). Repeat this process num_posterior_samples times, ie., simply iterate through predictions[“a”], and for each iteration, only sample one observation.

Are we following 1 or 2? My guess would be 2, but we could also be doing something completely different which I’m not aware of.

can you please ask your question in the context of a particular model?

ok @martinjankowiak I’ll try to look for or create a toy example and update my question soon