Monte Carlo methods

Simulation using inverse function open_in_new

Suppose our desired density function is $f$ in an open interval $I$. Then the distribution function $F(x) = \int_{-\infty}^{x} f(y) dy$ is an increasing map from $I$ to $(0,1)$. Let the quantile function be $$ \begin{align*} G(u) = \inf\sb{x\in\R}{u\leq F(x)}. \end{align*} $$ (When $f$ is positive everywhere, $G=F\inv$.) Note that for all $x\in\R, u\in(0,1)$, $$ \begin{align*} G(u) \leq x \iff u \leq F(x). \end{align*} $$ Then when we have $U\sim U[0,1]$ and let $X=G(U)$, we have $$ \begin{align*} \prob(X\leq x) = \prob(G(U)\leq x) = \prob(U\leq F(x)) = F(x) \end{align*} $$ so $X$ has a distribution function $F_X$.

Definition (Monte Carlo estimator) open_in_new

Let $X_1, \ldots, X_n$ be iid samples of $X \sim F$.

The Monte Carlo estimator for $\expect g(X)$ is $$ \begin{align*} \hat I = \frac{1}{n} \sum_{i=1}^{n} g(X_i). \end{align*} $$

$\var(\hat I) = \var(g(X))/n$.

The strong law of large number says $\hat I \xrightarrow{a.s.} \expect g(X)$.

Importance sampling open_in_new

Let $X$ have density $f$, and we wish to estimate $\expect g(X)$. However $f$ is hard to sample.

Let $\tilde f$ be a density which is easy to sample. Then since $$ \begin{align*} \expect_{X\sim f}[g(X)] = \expect_{X\sim \tilde f}\left[g(X) \cdot \frac{f(X)}{\tilde f(X)}\right], \end{align*} $$ we can sample $X_1, X_2, \ldots \sim \tilde f$ iid and use the Monte Carlo estimator $$ \begin{align*} \hat I_\text{IS} = \frac{1}{n} \sum_{i=1}^{n} g(X_i) \frac{f(X_i)}{\tilde f(X_i)} \xrightarrow{a.s.} \expect_{X\sim f}[g(X)]. \end{align*} $$

This works best when $\tilde f \propto fg$ approximately, since $\var\hat I_{\text{IS}} = \var_{X\sim \tilde f}(\frac{g(X)f(X)}{\tilde f(X)})$.

Proposition (rejection sampling) open_in_new

Let $X$ have a density $f$ (which is difficult to sample) and we wish to estimate $\expect g(X)$.

Let $X_1, X_2, \ldots\sim \tilde f$ and $U_1, U_2, \ldots\sim U[0,1]$ all independent such that $f(x) \leq M \tilde f(x)$. Take $$ \begin{align*} K := \min \sb{i\geq 1}{U_i \geq \frac{f(X_i)}{M \tilde f(X_i)}}, \qquad Y := X_K. \end{align*} $$ Then $Y \sim f$.

Note $\expect[K] = \frac{\int M \tilde f(x) \d x}{\int f(x) \d x} = M$.

Definition (Markov chain) open_in_new

A sequence $\ouline{X} = (X_n)_{n\geq 0}$ of random variables taking values in a discrete (finite or countably finite) set $I$ is called a Markov chain with state space $I$ if for all $x_0, x_1, \ldots, x_n, x_{n+1}\in I$, $$ \begin{align*} \prob(X_{n+1} = x_{n+1} | X_n = x_n, \ldots, X_0 = x_0) = \prob(X_{n+1} = x_{n+1} | X_n = x_n). \end{align*} $$

More generally, for a measurable space $\mathcal{X}$, $\ouline{X}$ is a Markov chain taking value in $\mathcal{X}$ if $$ \begin{align*} \prob(X_{n+1} \in B \mid X_n = x_n, \ldots, X_0 = x_0) = K(x_n, B) \end{align*} $$ for some function $K$ called the Markov kernel such that

  1. $K(t, \cdot)$ is a probability measure for all $t\in \mathcal{X}$;

  2. $t \mapsto K(t, B)$ is measurable for all $B\in \mathcal{X}$ measurable.

Definition (invariant measure) open_in_new

Consider a Markov chain on $I$ with a transition matrix $P$.

A measure $\lambda$ on $I$ is said to be invariant with respect to $P$ if $$ \begin{align*} \lambda &= \lambda P &&\text{or equivalently} & \lambda_j = \sum_{i\in I} \lambda_i P(i,j). \end{align*} $$

More generally, for a Markov kernel $K$, a measure $λ$ is invariant if $$ \begin{align*} λ(B) = \int_{\mathcal{X}} K(t, B) \,λ(\d t). \end{align*} $$

If $λ$ has a density $f$ and $K(t,\cdot )$ has a density $k(t,\cdot )$, then $$ \begin{align*} f(x) = \int_{\mathcal{X}} k(t,x) f(t) \d t. \end{align*} $$

  • Invariant distribution can be defined the same way.

Proposition (Gibbs sampling) open_in_new

To generate samples from a multivariate distribution $(X,Y)$ with joint density $f_{XY}$, let $f_{X\mid Y}$ and $f_{Y\mid X}$ be the conditional densities.

Given an initial state $(X_1, Y_1)$, form a Markov chain $(X_n, Y_n)_{n\geq 1}$ by

  1. sampling $X_{n+1}\sim f_{X\mid Y}(Y_n)$; then

  2. sampling $Y_{n+1} \sim f_{Y\mid X}(X_{n+1})$.

Therefore the Markov density is $$ \begin{align*} k((x, y), (x',y')) = f_{Y\mid X}(y'\mid x') f_{X\mid Y}(x'\mid y) \end{align*} $$

Then $f_{XY}$ is an invariant distribution of $(X_n, Y_n)_{n\geq 1}$.

Proof

This is efficient when $X$ and $Y$ are approximately independent.

Proposition (Metropolis-Hastings) open_in_new

We wish to sample $X$ with a density $f$ in $\mathcal{X}$.

Let $q(t,s)$ be a Markov kernel density in $\mathcal{X}$ (which is easy to compute), called the proposal kernel density. Given a initial state $X_0\in \mathcal{X}$,

  1. draw a proposal $S_n\sim q(X_n, \cdot)$; and

  2. take $$ \begin{align*} X_{n+1} := \begin{cases} S_n, &\text{if $A_n=1$}, \\ X_n, &\text{if $A_n = 0$} \end{cases} \end{align*} $$ where $A_n \sim{}$$\op{Bern}$$(a(X_n, S_n))$ and $a$ is the acceptance probability $$ \begin{align*} a(t,s) = \min\left\{1, \frac{f(s) q(s,t)}{f(t) q(t,s)}\right\}. \end{align*} $$

If $f(t) > 0$ and $q(t,s) > 0$ for all $t,s$, then $f$ is the invariant distribution of $(X_n)_{n\geq 0}$.

Proof