Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different shades colours appearing in panels of the same triangle plot #147

Closed
Stefan-Heimersheim opened this issue Mar 9, 2021 · 3 comments

Comments

@Stefan-Heimersheim
Copy link
Collaborator

Stefan-Heimersheim commented Mar 9, 2021

Describe the bug
When plotting contours with samples.plot_2d, in some cases the colours have different shades of Blue, but I would expect all the 68% regions to have the same colour.

To Reproduce
I didn't figure out under what conditions this happens. It does when I use my data:

fig, ax = dynesty_results.plot_2d(paramNames, types={'lower':'kde'})

screenshot_2021-03-09_12-16-19
The central panel is a darker blue which is confusing. It doesn't seem to occur with simple toy data though. Same with the new feature from #145:

fig, ax = dynesty_results.plot_2d(paramNames, types={'lower':'hist', 'diagonal':'filledfastkde'})

screenshot_2021-03-09_12-16-10
Here the colours seem all over the place.

Expected behavior
All 68% contours should be the same dark blue, and all 95% contours the same light blue. Like in this toy model:

a = anesthetic.samples.MCMCSamples(np.random.normal(loc=0, scale=1, size=(10000, 5)))
a.plot_2d(range(5),types={'lower':'kde'})

screenshot_2021-03-09_12-23-45

Additional context

  • Occurs in the current master version as well as the fork in 1d Confidence Regions #145.
  • I am using a jupyter-notebook
  • The runs are produced with dynesty
dynesty_sampler = dynesty.DynamicNestedSampler(loglikelihood, uniform_to_params, nDim)
dynesty_sampler.run_nested()
dynesty_to_anesthetic = lambda s: anesthetic.samples.NestedSamples(data=s['samples'], weights=np.exp(s['logwt']), logL=s['logl'], columns=paramNames, tex=texDict)
dynesty_results = dynesty_to_anesthetic(dynesty_sampler.results)

Edit: It does not seem to always occur with dynesty and jupyter-notebook either, this toy model produces results as expected:

import anesthetic
import dynesty
import scipy.stats as sst
import numpy as np
import matplotlib.pyplot as plt

toylike = lambda p: sst.multivariate_normal.logpdf(p, mean=[0,0,0,0,0])
u = lambda x:x
s = dynesty.NestedSampler(toylike, u, 5)
s.run_nested()
dynesty_to_anesthetic = lambda s: anesthetic.samples.NestedSamples(data=s['samples'], weights=np.exp(s['logwt']), logL=s['logl'])
r = dynesty_to_anesthetic(s.results)
r.plot_2d(range(4))
plt.show()

Do you have any idea where this comes from or how I can debug this?

@williamjameshandley
Copy link
Collaborator

williamjameshandley commented Mar 9, 2021

This here is a feature rather than a bug. On the GitHub frontpage README.rst:

  1. Many KDE plotting tools have conventions that don't play well with uniformly distributed parameters, which presents a problem if you are trying to plot priors along with your posteriors. anesthetic has a sensible mechanism, by defining the contours by the amount of iso-probability mass they contain, but colouring the fill in relation to the probability density of the contour.

The idea is that the colour dependency on height encourages you to intepret the nearly flat contours as being less tapered. If the 2-sigma contours were coloured lighter regardless of the height of the contour, then the eye can interpret that region as being more excluded than it is.

@Stefan-Heimersheim
Copy link
Collaborator Author

Stefan-Heimersheim commented Mar 9, 2021

Oh thanks for explaining this! I didn't realize what that meant but now that you say it I see that this refers to this effect. So do I understand this correctly, the lines refer to the confidence limit as in

int_{-inf}^{lower line} posterior(x) = 0.16, int_{lower line}^{upper line} posterior(x) = 0.68
Edit: I assumed a symmetric posterior here, not necessarily true for asymmetric cases I think

and the color refers to the average posterior/pdf in the region?

color = int_{lower line}^{upper line} posterior(x) dx / int_{lower line}^{upper line} 1 dx

I am not sure about the 2nd one / how exactly the color "in relation to the probability density" is defined

@williamjameshandley
Copy link
Collaborator

The color refers to the value of the iso-probability density contour (relative to the maximum). Basically it's a cmap(p/pmax).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants