-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding documentation for ArviZ support (#146)
* refactoring docs * rtds version * invalid key * adding tutorial for arviz
- Loading branch information
Showing
26 changed files
with
443 additions
and
832 deletions.
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 was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,63 +1,42 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import sys | ||
|
||
d = os.path.dirname | ||
sys.path.insert(0, d(d(os.path.abspath(__file__)))) | ||
import corner # NOQA | ||
import corner | ||
|
||
extensions = [ | ||
"sphinx.ext.autodoc", | ||
"sphinx.ext.mathjax", | ||
"sphinx.ext.napoleon", | ||
"myst_nb", | ||
] | ||
templates_path = ["_templates"] | ||
source_suffix = ".rst" | ||
master_doc = "index" | ||
|
||
# General information about the project. | ||
project = u"corner.py" | ||
copyright = u"2013-2016 Dan Foreman-Mackey & contributors" | ||
copyright = u"2013-2021 Dan Foreman-Mackey & contributors" | ||
|
||
version = corner.__version__ | ||
release = corner.__version__ | ||
|
||
exclude_patterns = ["_build", "_static/notebooks/profile"] | ||
pygments_style = "sphinx" | ||
|
||
# Sphinx-gallery | ||
sphinx_gallery_conf = dict( | ||
examples_dirs="../examples", | ||
gallery_dirs="examples", | ||
) | ||
|
||
# Readthedocs. | ||
on_rtd = os.environ.get("READTHEDOCS", None) == "True" | ||
if not on_rtd: | ||
import sphinx_rtd_theme | ||
|
||
html_theme = "sphinx_rtd_theme" | ||
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] | ||
|
||
# htmp_theme_options = dict( | ||
# analytics_id="analytics_id", | ||
# ) | ||
# html_context = dict( | ||
# display_github=True, | ||
# github_user="dfm", | ||
# github_repo="corner.py", | ||
# github_version="corner.py", | ||
# conf_py_path="/docs/", | ||
# favicon="favicon.png", | ||
# script_files=[ | ||
# "_static/jquery.js", | ||
# "_static/underscore.js", | ||
# "_static/doctools.js", | ||
# "//cdn.mathjax.org/mathjax/latest/MathJax.js" | ||
# "?config=TeX-AMS-MML_HTMLorMML", | ||
# "_static/js/analytics.js", | ||
# ], | ||
# ) | ||
exclude_patterns = ["_build"] | ||
html_theme = "sphinx_book_theme" | ||
html_title = "corner.py" | ||
html_static_path = ["_static"] | ||
html_show_sourcelink = False | ||
html_theme_options = { | ||
"path_to_docs": "docs", | ||
"repository_url": "https://github.com/dfm/corner.py", | ||
"repository_branch": "main", | ||
"launch_buttons": { | ||
"binderhub_url": "https://mybinder.org", | ||
"colab_url": "https://colab.research.google.com/", | ||
"notebook_interface": "jupyterlab", | ||
}, | ||
"use_edit_page_button": True, | ||
"use_issues_button": True, | ||
"use_repository_button": True, | ||
"use_download_button": True, | ||
} | ||
html_baseurl = "https://corner.readthedocs.io/en/latest/" | ||
|
||
jupyter_execute_notebooks = "force" |
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# ArviZ support\n", | ||
"\n", | ||
"As of version 2.2, corner supports plotting [ArviZ](https://arviz-devs.github.io/arviz/) samples, providing a consistent interface to [many MCMC samplers](https://arviz-devs.github.io/arviz/getting_started/CreatingInferenceData.html).\n", | ||
"\n", | ||
"Here is a simple example of this:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import corner\n", | ||
"import numpy as np\n", | ||
"import arviz as az\n", | ||
"\n", | ||
"np.random.seed(11234)\n", | ||
"\n", | ||
"x = np.random.randn(2, 2000)\n", | ||
"data = az.from_dict(\n", | ||
" posterior={\n", | ||
" \"x\": x,\n", | ||
" \"y\": np.random.randn(2, 2000, 2)\n", | ||
" },\n", | ||
" sample_stats={\n", | ||
" \"diverging\": x < -1.2\n", | ||
" }\n", | ||
")\n", | ||
"\n", | ||
"figure = corner.corner(data, divergences=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"When using this interface, it is probably best to provide the `truths` parameter using a dictionary keyed on the variable names:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"figure = corner.corner(data, truths={\"x\": 1.5, \"y\": [-0.3, 0.1]})" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.1" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
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,132 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Custom plotting\n", | ||
"\n", | ||
"It can sometimes be useful to add custom annotations or plot elements to the output of `corner.corner`.\n", | ||
"This tutorial shows how you can do this.\n", | ||
"\n", | ||
"For example, let's say that we want to overplot a few different values for comparison.\n", | ||
"The `truths` interface isn't sufficient for supporting this use case, so here's how you can do it.\n", | ||
"\n", | ||
"First, let's generate some fake data with a mode at the origin and another randomly sampled mode:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import corner\n", | ||
"import numpy as np\n", | ||
"\n", | ||
"ndim, nsamples = 4, 50000\n", | ||
"np.random.seed(1234)\n", | ||
"data1 = np.random.randn(ndim * 4 * nsamples // 5).reshape([4 * nsamples // 5, ndim])\n", | ||
"mean = 4*np.random.rand(ndim)\n", | ||
"data2 = (mean[None, :] + np.random.randn(ndim * nsamples // 5).reshape([nsamples // 5, ndim]))\n", | ||
"samples = np.vstack([data1, data2])\n", | ||
"\n", | ||
"figure = corner.corner(samples)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Now let's overplot the empirical mean of the samples and the true mean of the second mode." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# This is the true mean of the second mode that we used above:\n", | ||
"value1 = mean\n", | ||
"\n", | ||
"# This is the empirical mean of the sample:\n", | ||
"value2 = np.mean(samples, axis=0)\n", | ||
"\n", | ||
"# Make the base corner plot\n", | ||
"figure = corner.corner(samples)\n", | ||
"\n", | ||
"# Extract the axes\n", | ||
"axes = np.array(figure.axes).reshape((ndim, ndim))\n", | ||
"\n", | ||
"# Loop over the diagonal\n", | ||
"for i in range(ndim):\n", | ||
" ax = axes[i, i]\n", | ||
" ax.axvline(value1[i], color=\"g\")\n", | ||
" ax.axvline(value2[i], color=\"r\")\n", | ||
" \n", | ||
"# Loop over the histograms\n", | ||
"for yi in range(ndim):\n", | ||
" for xi in range(yi):\n", | ||
" ax = axes[yi, xi]\n", | ||
" ax.axvline(value1[xi], color=\"g\")\n", | ||
" ax.axvline(value2[xi], color=\"r\")\n", | ||
" ax.axhline(value1[yi], color=\"g\")\n", | ||
" ax.axhline(value2[yi], color=\"r\")\n", | ||
" ax.plot(value1[xi], value1[yi], \"sg\")\n", | ||
" ax.plot(value2[xi], value2[yi], \"sr\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"A similar procedure could be used to add anything to the axes that you can normally do with matplotlib.\n", | ||
"\n", | ||
"This being said, there is actually an even easier way to do this using the `overplot_lines` and `overplot_points` functions:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# This is the true mean of the second mode that we used above:\n", | ||
"value1 = mean\n", | ||
"\n", | ||
"# This is the empirical mean of the sample:\n", | ||
"value2 = np.mean(samples, axis=0)\n", | ||
"\n", | ||
"# Make the base corner plot\n", | ||
"figure = corner.corner(samples)\n", | ||
"\n", | ||
"corner.overplot_lines(figure, value1, color=\"C1\")\n", | ||
"corner.overplot_points(figure, value1[None], marker=\"s\", color=\"C1\")\n", | ||
"corner.overplot_lines(figure, value2, color=\"C2\")\n", | ||
"corner.overplot_points(figure, value2[None], marker=\"s\", color=\"C2\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.1" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Oops, something went wrong.