baudren / montepython_public

Public repository for the Monte Python Code
MIT License
65 stars 115 forks source link

Record individual likelihood in chain files #107

Open tririver opened 6 years ago

tririver commented 6 years ago

Hi everybody,

Is there an option to print individual likelihoods in chain files? For example, in CosmoMC, if both CMB and BAO data are used, in the chain files there are columns for chi2_CMB* and chi2_BAO* respectively. Would MontePython have this feature?

Thanks in advance :)

brinckmann commented 6 years ago

Hi,

This is not currently implemented. We have the option --display-each-chi2 when using 'run', which you can e.g. use along with -f 0 to print the -loglkl and effective chi2 for each likelihood in the best fit.

If this is not enough, in order to have it output in the chain, this should be possible, but it will take some modifications of (at least) montepython/mcmc.py, montepython/io_mp.py and montepython/sampler.py.

I think the way I would do it is I would set the compute_lkl function in sampler.py to return the current loglkl along with the full information loglkl information for each likelihood following the approach of the --display-each-chi2 option in the same function.

This will break montepython/mcmc.py, which uses the loglkl output from sampler.py by calling sampler.compute_lkl, as well as any other place the code uses this. So what you want to do is you want a 'loglkl' variable that functions as currently, and a 'loglkl_all' that contains the full information of total_loglkl and each_loglkl. You then need to pass loglkl_all' to all instances using io_mp.print_vector.

Finally, you need to make sure the print_vector function in io_mp.py correctly processes the array loglkl_all, this is just simple string formatting.

I can't promise this won't introduce additional bugs, but hopefully you can figure out how to handle them if it does. Otherwise, you can ask again. If you get it to work, I would appreciate if you reply with your final solution and I will consider including it in the public version. Thanks!

Best, Thejs