Skip to content

Commit 67070f1

Browse files
committed
pulled some docs into the main area
1 parent 6842066 commit 67070f1

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

docs/make.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ makedocs(;
9797
"integration-guide.md",
9898
"low_level_interface.md",
9999
"samplers.md",
100+
"guide.md",
101+
"distributions.md",
100102
"hierarchical.md",
101103
"debugging.md",
102104
],
@@ -127,13 +129,6 @@ makedocs(;
127129
"reference.md",
128130
"algorithms.md",
129131
],
130-
"Trunk" => [
131-
"distrib.md",
132-
"distributions.md",
133-
"background.md",
134-
"guide.md",
135-
"GSMP" => "gsmp.md",
136-
]
137132
],
138133
)
139134

docs/src/hamiltonianmontecarlo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ end
2626
Then use that likelihood to guide the next round of HMC. Using this simulation-plus-sampler
2727
setup is much easier than working out the math of non-Exponential distributions.
2828

29-
1. Billig, E. M., Roy, J. A., Ross, M. E., Dolgert, D. J., & Levy, M. Z. (2015, October). A BAYESIAN MODEL FOR IDENTIFYING AND PREDICTING THE DYNAMICS OF URBAN INSECT INFESTATIONS. In AMERICAN JOURNAL OF TROPICAL MEDICINE AND HYGIENE (Vol. 93, No. 4, pp. 537-537). 8000 WESTPARK DR, STE 130, MCLEAN, VA 22101 USA: AMER SOC TROP MED & HYGIENE.
29+
1. Billig, E. M., Roy, J. A., Ross, M. E., Dolgert, D. J., & Levy, M. Z. (2015, October). "A Bayesian model for identifying and predicting the dynamics of urban insect infestations," in American Journal OF Tropical Medicine and Hygeine (Vol. 93, No. 4, pp. 537-537).

docs/src/importance_skills.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Importance Sampling for Simulation
22

3+
Importance sampling is a way to steer a simulation towards simulating the conditions you most care about. The simplest importance sampling is to wait until a simulation gets near a state of interest and then [`CompetingClocks.split!`](@ref) the simulation into multiple copies that can better explore that state. The technique can be more powerful with the use of likelihoods, as described below.
4+
35
## The Process
46

57
When you apply importance sampling in simulation, the workflow feels like this:
@@ -14,15 +16,9 @@ When you apply importance sampling in simulation, the workflow feels like this:
1416

1517
The main problem is that too large of bias on distributions can lead to mathematical underflow in calculation of the weights. Intuitively, a stochastic simulation can have a lot of individual sampled events, and each event's probability multiplies to get the probability of a path of samples in a trajectory. If those samples are repeatedly biased, they can cause numbers that are too small to represent.
1618
```math
17-
w = \frac{L(\lambda_{\mbox{target}})}{L(\lambda_{\mbox{proposal}})}
18-
```
19-
20-
```math
21-
= \left(\frac{\lambda_{\mbox{target}}}{\lambda_{\mbox{proposal}}}\right)^N
22-
```
23-
24-
```math
25-
e^{-(\lambda_{\mbox{target}} - \lambda_{\mbox{proposal}})T}
19+
w = \frac{L(\lambda_{\text{target}})}{L(\lambda_{\text{proposal}})}
20+
= \left(\frac{\lambda_{\text{target}}}{\lambda_{\text{proposal}}}\right)^N
21+
e^{-(\lambda_{\text{target}} - \lambda_{\text{proposal}})T}
2622
```
2723
What you'll see in practice is that the initial simulation, under $p$, works fine, that a small change in a distribution's parameters still works fine, and then the importance-weighted estimates fall off a cliff and show values like $10^{-73}$.
2824

@@ -63,13 +59,13 @@ If it stops growing linearly with N, your proposal is too far from the target.
6359
### Use the coefficient of variation of weights to see where variance explodes.
6460

6561
```math
66-
\mbox{CV}^2 = \frac{\mbox{Var}(w)}{E[w]^2} = \frac{N}{\mbox{ESS}} - 1
62+
\text{CV}^2 = \frac{\text{Var}(w)}{E[w]^2} = \frac{N}{\text{ESS}} - 1
6763
```
6864
Coefficient of variation is a reparametrization of ESS.
6965

7066
### Make a weight histogram
7167

72-
Plot log of the weight, $\log_{10}(w)$ or $\log(w/\mbox{mean}(w))$. You want a unimodal, not-too-wide shape. Heavy-tailed distributions indicate you're close to degeneracy.
68+
Plot log of the weight, $\log_{10}(w)$ or $\log(w/\text{mean}(w))$. You want a unimodal, not-too-wide shape. Heavy-tailed distributions indicate you're close to degeneracy.
7369

7470
## Proposal Improvement
7571

@@ -88,7 +84,7 @@ w_i = \frac{p(x_i)}{\sum_{k=1}^K \alpha_k q_k(x_i)}
8884
```
8985
In log-space, we would use log-sum-exp.
9086
```math
91-
\log w_i = \log p(x_i) - \log\left(\sum_k\alpha_k q_k(x_i)\right) = \log p(x_i) - \mbox{logsumexp}_k(\log \alpha_k+\log q_k(x_i))
87+
\log w_i = \log p(x_i) - \log\left(\sum_k\alpha_k q_k(x_i)\right) = \log p(x_i) - \text{logsumexp}_k(\log \alpha_k+\log q_k(x_i))
9288
```
9389

9490
Let's say we have three proposal distributions from which we sample evenly, so $\alpha=[1/3, 1/3, 1/3]$. We run each simulation where for each enabling of a clock we pass in a vector of four (4) distributions. The first is the proposal distribution we want to use to generate events for this run. The next three are the actual distribution $p$ and the other proposal distributions.
@@ -118,7 +114,7 @@ to reduce variance in your estimate of the rare event.
118114
One each run, you choose bias parameters $\theta$ to minimize the Kullback-Liebler.
119115

120116
```math
121-
\mbox{KL}(p^*||q_\theta)
117+
\text{KL}(p^*||q_\theta)
122118
```
123119

124120
Here $p^*$ is the conditional distribution on the rare event.
@@ -182,7 +178,7 @@ Do the log-space trick. Just like log-sum-exp in machine learning.
182178
Underflow is a problem. $\exp(-700)$ is small enough to underflow.
183179

184180
```math
185-
\frac{e^{\Delta_i}}{\sum_j e^{\Delta_j}} = \frac{e^{\Delta_i}-\mbox{max}(\Delta)}{\sum_j e^{\Delta_j-\mbox{max}(\Delta)}}
181+
\frac{e^{\Delta_i}}{\sum_j e^{\Delta_j}} = \frac{e^{\Delta_i}-\text{max}(\Delta)}{\sum_j e^{\Delta_j-\text{max}(\Delta)}}
186182
```
187183
This makes the probabilities or expectations identical but improves numerical stability.
188184

0 commit comments

Comments
 (0)