import numpy as npimport bebi103import bokeh.iobokeh.io.output_notebook()
Loading BokehJS ...
In his 2003 paper, Radford Neal pointed out that sampling out of relatively simply distributions using MCMC can be challenging. He proposed the following model, a kind of distribution that Thomas Wiecki has referred to as the “funnel of hell,” as a demonstration.
That is, \(v\) is Normally distribution with mean zero and variance 9, and \(\theta\) is Normally distributed with mean zero and variance \(\mathrm{e}^v\). The joint distribution is then
We can compute the PDF analytically, so let’s make a plot of it so we know what we’re sampling out of.
theta = np.linspace(-4, 4, 400)v = np.linspace(-15, 5, 400)THETA, V = np.meshgrid(theta, v)P = np.exp(-V /2) /6/ np.pi * np.exp(-(V **2/9+ THETA **2/ np.exp(V)) /2)# Show it by hacking contour to show image, but no contoursbokeh.io.show( bebi103.viz.contour( THETA, V, P, overlaid=True, line_kwargs=dict(alpha=0), x_axis_label="θ", y_axis_label="v", ))
This probability density function is funnel shaped, named “the Funnel of Hell” by Thomas Wiecki.
Note that much of the probability density lies deep in the needle, which is a region of high curvature.
This simple distribution allows for independent sampling without MCMC. First, let’s generate some of these samples so we can see what effective sampling should look like.
Your task is to code up a Stan model for this distribution and use MCMC to get samples out of it. Then, overlay those samples on the plot of the independent samples. What do you observe? (There will be obvious problems with the sampling, and we will address these in coming lessons.)