joshspeagle / dynesty

Dynamic Nested Sampling package for computing Bayesian posteriors and evidences
https://dynesty.readthedocs.io/
MIT License
346 stars 76 forks source link

An issue about dynesty posterior #452

Closed wdqfdr closed 11 months ago

wdqfdr commented 11 months ago

Hi, I'm sorry to bother you. I've recently been using Dynesty for sampling to obtain posterior distributions, and I've noticed that the parameter ranges of the results I obtained are not covering the entire prior range I set. So, I referred to your documentation and created traceplots. Therefore, I'd like to ask if the yellow region shown in the traceplot represents the area where importance weighting is applied, and if the posterior distribution results I'm obtaining are confined to this region from where it starts? Thanks!

segasai commented 11 months ago

I'm sorry but there is not enough info here. i.e. which yellow region you are talking about and what you think is wrong. Please provide more details including plots to illustrate your question https://github.com/joshspeagle/dynesty/blob/master/demos/Demo%201%20-%20Overview.ipynb -- check here and in other notebooks for how plots should look like.

wdqfdr commented 11 months ago

Thank you for your reply and I'm sorry for the delay. I want to ask some questions about dynesty results and plots. I'm using dynesty to do some work about the Bayes factor and posterior estimation. The question I asked earlier is whether the posterior probability distribution results provided by dynesty are the results after the region colored (yellow) in traceplot at -lnX, which means where the samples are weighted? This is the traceplot: dyresult However results are now found to have significant deviations. The result looks like:

35907it [1:54:23, 5.23it/s, batch: 4 | bound: 28 | nc: 1 | ncall: 1027630 | eff(%): 3.449 | loglstar: -93.740 < -86.208 < -88.348 | logz: -139.041 +/- 0.247 | stop: 0.872] dyresult The truth values only show in x1 and x5. Through dynesty, I cannot obtain the original injected values, and I have also tried adjusting the bounds and samples, but the results remain the same. In runplot, compared to the graphs in your example, the likelihood seems to have an issue. : dyresult I am so sorry to bother you. I'm new to mcmc type calculation, so I wanted to ask what adjustments can be made to ensure that I can obtain the correct results.

segasai commented 11 months ago

It looks like your problem have multiple modes and likely dynesty is not picking up the right one.

In the left panel of the very first plot you can see multiple modes and the code jumping from one to another. It is hard to give a universal solution to this problem as if you have a very broad prior with many modes, it's impossible to guarantee that you find one.

If your problem is well posed and you are confident that that the true value of model parameters return very high likelihood you may want to try using more walkers/ restrict prior range to help the mode discovery. But it's really hard to tell without having an idea how the likelihood surface looks like

wdqfdr commented 11 months ago

Thank you for your reply! It works! I get a nice posterior distribution with more walkers in rwalk method. I'm a bit confused about the traceplots of results.

dyresult2

Is the posterior distribution of the parameters provided by dynesty starting from where I marked? (it mean where the samples are weighted?)

segasai commented 11 months ago

Glad it worked better.

The posterior distribution is not just truncated at the point you have marked. The posterior is constructed from weighting of all the live-points. The weights for live points below the 'yellow region' will be extremely small.

wdqfdr commented 11 months ago

Thank you very much for your help! It has been really helpful to me, and I will try more calculations again.