Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

I Monte Carlo for fitting

  1. Sep 11, 2016 #1
    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?

    Attached Files:

  2. jcsd
  3. Sep 11, 2016 #2


    Staff: Mentor

    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.
  4. Sep 12, 2016 #3


    User Avatar
    Education Advisor

    If you're using emcee something like this will help overcome the burn in:
    sampler = EnsembleSampler(...)

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


    sampler.run_mcmc(pos, 1000, rstate0=state)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted