-
-
Notifications
You must be signed in to change notification settings - Fork 393
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
[WIP] Add contours of highest posterior density for 2D KDE plot #1665
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
d49e526
Add a function to calculate HPD regions on 2D KDEs
wm1995 435d746
Add option to plot HPD regions to `plot_kde`
wm1995 9257f2b
Change `hpd_levels` to `levels` in `plot_kde`
wm1995 dcab869
Refactor `hpd_levels` to `hdi_levels` in helper fn
wm1995 4ff80d1
Refactor HDI contour fn to `_find_hdi_contours`
wm1995 cc8e72e
Update contour-finding to use corner.py algorithm
wm1995 23320e5
Increase clarity in `plot_kde` contour-finding
wm1995 19e8275
Add unit test for `_find_hdi_contours`
wm1995 45ef939
Add unit tests for `levels` keyword of `plot_kde`
wm1995 23757a8
Make minor stylistic changes for pylint compliance
wm1995 633899d
Update `_find_hdi_contours` docstring
wm1995 9a9239a
Update `plot_kde` docstring
wm1995 a9745b3
Update new unit tests for mypy compliance
wm1995 cf10583
Refactor `levels` and `hdi_levels` to `hdi_probs`
wm1995 7b5a53e
Add an example of the HDI contour plot interface
wm1995 1ddcacb
Add example to `plot_kde` docstring
wm1995 a5bbd61
Update CHANGELOG.md to add HDI contour feature
wm1995 3731a30
Update `plot_pair` to pass `kde_kwargs` by value
wm1995 d352b2f
Add example of KDE pair plot with HDI contours
wm1995 0fc524e
Update `kde_plot` HDI contour example docstring
wm1995 5a2d2df
Update docstring for `plot_kde`
wm1995 4aef438
Merge branch 'upstream/main' into hpd-contours
wm1995 9352c12
Add tests to catch bug in `plot_kde` with Bokeh
wm1995 6f2d912
Update docstring for `hdi_probs` arg in `plot_kde`
wm1995 014e0b7
Add unit tests for HDI contours with Bokeh backend
wm1995 9526274
Update title of existing Bokeh 2d KDE example
wm1995 14b126d
Add new examples for 2d KDE plots with Bokeh
wm1995 4b25e52
Update Bokeh `plot_pair` to deepcopy `kde_kwargs`
wm1995 3b56be1
Update example 2d KDE plot titles for clarity
wm1995 5595173
Update `plot_kde` to use `hdi_probs` over `levels`
wm1995 cf9be3f
Add unit tests to test `plot_kde` warnings
wm1995 2d70070
Update code to be Pylint-2.8.1 compliant
wm1995 1c496ac
Merge branch 'main' into hpd-contours
wm1995 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
""" | ||
2d KDE Bokeh | ||
============ | ||
2d KDE (default style) | ||
====================== | ||
|
||
_thumb: .1, .8 | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
""" | ||
2d KDE (custom style) | ||
===================== | ||
|
||
_thumb: .1, .8 | ||
""" | ||
import numpy as np | ||
|
||
import arviz as az | ||
|
||
az.style.use("arviz-darkgrid") | ||
|
||
az.plot_kde( | ||
np.random.beta(2, 5, size=100), | ||
np.random.beta(2, 5, size=100), | ||
contour_kwargs={"levels": 30}, | ||
contourf_kwargs={"alpha": 0.5, "levels": 30, "cmap": "viridis"}, | ||
backend="bokeh", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
2d KDE with HDI Contours | ||
======================== | ||
|
||
_thumb: .5, .8 | ||
_example_title: 2d KDE with HDI Contours | ||
""" | ||
import numpy as np | ||
|
||
import arviz as az | ||
|
||
az.style.use("arviz-darkgrid") | ||
|
||
rng = np.random.default_rng() | ||
data = rng.multivariate_normal([2, 2], [[1, 0.4], [0.4, 0.8]], 1000000) | ||
|
||
az.plot_kde( | ||
data[:, 0], | ||
data[:, 1], | ||
hdi_probs=[0.393, 0.865, 0.989], # 1, 2 and 3 sigma contours | ||
contourf_kwargs={"cmap": "Blues"}, | ||
backend="bokeh", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
KDE Pair Plot with HDI Contours | ||
=============================== | ||
|
||
_thumb: .2, .5 | ||
_example_title: KDE Pair Plot with HDI Contours | ||
""" | ||
import arviz as az | ||
|
||
az.style.use("arviz-darkgrid") | ||
|
||
centered = az.load_arviz_data("centered_eight") | ||
|
||
coords = {"school": ["Choate", "Deerfield"]} | ||
az.plot_pair( | ||
centered, | ||
var_names=["theta", "mu", "tau"], | ||
kind="kde", | ||
coords=coords, | ||
divergences=True, | ||
textsize=22, | ||
kde_kwargs={ | ||
"hdi_probs": [0.3, 0.6, 0.9], # Plot 30%, 60% and 90% HDI contours | ||
"contourf_kwargs": {"cmap": "Blues"}, | ||
}, | ||
backend="bokeh", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
""" | ||
2d KDE | ||
====== | ||
2d KDE (custom style) | ||
===================== | ||
|
||
_thumb: .1, .8 | ||
""" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit worried that this unit test is overly complicated, but I wasn't sure how best to approach it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is ok.