Non-uniform random distributions
In the previous section we learned how to generate random deviates with a uniform probability distribution in an interval . This distributioon is normalized, so that Hence, .
Now, suppose that we generate a sequence and we take some function of it to generate . This new sequence is going to be distributed according to some probability density , such that or
If we want to generate a desired normalized distribution , we need to solve the differential equation: But the solution of this is Therefore, where is the inverse of .
Exponential distribution
As an example, let us take with representing a uniform distribution in the interval . Then which is distributed exponentially. This distribution occurs frequently in real problems such as the radioactive decay of nuclei. You can also see that the quantity has the distribution .
von Neumann rejection
A simple and ingenious method for generating random points with a probability distribution was deduced by von Neumann. Draw a plot with you probability distribution, and on the same graph, plot another curve which has finite area and lies everywhere above your original distribution. We will call the “comparison function”. Generate random pairs with uniform distribution inside . Whenever the point lies inside the area of the original probability, we accept it, otherwise, we reject it. All the accepted points will be uniformly distributed within the original area, and therefore will have the desired distribution. The fraction of points accepted/rejected will deppend on the ratio between the two areas. The closer the comparison function resembles , the more points will be accepted. Ideally, for , all the points will be accepted, and none rejected. However, in practice, this is not always possible, but we can try to pick such that we minimize the fraction of rejected points.
It only remains how to pick a number with probability . For this purpose, we utilize the method shown in the previous section, using a function whose indefinite intergral is know analitically, and is also analitically invertible. We then pick a random number and retrieve the corresponding according to ([random_invert]). Then, we generate a second random number and we use the rejection criterion.
An equivalent procedure consists of picking the second number between 0 and 1 and accept or reject according to wether is it respectively less than or greater than the ratio . Clearly, if all the points will be accepted.
Challenge 9.1:
Improve the acceptance ratio by using a linear function , with a ppropriate choice of
Random walk methods: the Metropolis algorithm
Suppose that we want to generate random variables according to an arbitrary probability density . The Metropolis algorithm produces a “random walk” of points whose asymptotic probability approaches after a large number of steps. The random walk is defined by a “transition probability” for one value to another in order that the distribution of points , , , ... converges to . In can be shown that it is sufficient (but not necessary) to satisfy the “detailed balance” condition This relation dos not specify uniquely. A simple choice is This choice can be described by the following steps. Suppose that the “random walker” is a position . To generate we
choose a trial position , where the is a random number in the interval .
Calculate .
If we accept the change and let .
If , generate a random number .
If , accept the change and let .
If the trial change is not accepted, the let .
It is necessary to sample a number of points of the random walk before the asymptotic probability is attained. How do we choose the “step size” ? If is too large, only a small fraction of changes will be accepted and the sampling will be inefficient. If is too small, a large number will be accepted, but it would take too long to sample over the whole interval of interest. Ideally, we want at least 1/3-1/2 of the trial steps to be accepted. We also want to choose such that the distribution converges to as quickly as possible. An obvious choice is to begin the random walk at the point where is maximum.
Exercise 9.1: The Gaussian distribution
Use the Metropolis algorithm to generate a Gaussian distribution . Is the numerical value of the normalization constant relevant? Determine the qualitative dependence of the acceptance ratio and the equilibrium time on the maximum step size . One possible criterion for equilibrium is that . For , what is a reasonable choice of ? (choose .)
Plot the asymptotic probability distribution generated by the Metropolis algorithm.
Challenge 9.2:
Modify the code above to study the equilibration "time" for different step size .
Analize the acceptance ratio in terms of .