Efficient Monte Carlo Fitting with Python Package Emcee and MCMC Analysis

  • Context: Undergrad 
  • Thread starter Thread starter Silviu
  • Start date Start date
  • Tags Tags
    Fitting Monte carlo
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
Silviu
Messages
612
Reaction score
11
Hello I use a python package called emcee to fit a function to some data points. The fit looks great, but when I want to plot the value of each parameter at each step I get the plot.png below. In their example (with a different function and data points) they get the plot1.png image. Why is my function converging so fast, and why does it have that weird shape in the beginning. I apply MCMC using likelihood and posterior probability. And even if the fit looks very good, the error on parameters of function are very small (10^10 smaller than the actual value) and I think it is because of the random walks. Any idea how to fix it?
 

Attachments

  • plot.png
    plot.png
    9.1 KB · Views: 568
  • plot1.png
    plot1.png
    56 KB · Views: 603
Physics news on Phys.org
That looks like it is just the burn in period. Usually people just discard the first few thousand points in order to avoid that.

I have done all of my MCMC work in R, so I am not familiar with the Python package you mention, but it looks like it is either set with a burn in of 0 or it plots the burn in samples.
 
If you're using emcee something like this will help overcome the burn in:
sampler = EnsembleSampler(...)

pos, prob, state = sampler.run_mcmc(...)

sampler.reset()

sampler.run_mcmc(pos, 1000, rstate0=state)