corner.py icon indicating copy to clipboard operation
corner.py copied to clipboard

Apply priors on 1 and 2d histograms

Open ceyzeriat opened this issue 10 years ago • 3 comments

Hi, Not too much of an issue here, more of an additional feature. The idea is to multiply the 1d and 2d histograms curves/surfaces with the respective prior of each parameter, so that the full "posterior distribution" is plotted - not just the likelihood of the raw samples.

It seemed that the "weights" arguments served another purpose, so I hacked something together. It actually holds in a tiny amount of lines. Only one new input argument "priors" is needed. It is a N-list of (callable, dict) (for N parameters). The callable argument being the function to call with the dict as *_kwargs: prior_prob = callable(x, *_dict). The only drawback is the loss of the parameter "histtype" (hist_kwargs["histtype"]) for the 1d histograms, since they are now always plotted with ax.plot(...) whether they have smoothing or not. Cheers, G. Schworer @ceyzeriat

ceyzeriat avatar Jul 17 '15 16:07 ceyzeriat

Can you explain what you think weights does differently? That's exactly what it was for!

dfm avatar Jul 19 '15 19:07 dfm

Indeed weights parameter of np.histogram or plt.hist is the way to apply a prior to the histogram. However from reading your code, the same weight/prior is applied to each parameter the same way. e.g. for a 3 parameters triangle plot, the input data will be shape(N, 3). If I have different weights/priors for each parameter, I would like to have my weight data to be shape(N, 3). But for now the weights parameter must be shape(N). Or maybe I just missed something too obvious!

ceyzeriat avatar Jul 22 '15 13:07 ceyzeriat

I'm trying to catch up on old issues here:

Each weight corresponds to a specific sample with different parameter values in each case. In your case, I think what you would want is for the weight to be the product of priors evaluated at the parameter values of that sample.

dfm avatar May 26 '16 15:05 dfm