From 867752a2da1ec0d8e2fe9737a3fe4bf0cb19adcd Mon Sep 17 00:00:00 2001 From: Cameron Pfiffer Date: Sat, 18 Jan 2020 16:37:04 -0800 Subject: [PATCH] Fix interface guide math, increment version --- Project.toml | 2 +- docs/src/using-turing/interface.md | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Project.toml b/Project.toml index 0714b7909..8895671d8 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/docs/src/using-turing/interface.md b/docs/src/using-turing/interface.md index 868f4ca8b..68d6a0485 100644 --- a/docs/src/using-turing/interface.md +++ b/docs/src/using-turing/interface.md @@ -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: @@ -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. \ No newline at end of file +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.