Skip to content

Commit

Permalink
Fixed Bernoulli example, moved to examples repo.
Browse files Browse the repository at this point in the history
cf
tpapp/DynamicHMCExamples.jl@0ded67d

Bug reported by Andrew Slaughter (thanks!).
  • Loading branch information
tpapp committed Mar 7, 2018
1 parent 4b7cc86 commit f74df53
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 39 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Consequently, this package requires that the user is comfortable with the basics

Also, the building blocks of the algorithm are implemented using a *functional* (non-modifying) approach whenever possible, allowing extensive unit testing of components, while at the same time also intended to serve as a transparent, pedagogical introduction to the low-level mechanics of current Hamiltonian Monte Carlo samplers.

Examples are available in [DynamicHMCExamples.jl](https://github.com/tpapp/DynamicHMCExamples.jl).

## Bibliography

Expand Down
16 changes: 13 additions & 3 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ CurrentModule = DynamicHMC

The density function should take a single argument `q`, which is a vector of numbers, and return an object which provides the methods `DiffResults.value` and `DiffResults.gradient` to access ``\ell(q)`` and ``\nabla\ell(q)``, respectively.

The following example implements the density function for ``n`` observations from a ``\text{Bernoulli}(\alpha)`` distribution, ``s`` of which are `1`. The complete example is available in [`tests/example.jl`](https://github.com/tpapp/DynamicHMC.jl/blob/master/test/test-sample-dummy.jl).
The following example implements the density function for ``n`` observations from a ``\text{Bernoulli}(\alpha)`` distribution, ``s`` of which are `1`. This example and others are available in [DynamicHMCExamples.jl](https://github.com/tpapp/DynamicHMCExamples.jl).

First, we load some packages we use (you may have to install them):
```julia
using DynamicHMC
using ContinuousTransformations
using Parameters
using MCMCDiagnostics
using DiffWrappers
```

It is convenient to define a structure that holds the data,

Expand All @@ -19,10 +28,11 @@ struct BernoulliProblem
end
```

then make it callable:
then make it callable (with a vector argument):

```julia
function (problem::BernoulliProblem)(α)
function (problem::BernoulliProblem)(θ)
α, = θ # extract the first parameter
@unpack n, s = problem # using Parameters
s * log(α) + (n-s) * log(1-α) # log likelihood
end
Expand Down
36 changes: 0 additions & 36 deletions test/example.jl

This file was deleted.

0 comments on commit f74df53

Please sign in to comment.