Skip to content

Commit

Permalink
Add a DynamicHMC section to the docs (#623)
Browse files Browse the repository at this point in the history
* Added a DynamicHMC section.

* Added compositional inference note.
  • Loading branch information
cpfiffer authored and yebai committed Dec 13, 2018
1 parent 5fb9de3 commit 3c8ea47
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/site/_data/navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ docs:
url: /docs/guide/
- title: "Advanced Usage"
url: /docs/advanced/
- title: "Using DynamicHMC"
url: /docs/dynamichmc/

- title: Library
children:
Expand Down
29 changes: 29 additions & 0 deletions docs/src/dynamichmc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: Using DynamicHMC
permalink: /docs/dynamichmc/
---

Turing supports the use of [DynamicHMC](https://github.com/tpapp/DynamicHMC.jl) as a sampler through the use of the `DynamicNUTS` function. This is a [faster](https://github.com/TuringLang/Turing.jl/issues/559) version of Turing's native `NUTS` implementation.

`DynamicNUTS` is not appropriate for use in compositional inference. If you intend to use [Gibbs](http://turing.ml/docs/library/#-turinggibbs--type) sampling, you must use Turing's native `NUTS` function.

To use the `DynamicNUTS` function, you must import the `DynamicHMC` package as well as Turing. Turing does not formally require `DynamicHMC` but will include additional functionality if both packages are present.

Here is a brief example of how to apply `DynamicNUTS`:

```julia
# Import Turing and DynamicHMC.
using DynamicHMC, Turing

# Model definition.
@model gdemo(x, y) = begin
s ~ InverseGamma(2,3)
m ~ Normal(0,sqrt(s))
x ~ Normal(m, sqrt(s))
y ~ Normal(m, sqrt(s))
return s, m
end

# Pull 2,000 samples using DynamicNUTS.
chn = sample(gdemo(1.5, 2.0), DynamicNUTS(2000))
```

0 comments on commit 3c8ea47

Please sign in to comment.