joshspeagle / dynesty

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

Question on large negative logz #373

Closed Jayshil closed 2 years ago

Jayshil commented 2 years ago

Hi,

Thanks for creating this wonderful package! It is much useful in my research. Recently, while using dynesty in one of my analyses, I ran into something peculiar.

A bit of background: I am trying to fit a model (4 Gaussian + linear trend) to spectrum data with dynesty (version 1.2.2). I am using dynamic dynesty as follows:

dsampler = dynesty.DynamicNestedSampler(loglikelihood=log_like, prior_transform=prior_transform,\
    ndim=14, nlive=500, bound='multi', sample='rwalk')
dsampler.run_nested()
dres = dsampler.results

The output was,

62392it [53:13, 19.54it/s, batch: 4 | bound: 5 | nc: 34 | ncall: 2061630 | eff(%): 3.026 | loglstar: -976412117.210 < -inf < -976412116.450 | logz: -inf +/- 3.143 | stop: 0.999]

suggesting that the final calculated logz is -inf. And indeed when I printed dres.logz[-1], it gave me -976412216.986027. Since I am new to nested sampling, I am not sure if this is correct, or usual?!

One thing should be noted that the posteriors were just fine -- it is just this logz calculation that bothers me. That makes me wonder whether I should believe posteriors or not.

By the way, a working example of the issue can be found in this jupyter notebook (along with the data used).

Thanks for your help, Jayshil

segasai commented 2 years ago

Hi,

Otherwise there is nothing necessarily wrong with large negative logz values.

Jayshil commented 2 years ago

Hi @segasai,

Thanks for your quick reply -- this was very helpful!

My dataset is consisting of a total of 32k points (and 14 free parameters) and not 90k points.

I don't know if you have a good fit. I.e. since you have an essentially a chi-square likelihood, you'd expect the peak logl(l) value to be of the order of -0.5*ndim (where ndim =90k). And the logz should be not too far from that. So you should check if your peak logl values make sense (i.e. correspond to reduced chisq of ~ 1)

According to this, my logl should be of the order of -0.5*32k=-16k? However, dres.logl[-1] would give -976411898.6459092 which is nowhere near 16k (which is near to the computed logz though).

Thanks again, Jayshil

segasai commented 2 years ago

The logl value you get ( which corresponds to chi-square) is likely too low, but this really has nothing to do with dynesty, but instead with your data, model and goodness of fit of the best model.

Jayshil commented 2 years ago

Alright, thanks for your feedback. I will try fitting with some other models (and maybe priors) to improve the quality of the fit.