GitHub

@@ -36,7 +36,7 @@ import matplotlib.pyplot as plt

3636

from math import gamma

3737

```

383839-

## Mathematical Expectation of Likelihood Ratio

39+

## Mathematical expectation of likelihood ratio

40404141

In {doc}`this lecture <likelihood_ratio_process>`, we studied a likelihood ratio $\ell \left(\omega_t\right)$

4242

@@ -57,11 +57,10 @@ $$

5757

Our goal is to approximate the mathematical expectation $E \left[ L\left(\omega^t\right) \right]$ well.

58585959

In {doc}`this lecture <likelihood_ratio_process>`, we showed that $E \left[ L\left(\omega^t\right) \right]$ equals $1$ for all $t$.

60+6061

We want to check out how well this holds if we replace $E$ by with sample averages from simulations.

616262-

This turns out to be easier said than done because for

63-

Beta distributions assumed above, $L\left(\omega^t\right)$ has

64-

a very skewed distribution with a very long tail as $t \rightarrow \infty$.

63+

This turns out to be easier said than done because for Beta distributions assumed above, $L\left(\omega^t\right)$ has a very skewed distribution with a very long tail as $t \rightarrow \infty$.

65646665

This property makes it difficult efficiently and accurately to estimate the mean by standard Monte Carlo simulation methods.

6766

@@ -156,7 +155,7 @@ $$

156155

E^g\left[\ell\left(\omega\right)\right] = \int_\Omega \ell(\omega) g(\omega) d\omega = \int_\Omega \ell(\omega) \frac{g(\omega)}{h(\omega)} h(\omega) d\omega = E^h\left[\ell\left(\omega\right) \frac{g(\omega)}{h(\omega)}\right]

157156

$$

158157159-

## Selecting a Sampling Distribution

158+

## Selecting a sampling distribution

160159161160

Since we must use an $h$ that has larger mass in parts of the distribution to which $g$ puts low mass, we use $h=Beta(0.5, 0.5)$ as our importance distribution.

162161

@@ -178,7 +177,7 @@ plt.ylim([0., 3.])

178177

plt.show()

179178

```

180179181-

## Approximating a Cumulative Likelihood Ratio

180+

## Approximating a cumulative likelihood ratio

182181183182

We now study how to use importance sampling to approximate

184183

${E} \left[L(\omega^t)\right] = \left[\prod_{i=1}^T \ell \left(\omega_i\right)\right]$.

@@ -233,7 +232,7 @@ For our importance sampling estimate, we set $q = h$.

233232

estimate(g_a, g_b, h_a, h_b, T=1, N=10000)

234233

```

235234236-

Evidently, even at T=1, our importance sampling estimate is closer to $1$ than is the Monte Carlo estimate.

235+

Evidently, even at $T=1$, our importance sampling estimate is closer to $1$ than is the Monte Carlo estimate.

237236238237

Bigger differences arise when computing expectations over longer sequences, $E_0\left[L\left(\omega^t\right)\right]$.

239238

@@ -248,7 +247,17 @@ estimate(g_a, g_b, g_a, g_b, T=10, N=10000)

248247

estimate(g_a, g_b, h_a, h_b, T=10, N=10000)

249248

```

250249251-

## Distribution of Sample Mean

250+

The Monte Carlo method underestimates because the likelihood ratio $L(\omega^T) = \prod_{t=1}^T \frac{f(\omega_t)}{g(\omega_t)}$ has a highly skewed distribution under $g$.

251+252+

Most samples from $g$ produce small likelihood ratios, while the true mean requires occasional very large values that are rarely sampled.

253+254+

In our case, since $g(\omega) \to 0$ as $\omega \to 0$ while $f(\omega)$ remains constant, the Monte Carlo procedure undersamples precisely where the likelihood ratio $\frac{f(\omega)}{g(\omega)}$ is largest.

255+256+

As $T$ increases, this problem worsens exponentially, making standard Monte Carlo increasingly unreliable.

257+258+

Importance sampling with $q = h$ fixes this by sampling more uniformly from regions important to both $f$ and $g$.

259+260+

## Distribution of sample mean

252261253262

We next study the bias and efficiency of the Monte Carlo and importance sampling approaches.

254263

@@ -323,17 +332,15 @@ The simulation exercises above show that the importance sampling estimates are u

323332324333

Evidently, the bias increases with increases in $T$.

325334326-

## Choosing a Sampling Distribution

335+

## Choosing a sampling distribution

327336328337

+++

329338330339

Above, we arbitraily chose $h = Beta(0.5,0.5)$ as the importance distribution.

331340332341

Is there an optimal importance distribution?

333342334-

In our particular case, since we know in advance that $E_0 \left[ L\left(\omega^t\right) \right] = 1$.

335-336-

We can use that knowledge to our advantage.

343+

In our particular case, since we know in advance that $E_0 \left[ L\left(\omega^t\right) \right] = 1$, we can use that knowledge to our advantage.

337344338345

Thus, suppose that we simply use $h = f$.

339346

@@ -364,10 +371,10 @@ b_list = [0.5, 1.2, 5.]

364371

```{code-cell} ipython3

365372

w_range = np.linspace(1e-5, 1-1e-5, 1000)

366373367-

plt.plot(w_range, g(w_range), label=f'p=Beta({g_a}, {g_b})')

368-

plt.plot(w_range, p(w_range, a_list[0], b_list[0]), label=f'g=Beta({a_list[0]}, {b_list[0]})')

369-

plt.plot(w_range, p(w_range, a_list[1], b_list[1]), label=f'g=Beta({a_list[1]}, {b_list[1]})')

370-

plt.plot(w_range, p(w_range, a_list[2], b_list[2]), label=f'g=Beta({a_list[2]}, {b_list[2]})')

374+

plt.plot(w_range, g(w_range), label=f'g=Beta({g_a}, {g_b})')

375+

plt.plot(w_range, p(w_range, a_list[0], b_list[0]), label=f'$h_1$=Beta({a_list[0]},{b_list[0]})')

376+

plt.plot(w_range, p(w_range, a_list[1], b_list[1]), label=f'$h_2$=Beta({a_list[1]},{b_list[1]})')

377+

plt.plot(w_range, p(w_range, a_list[2], b_list[2]), label=f'$h_3$=Beta({a_list[2]},{b_list[2]})')

371378

plt.title('real data generating process $g$ and importance distribution $h$')

372379

plt.legend()

373380

plt.ylim([0., 3.])

Read the original on github.com ↗