MCMC ensemble state reset after burn-in
bartdunlap opened this issue · comments
After burn-in, the fit_model
function loses the state, resetting it to a state that isn't burnt in (lines 879-881 in the fit
module):
# adjust the walkers to start around the MAP position from burnin
pos = emcee.utils.sample_ball(p1, std, size=ntemps*nwalkers)
pos = fix_pos(pos, free_param_names, params)
Here, the MAP values from the burn in distributions, p1, and an initial user-input scale for each, std, are used to generate a distribution of walkers that are fed into the production run. But these walkers will not, in general, have a distribution representative of the posterior. The production run should instead start the walkers from the state at the end of burn-in.
(The fix_pos
function here can also have the unintended consequence of moving the distributions off of those from the sample ball centered on p1 because fix_pos
uses p0, the initial guesses, and the initial scales, not just the bounds. But this will be moot if the final burn-in state is used to initialize the production run.)
Here's a plot demonstrating the problem (from a run with 200 walkers, an 800 step burn-in, and 50 production steps):
Wow - I never got a notification for this issue for whatever reason. Thanks for catching, and for the PR.
Merged your PR after some testing - thanks for the fix