joshspeagle / dynesty

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

Importance weight PDF shape #469

Closed tjtakys closed 6 months ago

tjtakys commented 7 months ago

Dynesty version 2.1.2 (conda)

Your question Hello, I am using the nested sampler in dynesty to estimate the posterior distribution of model parameters. After running run_nested, I noticed that the results do not seem to converge well when looking at the corner plot. Additionally, when I use dyplot.runplot to visualize the run plots, the shape of the importance weight PDF seems unnatural to me. It has two peaks, and one of them is at the loglikelihood value of zero on the high lnX region. I suspect that the presence of weight in this low likelihood region is affecting the convergence of the final results in the corner plot. Initially, I thought the issue might be due to having too few live points, so I increased nlive_init from 1024 to 4096, but the results did not change. Why does the weight distribution have these two peaks? Any insights would be greatly appreciated. Thank you in advance. runplot

The script I used is attached.

segasai commented 7 months ago

Hi,

I can't comment on the question of the convergence, since you don't show anything that would suggest the lack of convergence, but the importance weight graph looks fine to me. The fact that it has multiple peaks is perfectly fine.

It is easy to make the importance weight graph of "any" shape even if you consider posteriors shaped like Gaussian mixtures of the form

$f_1 N(x|0,\sigma_1) + f_2 N(x|0,\sigma_2)$

tjtakys commented 7 months ago

Thank you for your comments! I'm sorry, the corner plot was in the attached .ipynb file. While I understand that the importance weight can exhibit a multimodal distribution when the posterior distribution is multimodal, I have another point that concerns me. I believe that the importance weight is the product of the likelihood and the decrease in volume. However, at the first peak of the importance weight, the likelihood is extremely low. In fact, I have looked at the observational and model images around this moment, and they were not modeled well at all. Compared to the run plot in the dynesty paper or example codes, the run plot I obtained has a high importance weight at a very early stage of sampling (where -ln X is close to 0). I am concerned about this. Do you think there might be a problem related to this? image

segasai commented 7 months ago

Thank you for your comments! I'm sorry, the corner plot was in the attached .ipynb file.

TBH I do not see anything suspicious in the corner plot

While I understand that the importance weight can exhibit a multimodal distribution when the posterior distribution is multimodal,

The posterior distribution does not need to be multimodal to show mutlimodality in the importance weigths. My example had only one one mode.

I have another point that concerns me. I believe that the importance weight is the product of the likelihood and the decrease in volume. However, at the first peak of the importance weight, the likelihood is extremely low. In fact, I have looked at the observational and model images around this moment, and they were not modeled well at all.

This seems to be a feature of your likelihood+prior. I.e. significant volume of your posterior seems to be there (at low logl values) . Whether that's how it should be, or you have incorrectly specified either the prior, or the likelihood I don't know. But those are the possibilities IMO.

Compared to the run plot in the dynesty paper or example codes, the run plot I obtained has a high importance weight at a very early stage of sampling (where -ln X is close to 0). I am concerned about this. Do you think there might be a problem related to this? !

Again on it's own the importance weight can show anything, it really depends on how the function log-likelihood vs prior volume above the logl value. For a typical Gaussian posterior, you only get one peak, for something very different you don't.

So personally I would check if your likelihood function is defined correctly.

tjtakys commented 6 months ago

Thank you for the detailed advice! I will check my code again.