1

How can I simulate using Inverse and Rejection method for $f(x)=\left\{\begin{matrix} \frac{1}{2} & 0\leq x\leq 1 \\ \frac{1}{4} & 2\leq x\leq 4 \\ 0 & otherwise \end{matrix}\right.$

I found the cdf $F(x)=\left\{\begin{matrix} 0 & x < 0 \\\frac{x}{2} & 0\leq x< 1 \\ \frac{x}{4} & 2\leq x< 4 \\ 1 & x\geq 4 \end{matrix}\right.$ and the inverse $F^{-1}(x)=\left\{\begin{matrix} 2x & 0\leq x< 1 \\4x & 2\leq x< 4 \end{matrix}\right.$

but I don't know how to apply the algorithms for a function defined in this way, I didn't find any examples.

For the inverse method I generate $U\sim Unif(0,1)$ and take $F^{-1}(U)=X$, but how do I do this? Do I use just the $0\leq x< 1$ interval because $U$ takes values just there?

For the rejection method I took

$X_{1}\sim Unif(0,1)$ $f_{1} = \frac{1}{2}$ and $Y_{1} \sim Unif(0,1)$ $g_{1} = 1$ , for both $f_{1}$ and $g_{1}$ $0\leq x\leq 1$

$X_{2}\sim Unif(0,1)$ $f_{2} = \frac{1}{4}$ and $Y_{2} \sim Unif(2,4)$ $g_{2} = \frac{1}{2}$ , for both $f_{2}$ and $g_{2}$ $2\leq x\leq 4$

and for both $c= \frac{1}{2}$.

If I had the function just for $0\leq x\leq 1$ I would generate $U_{1},Y_{1} \sim Unif(0,1)$ and $X=Y_{1}$ if $U_{1} \leq \frac{f_{1}}{c \cdot g_{1}}$, but how do I do this for my function?

1 Answers1

0

For the inverse method:

$$F(x) = \begin{cases} 0 & x\le 0\\ \frac x2 & 0<x\le 1\\ \color{red}{\frac 12} & \color{red}{1<x\le 2}\\ \frac x4 & 2 < x\le 4\\ 1 & x\ge 4 \end{cases}$$

The inverse is

$$F^{-1}(u) = \begin{cases} 2u & \color{red}{0 \le u \le .5}\\ 4u & \color{red}{.5 < u \le 1} \end{cases}$$

To use the inverse method, you generate $u$ from $Uniform(0, 1)$ and plug it into $F^{-1}(u)$.

For the rejection method:

Let's use a proposal of $Uniform([0,1]\cup [2,4])$ with $c=2$ (this is necessary to get the proposal's density 'above' the desired density.) Generate $u$ from $Uniform(0, 1)$. Rejection sampling will reject the candidate value if $u \ge f(u) / (c(g(u)) = f(u) / (2(1/3)) = 3/2 f(u)$ and accept it otherwise.

Vons
  • 11,004