Skip to content

Commit

Permalink
Fix interface guide math, increment version
Browse files Browse the repository at this point in the history
  • Loading branch information
cpfiffer committed Jan 19, 2020
1 parent 7726d27 commit 867752a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Turing"
uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
version = "0.8.2"
version = "0.8.3"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
18 changes: 8 additions & 10 deletions docs/src/using-turing/interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,22 @@ transition_type(model::DensityModel, spl::MetropolisHastings) =

### Metropolis-Hastings

Now it's time to get into the actual inference. We've defined all of the core pieces we need, but we need to implement the `step!` function which actually perform inference.
Now it's time to get into the actual inference. We've defined all of the core pieces we need, but we need to implement the `step!` function which actually performs inference.

As a refresher, Metropolis-Hastings implements a very basic algorithm:

1. Pick some initial state, $\theta_0$.
2. For $t$ in $[1,N]$, do
1. Pick some initial state, \$\$\theta\_0\$\$.
2. For \$\$t\$\$ in \$\$[1,N]\$\$, do

a. Generate a proposal parameterization $θ'_t \sim q(\theta'_t \mid \theta_{t-1})$.
a. Generate a proposal parameterization \$\$θ'\_t \sim q(\theta'\_t \mid \theta\_{t-1})\$\$.

b. Calculate the acceptance probability, $\alpha = \text{min}\Big[1,\frac{\pi(θ'_t)}{\pi(\theta_{t-1})} \frac{q(θ_{t-1} \mid θ'_t)}{q(θ'_t \mid θ_{t-1})}) \Big]$.
b. Calculate the acceptance probability, \$\$\alpha = \text{min}\Big[1,\frac{\pi(θ'\_t)}{\pi(\theta\_{t-1})} \frac{q(θ\_{t-1} \mid θ'\_t)}{q(θ'\_t \mid θ\_{t-1})}) \Big]\$\$.

c. If $U \le α$ where $U \sim [0,1]$, then $\theta_t = \theta'_t$. Otherwise, $\theta_t = \theta_{t-1}$.
c. If \$\$U \le α\$\$ where \$\$U \sim [0,1]\$\$, then \$\$\theta\_t = \theta'\_t\$\$. Otherwise, \$\$\theta\_t = \theta\_{t-1}\$\$.

Of course, it's much easier to do this in the log space, so the acceptance probability is more commonly written as

$$
\alpha = \min\Big[\log \pi(θ'_t) - \log \pi(θ_{t-1}) + \log q(θ_{t-1} \mid θ'_t) - \log q(θ'_t \mid θ_{t-1}), 0\Big]
$$
$$\alpha = \min\Big[\log \pi(θ'\_t) - \log \pi(θ\_{t-1}) + \log q(θ\_{t-1} \mid θ'\_t) - \log q(θ'\_t \mid θ\_{t-1}), 0\Big]$$

In interface terms, we should do the following:

Expand Down Expand Up @@ -315,4 +313,4 @@ It looks like we're extremely close to our true parameters of `Normal(5,3)`, tho

## Conclusion

We've seen how to implement the sampling interface for general projects. Turing's interface methods are ever-evolving, so please open an issue at [AbstractMCMC](https://github.com/TuringLang/AbstractMCMC.jl) with feature requests or problems.
We've seen how to implement the sampling interface for general projects. Turing's interface methods are ever-evolving, so please open an issue at [AbstractMCMC](https://github.com/TuringLang/AbstractMCMC.jl) with feature requests or problems.

0 comments on commit 867752a

Please sign in to comment.