Simulating from a given CDF

451 Views Asked by At

I don't really understand what to do when asked to "simulate from this distribution", given a CDF.

I understand that I am being asked to describe the algorithm, or find a method, for simulating. I assume this involves the acceptance-rejection method or an alternative. But I do not understand the process on a theoretical level. Could anyone help me?

1

There are 1 best solutions below

0
On BEST ANSWER

Simulating in this case means generate a sample that follows the distribution. Imagine the distribution $f_X(x)$ for which you want to generate a sample, you're given its CDF $F_X(x)$, then if $F_X^{-1}(u)$ is the inverse of $F_X(x)$ then

If $U\sim\mu(0,1)$ then $F_X^{-1}(u)\sim f_X$

You can see the proof here. I'm just going to write an example. Imagine you are tasked with generating random numbers following an exponential distribution with parameter $\lambda$. The CDF is

$$ F_X(x) = 1 - e^{-\lambda x} \tag{1} $$

and its inverse is

$$ F_X^{-1}(u) = -\frac{1}{\lambda}\ln(1 - u) \tag{2} $$

All you need to now is to generate a bunch of uniformly distributed random numbers in $(0,1)$ and evaluate (2), the result is then exponential! In python this looks like

l = 0.4
u = np.random.uniform(0, 1, 1000)
x = -np.log(1 - u) / l

enter image description here

The red line is $f_X(x) = \lambda e^{-\lambda x}$