# Blog

## 5000+ Members

### MEETUPS

LEARN, CONNECT, SHARE

Join our meetup, learn, connect, share, and get to know your Toronto AI community.

### JOB POSTINGS

INDEED POSTINGS

Browse through the latest deep learning, ai, machine learning postings from Indeed for the GTA.

### CONTACT

CONNECT WITH US

Are you looking to sponsor space, be a speaker, or volunteer, feel free to give us a shout.

# [D] How to compute the “true” posterior for a generative model?

I have seen a few papers that show plots of the “true posterior” for a generative model on a toy problem.

Before I did not understand how this could be computed, but now maybe I am closer. I’m sure you can help me

Is this the way to do it? (See below)

Definitions and setup:

The generative model is p(x|z)*p(z). The posterior is p(z|x).

A particular x is given and we want to know the distribution p(z|x) for that x,

using p(z|x) ~ p(x|z)*p(x) ,

i.e. without evaluate the Bayes denominator.

1. Sample z from p(z),
2. evaluate p(x|z) for the given x, and multiply this by p(z) for the z that was sampled in step 1. This gives an “unnormalized” probability for this particular z.
3. Accept this new z as a sample using MCMC, e.g. metropolis-hasting.
4. Repeat 1-3, and then eventually make a kernel density plot of the resulting z sample locations.