Random Walks and MCMC

2025-11-18

Non-standard distributions

How do we sample from distributions that are not gamma, exponential, normal, etc?

\[ f(x)=\begin{cases} 2-4x, & 0 \leq x< 1/2\\ 4x-2, & 1/2 \leq x \leq 1 \end{cases} \]

Inverse Probability Sampling

  1. Get the CDF, \(F(x) = ...\)
  2. Invert the CDF to get \(F^{-1}(u) = x\)
  3. Generate uniform \(u\sim U[0,1]\) random variables
  4. Use the Inverse CDF to get samples \(x\) from \(f(x)\)

Inverse Probability Sampling

\[F(x) = \begin{cases} -2x^2 + 2x, & 0 \leq x< 1/2\\ \hphantom{-}2x^2-2x, & 1/2 \leq x \leq 1 \end{cases}\]

\[F^{-1}(u) = \begin{cases} \frac{1}{2}-\frac{\sqrt{1-2u}}{2} & u < 0.5\\\frac{1}{2} + \frac{\sqrt{u}}{\sqrt2} & u \geq 0.5\end{cases}\]

set.seed(2043872)
u <- runif(100)
x <- 1/2 -0.5*(1-2*u)*(u<0.5) + (u/2)^0.5 * (u>0.5)
hist(x)