Generate R.V.
An important Lemma.

Note: Unless otherwise stated, the algorithms and the corresponding screenshots are adopted from Robert and Casella (2005).
Box-Muller Algorithm


Accept-Reject Method


Example:
The Julia code is as follows:
Envelope Accept-Reject

It is easy to write the Julia code:
Atkinson's Poisson Simulation

It is necessary to note that the parameters in the algorithm are not same with those in the density function. In other words, the corresponding density function of the algorithm should be
The following Julia code can generate the poisson random variable with respect to .
As mentioned in the above exercise, another poisson generation method can be derived from the following exercise.

We can write the following Julia code to implement this generation procedure.
ARS Algorithm
ARS is based on the construction of an envelope and the derivation of a corresponding Accept-Reject algorithm. It provides a sequential evaluation of lower and upper envelopes of the density when is concave.
Let be a set of points , in the support of such that is known up to the same constant. Given the concavity of , the line through and is below the graph of in and is above this graph outside this interval.
For , define
the envelopes are
uniformly on the support of . Thus,

Davison (2008) provides another version of ARS

and gives an illustration example.

Let's consider the slightly simple verison in which we do not need to consider . It is obvious that

Consider the CDF of :
and
Then use the inverse of to sample random variable whose density function is . So we can use the following Julia program to sample from .
Back to the main sampling algorithm, we can implement the procedure as follows:
Based on the ARS algorithm, we can also get the Supplemental ARS algorithm:

Exponential Random Variable
The inverse transform sampling from a uniform distribution can be easily used to sample an exponential random variable. The CDF is
whose inverse function is
Thus, we can sample , and then perform the transfomation
Today, I came across another method from Xi'an's blog, which points to the question on StackExchange.
Still confused about the details, as commented in the code.
The theoretical part is as follows,

I rewrite the provided C code in Julia, and compare the distribution with samples from inverse CDF and the package Distributions

Last updated