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
Click For Summary
SUMMARY

The forum discussion centers on using the Python package Emcee for Monte Carlo fitting and MCMC analysis. The user experiences rapid convergence and unusual parameter plots, suspecting issues related to the burn-in period. Recommendations include adjusting the burn-in settings and utilizing the EnsembleSampler to manage the sampling process effectively. The discussion highlights the importance of discarding initial samples to improve parameter estimation accuracy.

PREREQUISITES
  • Familiarity with MCMC (Markov Chain Monte Carlo) techniques
  • Understanding of likelihood and posterior probability in statistical modeling
  • Experience with the Emcee Python package for MCMC sampling
  • Basic knowledge of parameter estimation and convergence diagnostics
NEXT STEPS
  • Explore the Emcee documentation for advanced usage and configuration options
  • Learn about burn-in strategies in MCMC analysis to improve sampling accuracy
  • Investigate convergence diagnostics techniques for MCMC chains
  • Study the impact of random walks on parameter estimation in MCMC
USEFUL FOR

Data scientists, statisticians, and researchers involved in Bayesian analysis and MCMC methods, particularly those transitioning from R to Python for statistical modeling.

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: 542
  • plot1.png
    plot1.png
    56 KB · Views: 566
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)
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
28
Views
4K