Efficient Monte Carlo Fitting with Python Package Emcee and MCMC Analysis

In summary, the conversation discusses using the Python package emcee to fit a function to data points. The speaker is concerned about the fast convergence and strange shape of the function, as well as the small errors on the parameters due to random walks. The other speaker suggests discarding the first few thousand points to avoid the burn in period. They also mention using something like a reset function in order to overcome the burn in.
  • #1
Silviu
624
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: 464
  • plot1.png
    plot1.png
    56 KB · Views: 476
Physics news on Phys.org
  • #2
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.
 
  • #3
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)
 

What is Monte Carlo for fitting?

Monte Carlo for fitting is a statistical method used to fit a model or function to a set of data points by generating random samples and evaluating the model for each sample.

What are the advantages of using Monte Carlo for fitting?

One advantage of using Monte Carlo for fitting is that it can handle complex models with many parameters. It also provides a robust estimation of the model parameters and their uncertainties.

How does Monte Carlo for fitting work?

Monte Carlo for fitting works by randomly sampling values for the model parameters and evaluating the model for each sample. The results are then used to estimate the most likely values for the parameters and their uncertainties.

What types of models can be fitted using Monte Carlo?

Monte Carlo for fitting can be used to fit a wide range of models, including linear, non-linear, and multi-dimensional models. It can also handle models with complex relationships between the parameters.

What are some common applications of Monte Carlo for fitting?

Monte Carlo for fitting is commonly used in physics, engineering, and other fields to fit models to experimental data. It is also used in finance and risk analysis to simulate and analyze complex systems.

Similar threads

  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
12
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
744
  • Set Theory, Logic, Probability, Statistics
Replies
8
Views
824
  • Set Theory, Logic, Probability, Statistics
Replies
16
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
28
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
814
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
2K
  • Programming and Computer Science
Replies
9
Views
2K
Back
Top