I am reading the following approach of generating a random number from a given probability distribution.
https://blogs.sas.com/content/iml/2013/07/22/the-inverse-cdf-method.html
I understand that cdf is 1-1 mapping, so there is a guarantee that the generated number will be within the domain of the pdf. However, I am wondering what's the accuracy of this approach? Is there a mathematical prove?
I applied this method on the exponential distribution, and found the the average of the generated numbers are smaller than expected ... I am wondering is this because I just didn't draw enough samples or this method is not very accurate? Thanks!
Proof
In what follows, $F(x)$ is a CDF and $f(x)$ is a PDF.
Here is a proof for your case, if $$U \sim U([0,1])$$ Then let's prove that (assuming that the CDF of $X$ is bijective) $$X = F^{-1}(U)$$ is distributed according to $f_X(x)$. This is what you're looking for So \begin{equation} Pr(F^{-1}(u) \leq x) = Pr(u \leq F(x)) \end{equation} where we have inverted the CDF to the other side, now we get \begin{equation} Pr(F^{-1}(u) \leq x)= \int\limits_{-\infty}^{\infty}f_U(u) \ du = \int\limits_{0}^{F(x)} \ du \end{equation} This is so because $F(x) \geq 0$. Now, we get \begin{equation} Pr(F^{-1}(u) \leq x)= F(x) \end{equation} We have just proved that \begin{equation} Pr(F^{-1}(u) \leq x) = F(x) \end{equation} which is the CDF of $X$.
Empirical results
The approach is accurate and this is what I got on MATLAB
This is the MATLAB code