Drop dots evenly down the side of a box, bounce them off a curve, and let them fall. Watch them pile into a new shape.
Turning randomness into any shape
Even random heights from 0 to 1, sent through a distribution function (seed 2600 + target).
Exponential: each dot starts at a random height u between 0 and 1, runs across to the curve F, and falls to the value x where F(x) = u.
Describe this picture
Two panels on one horizontal axis. On top, a rising curve, a distribution function, from 0 to 1 up the vertical axis, labelled . Below, a histogram. Seeded dots (400 for each curve; seeds 2600, 2601 and 2602) start at random heights spread evenly between 0 and 1 on the vertical axis, travel across until they meet the curve, then fall straight down into the histogram: the first 12 one by one, stacking on their bins, the rest poured in. The clip runs three curves in turn, an exponential, a Rayleigh and a standard normal, and each pile takes that law’s shape, which is then outlined as a dotted curve. Where the curve is steep, the falling dots crowd together; where it is flat, they spread out. Readouts give the shape, the dots landed and, after the clip, the value . After the clip a slider, “Level u”, sets from 0.01 to 0.99 on the standard normal curve, and a marker runs from across to the curve and down to the value ; at 0.975 it reads 1.9600.
Even dots in, any shape out
Computers make random numbers that are spread evenly between 0 and 1: a uniform variable , from Continuous random variables. A simulation usually needs something else: waiting times, noise, heights. The picture shows how to get any shape from even dots.
Each dot starts at a height and moves across to the curve , then drops to the where . That is written , the inverse of the distribution function: it answers “at which value has the curve climbed to ?”. So the method is
Why does the pile take the shape of ? Because climbs, happens exactly when . And a uniform lands below any level with chance equal to that level:
The new variable has distribution function , which is what I wanted. This is the inverse distribution function method, often called the inverse CDF method.
Exponential waits. For , . Solve for :
With , the level gives .
Steep and flat
Look at where the dots land. A band of starting heights from to catches the same share of dots, , wherever it is. Where the curve is steep, that band meets the curve over a narrow stretch of , so its dots land close together and the pile is tall. Where the curve is flat, the same share of dots is spread over a wide stretch of , and the pile is low.
That is the density again: the slope of is . Steep means a high density, flat means a low one.
The density of a function
The same idea answers a general question. If has a known density and for some function , what is the density of ?
Take increasing, so that it keeps order. Then exactly when , and
Take the slope of both sides, by the chain rule. For decreasing the same steps give a minus sign, and the absolute value covers both:
The last factor is the stretch factor. Where stretches a stretch of into a wider stretch of , the same probability is spread thinner, and the density drops by that factor.
A small case: and . Then , its slope is , and has density on : the same flat shape, twice as wide and half as tall.
Watch out
Leaving out the stretch factor is the common mistake. Without it, would get height 1 on a width of 2, an area of 2. A density must have area 1, and the stretch factor is what keeps it there.
Three shapes made by transforming
Rayleigh. Take a point whose two coordinates are independent and each , and let be its distance from the origin. follows the Rayleigh law, with for . Its inverse gives the recipe
and its mean is .
Log-normal. If is standard normal, is log-normal: always positive, with a long tail to the right. An increasing map keeps the middle value in the middle, so its median is . Its mean is larger, , pulled up by the tail.
Chi-square with one degree of freedom. is the square of a standard normal. Its mean is , the variance of . The square is not increasing over all of , since and give the same ; its density adds the two halves, one from each side.
Worked example
1. Squaring a uniform. Let and , which also lies between 0 and 1. Squaring is increasing there, so
The density is tall near 0 and low near 1: squaring pushes small values closer to 0. Half of the values of lie below 0.25, since .
Its mean is , not , as Expected value warned.
2. Reading levels off three curves. Here is what the slider gives at a few levels , for the exponential with rate , the Rayleigh with and the standard normal:
| Level | Exponential | Rayleigh | Standard normal |
|---|---|---|---|
| 0.5 | 0.6931 | 1.1774 | 0 |
| 0.9 | 2.3026 | 2.1460 | 1.2816 |
| 0.975 | 3.6889 | 2.7162 | 1.9600 |
| 0.99 | 4.6052 | 3.0349 | 2.3263 |
The standard normal at 0.975 gives 1.96, the edge of the 95 % band of The normal distribution: 2.5 % lies above it and 2.5 % below .
Try it yourself. An exponential draw with rate 1 from the level : .
Where you’ll meet this
Simulation. Simulators of queues, networks and markets need random draws of every shape. Most start from uniform numbers and use this page’s method, or a cousin of it, for each law.
The envelope of noise. The strength of narrow-band radio noise, its envelope, is the distance from the origin of two independent bell-shaped parts: a Rayleigh variable. Fading radio channels are described the same way.
Decibels and growth. Quantities that grow by multiplying, such as incomes or signal strengths through many layers of fading, are often log-normal: their logarithm, in decibels, is a bell.
Squared errors. The square of a standard bell-shaped value is a chi-square variable; a bell-shaped error with mean 0, squared and divided by its variance, is one, and so is the power of a bell-shaped noise sample scaled the same way. Chi-square tests are built on sums of them.
In signal processing · the envelope of noise
In the signal processing course, The Hilbert transform and the analytic signal reads the envelope of narrow-band Gaussian noise, and finds it follows the Rayleigh law above: the distance from the origin of two independent bell-shaped parts of equal variance.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| Inverse CDF method | , | even dots into any shape |
| Exponential draws | ||
| Rayleigh draws | mean | |
| Function of , one-to-one | the stretch factor keeps area 1 | |
| Steep | dots crowd: high density | flat : dots spread |
| Log-normal | median 1, mean | |
| Chi-square, one degree | , mean 1 |