WOLFRAM|DEMONSTRATIONS PROJECT

Distributions Using Slice Sampling

​
th
n
sample from distribution
distribution shape
multiple Gaussian
generate random sample
distribution
previous samplepoint
new samplepoint
region forrandom variable 1
region forrandom variable 2
chosenrandom variable 1
chosenrandom variable 2
Slice sampling is a Markov chain Monte Carlo method used to sample points from a given distribution. The algorithm may be summarized as follows: given the previously sampled point, indicated by a purple dashed line, the corresponding ordinate is evaluated. A random number is drawn from a uniform distribution from zero to the ordinate value, indicated by a green circle. The intersections of a horizontal line (slice) at this value with the distribution curve is calculated. From the regions where the curve lies above the horizontal line, a second uniformly distributed random value is drawn, indicated by a red circle. This value is taken as the new sample point, and the algorithm repeats using this as the new starting point. A histogram of the sampled points is shown at the bottom. Adjust the slider to view the next or previous sample points. The distribution shapes may be chosen as Gaussian, gamma, or a linear combination of multiple Gaussian or gamma distributions. To generate new random variables for the current sample point, click the "generate random sample" button.