-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Doc updates, full tests re-enabled, osx disabled in travis
- Loading branch information
Showing
12 changed files
with
43 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
language: julia | ||
os: | ||
- linux | ||
- osx | ||
# - osx | ||
julia: | ||
- 0.6 | ||
- nightly | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Connection to hidden Markov models | ||
|
||
Probably the most common use for SMC is in statistical applications involving hidden Markov models (HMMs), where the methodology originates. Indeed, there is a very simple correspondence between an HMM and an SMC model. The purpose of this part of the documentation is only to clarify how different SMC models can be associated with the same HMM. | ||
|
||
An simple HMM can be described as a bivariate Markov chain $(X_1,Y_1), \ldots, (X_n, Y_n)$ as follows. $X_1, \ldots, X_n$ is a Markov chain determined by an initial distribution $\mu$ and Markov transition densities $f_2, \ldots, f_n$. For each $p \in \{1, \ldots, n\}$, $Y_p$ is conditionally independent of all other random variables given $X_p$ and $Y_p \mid (X_p = x)$ has density $g_p(x, \cdot)$. Statistical inference for HMMs involve performing inference after observing $(y_1, \ldots, y_n)$ as a realization of $(Y_1, \ldots, Y_n)$. | ||
|
||
A standard use of SMC for such an HMM is as follows. Let the observations $(y_1, \ldots, y_n)$ be given and choose $M_1 = \mu$, $M_p(x, dx') = f_p(x, x') dx'$ for $p \in \{2, \ldots, n\}$ and $G_p(x) = g_p(x, y_p)$ for $p \in \{1, \ldots, n\}$. Notice that the potential function $G_p$ is defined using the observation $y_p$. Then it can be deduced that $\hat{Z}_p$ is the *marginal likelihood* associated with the first $p$ observations, $\eta_p$ is the *predictive* distribution of $X_p$ given the first $p-1$ observations and $\hat{\eta}_p$ is the *filtering* distribution of $X_p$ given the first $p$ observations. That is, \\[ X_p \mid \\{(Y_0, \ldots, Y_{p-1}) = (y_0, \ldots, y_{p-1})\\} \sim \eta_p \\] and \\[ X_p \mid \\{(Y_0, \ldots, Y_{p}) = (y_0, \ldots, y_{p})\\} \sim \hat{\eta}_p. \\] | ||
|
||
However, this is only one way to map the HMM into an SMC Model. We extend the HMM's state space and define $M_1(d(x_{\rm prev}, x)) = \mu(dx) \delta_x(dx_{\rm prev})$, and \\[ M_p((x_{\rm prev},x), d(x_{\rm prev}',x')) = q_p(x, x') \delta_x(dx_{\rm prev}'), \qquad p \in \\{2, \ldots, n\\} \\] where $q_p$ is such that $q_p(x, x') > 0$ whenever $f_p(x, x') > 0$. Then one can define \\[ G_p(x_{\rm prev}, x) = \frac{f_p(x_{\rm prev}, x)}{q_p(x_{\rm prev}, x)} g(x, y_p), \qquad p \in \\{1, \ldots, n\\} \\] and it is still the case that $\hat{Z}_p$ is the marginal likelihood associated with the first $p$ observations, $\eta_p$ is the predictive distribution of $X_p$ given the first $p-1$ observations and $\hat{\eta}_p$ is the filtering distribution of $X_p$ given the first $p$ observations. An example of using different SMC models for a given HMM is provided in [SMCExamples: comparison of Linear Gaussian models](https://github.com/awllee/SMCExamples.jl/blob/master/demo/lgComparisonDemo.jl) ; the model associated with the "locally optimal proposal" is defined [here](https://github.com/awllee/SMCExamples.jl/blob/master/src/lgLOPModel.jl). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
# Implementation notes | ||
|
||
The multi-threaded implementation of SMC is fairly straightforward. The attempt to efficiently utilize multiple cores is largely focused around low-overhead resampling / selection, since the remaining steps are embarrassingly parallel. | ||
The multi-threaded implementation of SMC is fairly straightforward. The attempt to efficiently utilize multiple cores is largely focused around using appropriate data structures and low-overhead resampling / selection, since the remaining steps are embarrassingly parallel. | ||
|
||
There is also some attention paid to Julia's threading interface and, for both parallel and serial execution, the need to avoid dynamic memory allocations. All code for the main package was written using Julia's core and base functionality. | ||
There is also some attention paid to Julia's threading interface and, for both parallel and serial execution, the need to avoid dynamic memory allocations by pre-allocating reusable memory. All code for the package was written using Julia's core and base functionality. | ||
|
||
Generating the ancestor indices in sorted order is accomplished primarily through use of the uniform spacings method for generating a sequence of sorted uniform random variates developed by Lurie & Hartley (1972) and described by Devroye (1986, p. 214). In multi-threaded code, the multinomial variate giving the number of ancestor indices each thread should simulate using a thread-specific local vector of particle weights is simulated by using a combination of inversion sampling and a a Julia implementation of the ```btrd``` algorithm of Hörmann (1993), which simulates binomially distributed variates in expected $\mathcal{O}(1)$ time. Simulating a multinomial random variate is accomplished by simulating a sequence of appropriate Binomial random variates. The code-generating function for copying particles was adapted from [a suggestion on Julia Discourse](https://discourse.julialang.org/t/how-to-copy-all-fields-without-changing-the-referece/945/5) by Greg Plowman. | ||
Generating the ancestor indices in sorted order is accomplished primarily through use of the uniform spacings method for generating a sequence of sorted uniform random variates developed by Lurie & Hartley (1972) and described by Devroye (1986, p. 214). In multi-threaded code, the multinomial variate giving the number of ancestor indices each thread should simulate using a thread-specific subvector of particle weights is simulated by using a combination of inversion sampling and an implementation of the ```btrd``` algorithm of Hörmann (1993), which simulates binomially distributed variates in expected $\mathcal{O}(1)$ time. Simulating a multinomial random variate is accomplished by simulating a sequence of appropriate Binomial random variates. The code-generating function for copying particles was adapted from [a suggestion on Julia Discourse](https://discourse.julialang.org/t/how-to-copy-all-fields-without-changing-the-referece/945/5) by Greg Plowman. | ||
|
||
For the demonstration code, use of the [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl) package provides dramatic improvements for multivariate particles, and is highly recommended for fixed-size vector components of particles. It is possible to use the counter-based RNGs in the [RandomNumbers.jl](https://github.com/sunoru/RandomNumbers.jl) package in place of the default random number generator; this was not working on the Julia-0.7 master branch at the time of development, and is slightly slower than the MersenneTwister RNG provided by Julia's base. | ||
For the demonstration code in the [SMCExamples](https://github.com/awllee/SMCExamples.jl) package, use of [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl) provides dramatic improvements for multivariate particles, and is highly recommended for fixed-size vector components of particles. | ||
|
||
It is possible to use the counter-based RNGs in the [RandomNumbers.jl](https://github.com/sunoru/RandomNumbers.jl) package in place of the default random number generator; this was not working on the Julia-0.7 development branch at the time of development, and is slightly slower than the MersenneTwister RNG provided by Julia's base. In the future, allowing users to choose between the two, or to specify their own RNGs, would be useful. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#SMCExamples | ||
SMCExamples | ||
StaticArrays |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters