Inverse CDF for generating random points from U[0,1]

544 Views Asked by At

I read online that:

"The inverse CDF technique for generating a random sample uses the fact that a continuous CDF, F, is a one-to-one mapping of the domain of the CDF into the interval (0,1). Therefore, if U is a uniform random variable on (0,1), then X = F–1(U) has the distribution F."

From: Article

But I'm failig to undertand this, in the specific case that I have:

$\displaystyle F_{X}( x) =\frac{e^{x}}{1+e^{x}}$, and therefore $\displaystyle F^{-1}_{X}( x) =\log\frac{x}{1-x}$.

From the derativate I was able to get the PDF: $\displaystyle f_{X}( x) =\frac{e^{x}}{\left( 1+e^{x}\right)^{2}}$.

How are the two functions mapping one-to-one?

If I have a random point generator $\displaystyle U$ between $\displaystyle [ 0,1]$. How exactly should I be able to generate a random point in $\displaystyle f_{X}( x)$? This is what I'm not getting, like what should I do exactly, and why it works.

2

There are 2 best solutions below

0
On

With $U\sim \mathcal{U}(0,1)$, you have $\log \frac{U}{1-U} \sim \mathrm{logistic}(0,1)$. That is, you generate $U$ from a uniform on unit interval, transform it according to $\log \frac{U}{1-U}$, to obtain a random draw from a standard logistic distribution.

0
On

WHY IT WORKS (more mind map than a real demo)

X is a random variable according to the CDF F(X) means that $P(X\leq x)=F_X(x)$. Let's introduce $u=F_X(x)$, and try to identify the corresponding distribution.

By assuming $F_X$ is strictly increasing (not always the case in case of "steps distribution") $$X \leq x \Leftrightarrow F_X(X) \leq F_X(x) \Leftrightarrow U \leq u$$

Then, $$P(U \leq u) = P(X \leq x)$$ By using $t=F_X(s)$ variable change, inducing $dt=f_X(s)ds$ $$P(U \leq u) = \int_{-\infty}^{x}f_X(s)ds=\int_{F_X(-\infty)=0}^{F_X(x)=u}1dt$$ Note: it's still working even in case of finite boundaries for X.

So, if X is randomly distributed according to the CDF $F_X$, then $U=F_X(X)$ is distributed according to a uniform distribution between $[0,1]$.

You can have exactly the symetric process from U a standard uniform distribution variable, and $X=F^{-1}_X(U)$: $$U \leq u \Leftrightarrow F_X^{-1}(U) \leq F_X^{-1}(u) \Leftrightarrow X \leq x$$ With $s=F^{-1}_X(t)$, $ds= \frac{dt}{f_X(F_X^{-1}(t))}$: $$P(X \leq x)=P(U \leq u)=\int_0^u1dt=\int_{F_X^{-1}(0)}^{F_X^{-1}(u)=x}f_X(F_X^{-1}(t))ds=\int_{F_X^{-1}(0)}^{F_X^{-1}(u)=x}f_X(s)ds$$

So you can see that if X is randomly distributed according to the strictly increasing CDF $F_X$, then $U=F_X(X)$ is uniformaly distributed in between $[0,1]$ and reciprocally.

So if you are able to identify the analytical $F_X^{-1}$ equation for any $F_X$ stricly increasing, you simply have to generate a random variable U according to a standard uniform distribution (e.g. between $[0,1]$), and then compute $X= F_X^{-1}(U)$. This new X variable will be distributed according to the CDF $F_X$.