Prediction or Criticism of the model mean()


Hi all

I’m trying to run criticism of a simple bayesian linear regression model

When calling, feed_dict=X_tst) the result varies each time this is run. I suspect this has something to do with the variational parameter distributions not being set to return their mean. Is this correct and if one wanted exactly the same predictive mean would you have to specify the variational distributions to be the mean values?

i.e. when calling

mean =, feed_dict=X_test)

Should the definintion of Y_post be defined instead of

Y_post = ed.copy(Y, {W: qW, … } )


Y_post = ed.copy(Y, {W: qW.mean(), … } )

is this the correct way to do this? If not what is the recommended way to do this


Fetching y_post draws new parameters because any random variables it depends on in the computational graph are redrawn. The same happens if you try to fetch x in the program
theta = Beta(1.0, 1.0); x = Bernoulli(probs=theta, sample_shape=50).

Consider what this means mathematically. The first line represents the posterior predictive,

p(xnew | x) = \int p(xnew | theta) p(theta | x) d\theta

The second line represents the likelihood with parameters given by the posterior mean, p(xnew | theta = mean(p(theta | x))).

In general, to calculate something like the posterior predictive mean you should fetch y_post many times and average.


Thanks Dustin!

To clarify, is there any difference in running Y_post, Y_post.mean() and multiple Y_post.sample() and then averaging their results; with Y_post.sample([num_samples]) being the most efficient to obtain an approximate posterior mean?



It’s worth working out what these mean:

  • np.mean([ for _ in range(50)]) fetches a posterior sample; then likelihood sample; then repeats 50 times and takes the mean.
  • fetches a posterior sample, then takes the likelihood’s mean given the single posterior sample.
  •[num_samples])) fetches a posterior sample, then draws num_samples samples from the likelihood given the single posterior sample.

Only the first method is correct.


cheers; this makes things clearer