-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a DynamicHMC section to the docs (#623)
* Added a DynamicHMC section. * Added compositional inference note.
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 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
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,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)) | ||
``` |