Math 2.0

Numerical analysis Monte Carlo and quasi-Monte Carlo methods Theorem

Ziggurat algorithm

Builds on Rejection samplingProbability density functionContinuous uniform distributionNormal distribution

Statement

Let f ⁣:[0,∞)→(0,∞)f \colon [0, \infty) \to (0, \infty) be continuous, non-increasing and integrable. Let n≥2n \ge 2, let 0=x0<x1<⋯<xn−1=r0 = x_0 < x_1 < \cdots < x_{n-1} = r, and let v>0v > 0 be such that:

  1. xi(f(xi−1)−f(xi))=vx_i \bigl(f(x_{i-1}) - f(x_i)\bigr) = v for 1≤i≤n−11 \le i \le n-1;
  2. rf(r)+∫r∞f(x) dx=vr f(r) + \int_r^\infty f(x)\, dx = v.

Define the layers Li=[0,xi]×[f(xi),f(xi−1)]L_i = [0, x_i] \times [f(x_i), f(x_{i-1})] for 1≤i≤n−11 \le i \le n-1 and the base Ln={(x,y):0≤x≤r, 0≤y≤f(r)}∪{(x,y):x>r, 0≤y≤f(x)}L_n = \set{(x, y) : 0 \le x \le r,\ 0 \le y \le f(r)} \cup \set{(x, y) : x > r,\ 0 \le y \le f(x)}. The ziggurat algorithm repeats the following trial until it returns a value. It chooses i∈{1,…,n}i \in \set{1, \ldots, n} uniformly at random, draws a point (X,Y)(X, Y) uniformly from LiL_i, and returns XX if Y≤f(X)Y \le f(X). Then the returned value has probability density f/∫0∞ff / \int_0^\infty f, and each trial returns a value with probability ∫0∞f/(nv)\int_0^\infty f / (n v).

Remarks

Each layer has area vv by clauses 1 and 2, and the layers overlap only in boundary segments of measure zero. So a uniform choice of layer followed by a uniform point in it gives a point uniform on the union Z=L1∪⋯∪LnZ = L_1 \cup \cdots \cup L_n. Since ff is non-increasing, ZZ contains the region {(x,y):x≥0, 0≤y≤f(x)}\set{(x, y) : x \ge 0,\ 0 \le y \le f(x)} under the graph. A uniform point of ZZ conditioned to lie under the graph is uniform there, and its first coordinate has density proportional to ff. This is rejection sampling with a uniform envelope on ZZ. The speed comes from a shortcut: in layer i≤n−1i \le n-1, if X<xi−1X < x_{i-1} then Y≤f(xi−1)≤f(X)Y \le f(x_{i-1}) \le f(X), so the point is accepted without evaluating ff. For large nn, such as n=128n = 128 or 256256, almost all trials end this way, after one random integer, one multiplication and one comparison. A uniform point of the base LnL_n is drawn as follows. With probability rf(r)/vr f(r)/v it is a uniform point of the rectangle [0,r]×[0,f(r)][0, r] \times [0, f(r)]. Otherwise XX is drawn from the tail density proportional to ff on (r,∞)(r, \infty), which needs a separate tail sampler, and YY is uniform on [0,f(X)][0, f(X)]. For the standard normal distribution, one samples ∣Z∣\abs{Z} with f(x)=e−x2/2f(x) = e^{-x^2/2} and attaches a random sign. The numbers xix_i, rr and vv are computed once, by solving the equations of clauses 1 and 2 numerically.

Going deeper

For a student

The algorithm, due to Marsaglia and Tsang, is a form of rejection sampling with a piecewise constant envelope that fits the density tightly. It is used for normal and exponential random numbers in many numerical libraries. For symmetric densities such as the normal, it samples the right half and attaches a random sign; often the sign comes from a spare bit of the same random integer. Its exactness depends on good uniform variates and an exact tail sampler; the tail of the normal is usually handled by a method of Marsaglia based on exponential variates.

Reading path

To understand this page from the ground up, read these 7 pages in order. The foundations come first.

Show the path as a graph
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Conditional probability concept
  2. Continuous uniform distribution concept
  3. Geometric distribution concept
  4. Normal distribution concept
  5. Probability density function concept
  6. Rejection sampling statement
  7. Ziggurat algorithm statement

Further reading

  1. Web https://en.wikipedia.org/wiki/Ziggurat_algorithm
About this page
Tag2PSDHH34BJ
URIm2://2PSDHH34BJ
Kindstatement, theorem
WritingW0 stub
MSC65C10
StatusThis copy of the site has no build data. Run m2 status 2PSDHH34BJ.
AboutRejection sampling
UsesRejection sampling, Probability density function, Continuous uniform distribution, Normal distribution
Same as

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • an inventory row: the row of the inventory that the node accounts for (0 of 1)
  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.