What is the purpose of a burned trace?

I’m reading [Probabilistic Programming for Hackers] (https://nbviewer.jupyter.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/blob/master/Chapter2_MorePyMC/Ch2_MorePyMC_PyMC3.ipynb) and i’m wondering why did he used the first few data points from trace as a posterior distribution?

step = pm.Metropolis()
trace = pm.sample(20000, step=step)

Random walk MH sampler usually converge to the typical set very very slowly in high dimension, thus it becomes a good practices to discard the first few thousand samples that are not yet in the typical set.

You usually dont need it any more using modern sampler like NUTS or HMC, because they find the typical set very quickly.


I’m having a problem with the above code (from the book/github site) and I can’t tell if it’s because of a version change or something else. When entering those same 3 lines of code I get an error for
burned_trace = trace[1000:]
KeyError: slice(1000, None, None)
Any suggestions?

If you are using a newer version of pymc (e.g., >=4.0.0), then pm.sample() defaults to returning a trace of a new type (an arviz InferenceData object). So your handling of the trace will need to change accordingly. See here.