Prediction or Criticism of the model mean()


#1

Hi all

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

When calling sess.run(Y_post.mean(), 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 = sess.run(Y_post.mean(), feed_dict=X_test)

Should the definintion of Y_post be defined instead of

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

as

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


#2

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.


#3

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?


#4

Yes.

It’s worth working out what these mean:

  • np.mean([sess.run(y_post) for _ in range(50)]) fetches a posterior sample; then likelihood sample; then repeats 50 times and takes the mean.
  • sess.run(y_post.mean()) fetches a posterior sample, then takes the likelihood’s mean given the single posterior sample.
  • sess.run(y_post.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.


#5

cheers; this makes things clearer