joshspeagle / dynesty

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

How to get the MAP from chains? #449

Closed epaillas closed 1 year ago

epaillas commented 1 year ago

Hi, apologies for the basic question, but I'm working with some dynesty chains that include the following columns:

log_likelihood, log_weights, log_evidence, log_evidence_err, param1, param2...

I'm interested in calculating the maximum a posteriory probability for each chain. Some parameter priors are Gaussian, others are uniform.

This is my first time working with dynesty so I'm a bit lost. I don't see a column explicitly recording the log posterior, so I'm guessing it can be derived from the other columns? What's the best way to approach this?

segasai commented 1 year ago

Hi,

It's hard to tell. given that nowhere in the dynesty code 'log_evidence' term/variable is used. But if you have log-likelihood, uou should be able to to compute the log-posterior by adding log-prior to it. (it is not saved explicitely in dynesty, so you'll need to compute logprior yourself)

epaillas commented 1 year ago

Hi, thanks for the reply. According to https://dynesty.readthedocs.io/en/stable/quickstart.html, the dictionary containing the full set of quantities from the sampling results includes:

which should correspond to the log_evidence and log_evidence_err columns in my files. I was wondering if this would have to be included in the determination of the log posterior. If it's just an overall normalization factor, I guess it shouldn't impact the MAP, so I'll go ahead and try to compute the log posterior from the likelihood and prior.

segasai commented 1 year ago

The logz will not help you determine the MAP value according to my understanding (as this is cumulative evidence up to that point). I think the only choice I can see is to take logl values and add to them logprior values that you will need to compute.