MCMC Trace Plot in Edward

345 views Asked by At

I'm using a Dirichlet Process Mixture Model (DPMM) to infer cluster assignments and cluster parameters on a synthetic dataset using Edward based on the following community post. I'm using GPU-accelerated Metropolis Hastings to learn the posterior distribution over model parameters. For example, for cluster means, we have:

D = 2 #dimension of the data
K = 5 #cluster truncation
T = 10000 #number of samples
mu = Normal(loc=tf.zeros(D), scale=tf.ones(D), sample_shape=K)  
qmu = Normal(loc=tf.zeros(D), scale=tf.ones(D), sample_shape=K) #posterior
gmu = Normal(loc=tf.zeros(D), scale=tf.ones(D), sample_shape=K) #proposal

inference = ed.MetropolisHastings(
    latent_vars={mu: qmu, ...},
    proposal_vars={mu: gmu, ...},
    data={x: x_data})

I'm interested in generating a trace-plot to visualize samples from the posterior distribution qmu. I'm looking for something similar to PyMC pm.traceplot() How do I generate a trace plot in Edward?

1

There are 1 answers

0
Vadim Smolyakov On BEST ANSWER

For an Empirical distribution used in sampling, we can access the sampled values as follows:

thin=4
burnin=2000
qmu_trace = qmu.params[burnin::thin].eval()

We can then plot the trace and compute histogram and auto-correlation as usual.