Draws from the usual families
Section of Simulation, part of Probability
Draws from the usual families
| Type | Section |
| Taught in | Simulation |
| Part | Probability |
Exponential. If X\sim\operatorname{Exp}(\lambda), then F(x)=1-e^{-\lambda x} for x>0, so F^{-1}(u)=-\lambda^{-1}\log(1-u). Because 1-U is again uniform on [0,1], the draw X=-\lambda^{-1}\log U has the same distribution. In Python, with numpy imported as np,
u = np.random.rand()
x = -np.log(u) / lamUniform on an interval. If U\sim\operatorname{U}[0,1], then a+(b-a)U is uniform on [a,b]. This is the inverse transform of the linear distribution function, and it is also an affine image of a uniform variable.
Normal. There is no elementary inverse of \Phi. If a standard normal draw Z is already available, then \mu+\sigma Z is \operatorname{N}(\mu,\sigma^2). Two independent standard normals can be made from two independent uniforms (U,V) by the Box–Muller map
Z_1=\sqrt{-2\log U}\,\cos(2\pi V), \qquad Z_2=\sqrt{-2\log U}\,\sin(2\pi V).
The Jacobian of that transformation is checked in Functions of random variables and limit theorems. The two coordinates come out independent and standard normal.
Bernoulli and binomial. A Bernoulli trial with success probability p is the indicator \mathbf{1}\{U\le p\}. A binomial count is the sum of n independent copies. That uses the representation of the binomial distribution as a sum of Bernoulli trials, rather than an inverse of its distribution function.
Geometric and Poisson. A geometric count starting at 1, with success probability p, is the number of Bernoulli trials until the first success, which is \lfloor \log U/\log(1-p)\rfloor+1. A Poisson count can be built from exponential spacings: if E_i are independent exponential variables with rate 1, the largest n with E_1+\cdots+E_n\le\lambda is Poisson with mean \lambda. Both constructions are consequences of the memoryless property and of the gamma–Poisson relationship, not new definitions of the laws.
Discrete distributions in general. Stack the masses into a cumulative sum and apply the discrete inverse transform. That one algorithm covers every finite support, including an empirical distribution read off a table.
One uniform draw, passed through F^{-1}, has distribution function F. When the inverse is awkward, propose from a density that sits above f and keep the proposals that fall underneath it. The chance of keeping a proposal is 1/C.
Used in
- Taught in Simulation
- All 4 questions on Simulation
See also
Linear congruential generator · Inverse-transform method · Acceptance–rejection method · Random numbers · Box–Muller method · Cauchy distribution · Random seed