| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "markdown", |
| 5 |
"metadata": {}, |
| 6 |
"source": [ |
| 7 |
"# A note about sigmas\n", |
| 8 |
"\n", |
| 9 |
"We are regularly asked about the \"sigma\" levels in the 2D histograms. These are not the 68%, *etc.* values that we're used to for 1D distributions. In two dimensions, a Gaussian density is given by:\n", |
| 10 |
"\n", |
| 11 |
" pdf(r) = exp(-(r/s)^2/2) / (2*pi*s^2)\n", |
| 12 |
"\n", |
| 13 |
"The integral under this density (using polar coordinates and implicitly integrating out the angle) is:\n", |
| 14 |
"\n", |
| 15 |
" cdf(x) = Integral(r * exp(-(r/s)^2/2) / s^2, {r, 0, x})\n", |
| 16 |
" = 1 - exp(-(x/s)^2/2)\n", |
| 17 |
"\n", |
| 18 |
"This means that within \"1-sigma\", the Gaussian contains `1-exp(-0.5) ~ 0.393` or 39.3% of the volume. Therefore the relevant 1-sigma levels for a 2D histogram of samples is 39% not 68%. If you must use 68% of the mass, use the `levels` keyword argument when you call `corner.corner`.\n", |
| 19 |
"\n", |
| 20 |
"We can visualize the difference between sigma definitions:" |
| 21 |
] |
| 22 |
}, |
| 23 |
{ |
| 24 |
"cell_type": "code", |
| 25 |
"execution_count": null, |
| 26 |
"metadata": { |
| 27 |
"tags": [] |
| 28 |
}, |
| 29 |
"outputs": [], |
| 30 |
"source": [ |
| 31 |
"import corner\n", |
| 32 |
"import numpy as np\n", |
| 33 |
"\n", |
| 34 |
"# Generate some fake data from a Gaussian\n", |
| 35 |
"np.random.seed(42)\n", |
| 36 |
"x = np.random.randn(50000, 2)" |
| 37 |
] |
| 38 |
}, |
| 39 |
{ |
| 40 |
"cell_type": "markdown", |
| 41 |
"metadata": {}, |
| 42 |
"source": [ |
| 43 |
"First, plot this using the correct (default) 1-sigma level:" |
| 44 |
] |
| 45 |
}, |
| 46 |
{ |
| 47 |
"cell_type": "code", |
| 48 |
"execution_count": null, |
| 49 |
"metadata": { |
| 50 |
"jupyter": { |
| 51 |
"outputs_hidden": false |
| 52 |
} |
| 53 |
}, |
| 54 |
"outputs": [], |
| 55 |
"source": [ |
| 56 |
"fig = corner.corner(x, quantiles=(0.16, 0.84), levels=(1 - np.exp(-0.5),))\n", |
| 57 |
"_ = fig.suptitle(\"default 'one-sigma' level\")" |
| 58 |
] |
| 59 |
}, |
| 60 |
{ |
| 61 |
"cell_type": "markdown", |
| 62 |
"metadata": {}, |
| 63 |
"source": [ |
| 64 |
"Compare this to the 68% mass level and specifically compare to how the contour compares to the marginalized 68% quantile:" |
| 65 |
] |
| 66 |
}, |
| 67 |
{ |
| 68 |
"cell_type": "code", |
| 69 |
"execution_count": null, |
| 70 |
"metadata": { |
| 71 |
"jupyter": { |
| 72 |
"outputs_hidden": false |
| 73 |
} |
| 74 |
}, |
| 75 |
"outputs": [], |
| 76 |
"source": [ |
| 77 |
"fig = corner.corner(x, quantiles=(0.16, 0.84), levels=(0.68,))\n", |
| 78 |
"_ = fig.suptitle(\"alternative 'one-sigma' level\")" |
| 79 |
] |
| 80 |
} |
| 81 |
], |
| 82 |
"metadata": { |
| 83 |
"kernelspec": { |
| 84 |
"display_name": "Python 3", |
| 85 |
"language": "python", |
| 86 |
"name": "python3" |
| 87 |
}, |
| 88 |
"language_info": { |
| 89 |
"codemirror_mode": { |
| 90 |
"name": "ipython", |
| 91 |
"version": 3 |
| 92 |
}, |
| 93 |
"file_extension": ".py", |
| 94 |
"mimetype": "text/x-python", |
| 95 |
"name": "python", |
| 96 |
"nbconvert_exporter": "python", |
| 97 |
"pygments_lexer": "python", |
| 98 |
"version": "3.9.1" |
| 99 |
} |
| 100 |
}, |
| 101 |
"nbformat": 4, |
| 102 |
"nbformat_minor": 4 |
| 103 |
} |