JohannesBuchner / PyMultiNest

Pythonic Bayesian inference and visualization for the MultiNest Nested Sampling Algorithm and PyCuba's cubature algorithms.
http://johannesbuchner.github.io/PyMultiNest/
Other
194 stars 88 forks source link

Obtain modal posteriors? #169

Closed AlecThomson closed 3 years ago

AlecThomson commented 3 years ago

Hi there,

I've been using multinest for a model-fitting problem with:

multimodal = True

To obtain seperate out different modes in the posteriors, and correctly cluster the parameter values. We've also been using the posteriors directly to get asymmetric errors in our best-fit parameters using:

aObj = pmn.Analyzer(n_params=nDim, outputfiles_basename=nestOut)
aObj.get_equal_weighted_posterior()

In many cases, however, this is being thrown off by nearby modes in the posteriors. Is it possible to return the posteriors for a single mode only?

Thanks!

P.S. for reference, our complete model-fitting script is here

JohannesBuchner commented 3 years ago

If you turn off importance nested sampling, the mean and std of each mode is reported by multinest, and can be read with the analyser.

JohannesBuchner commented 3 years ago

(from ....stats.dat)

AlecThomson commented 3 years ago

Thanks! So we've been using those. It'd be really useful to get the distributions as well. Both to get possibly asymmetric errors, e.g. where std doesn't apply, and also for corner plot visualisation. Is that possible at all?

JohannesBuchner commented 3 years ago

I usually get the posterior points, and split them manually by mode (e.g., col1<0.5), and then you can get any statistics and higher modes based on the selected points.

AlecThomson commented 3 years ago

Ah, ok. I think that's what I've been trying (and failing) to apply. I don't completely follow how you do the splitting. What do you mean by col1? Are you able to share a snippet? Thanks for your help with this

JohannesBuchner commented 3 years ago

Your posterior is a 2d array, with the columns identifying the parameters, and each row a "solution". You look at the corner plot, identify where each mode lies, then develop some criteria to isolate them. Use numpy masks to select the points for one mode.

rpoleski commented 3 years ago

I think @AlecThomson wants to get the information that is in ROOTpost_separate.dat file. Different modes are separated by 2 blank lines. Separating "by hand" can be very inefficient if modes are overlapping in different parts of the corner plot.

AlecThomson commented 3 years ago

Thanks @rpoleski, that looks exactly like what I'm after! I'm guessing the order is the same as reported in the stat file?

JohannesBuchner commented 3 years ago

It's documented in the README https://github.com/JohannesBuchner/MultiNest/

[root]post_separate.dat This file is only created if mmodal is set to T. Posterior samples for modes with local log-evidence value greater than Ztol, separated by 2 blank lines. Format is the same as [root].txt file.

I am closing this issue now. Please reopen if you want Analyzer to be able to read the file.