Slice sampling

From Wikipedia, the free encyclopedia

In mathematics and physics, Slice sampling is a type of Markov chain Monte Carlo sampling algorithm based on the observation that to sample a random variable one can sample uniformly from the region under the graph of its density function.

Contents

[edit] Implementation

To sample a random variable X with density f(x) we introduce an auxiliary variable Y and iterate as follows: Given a sample x we choose y uniformly at random from the interval [0,f(x)]; given y we choose x uniformly at random from the set f − 1[0,y]. The sample of x is obtained by ignoring the y values.

[edit] Example

To sample from the normal distribution N(0,1) we first choose an initial x -- say 0. After each sample of x we choose y uniformly at random from [0, e^{-x^2/2}/\sqrt{2\pi}]; after each y sample we choose x uniformly at random from [ − α,α] where \alpha = \sqrt{-2\log(y\sqrt{2\pi})}.

An implementation in the Macsyma language is:
slice(x):=block([y,alpha],

  y:random( exp(-x^2/2.0)/sqrt(2.0*dfloat(%pi))),
  alpha:sqrt(-2.0*ln(y*sqrt(2.0*dfloat(%pi)))),
  x:signum(random())*random(alpha)

);

[edit] See also

[edit] References

  • Radford M. Neal, "Slice Sampling". The Annals of Statistics, 31(3):705-767, 2003.