Skip to content

Commit 0ef7b9d

Browse files
author
Brian DePasquale
committed
updated project version, fixed readme and tests to pass julia 1.0 tests
1 parent ed299d1 commit 0ef7b9d

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "AdvancedMH"
22
uuid = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170"
3-
version = "0.5.4"
3+
version = "0.5.5"
44

55
[deps]
66
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"

README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ chain = psample(model, RWMH(init_params), 100000, 4; param_names=["μ","σ"], ch
123123

124124
AdvancedMH.jl also offers an implementation of [MALA](https://en.wikipedia.org/wiki/Metropolis-adjusted_Langevin_algorithm) if the `ForwardDiff` and `DiffResults` packages are available.
125125

126-
A set of `init_params` are required. `x->` within the `MALA` struct takes the gradient computed at the current sample.
126+
A `MALA` sampler can be constructed by `MALA(proposal)` where `proposal` is a function that
127+
takes the gradient computed at the current sample. It is required to specify an initial sample `init_params` when calling `sample`.
127128

128129
```julia
129130
# Import the package.
@@ -144,11 +145,9 @@ density(θ) = insupport(θ) ? sum(logpdf.(dist(θ), data)) : -Inf
144145
# Construct a DensityModel.
145146
model = DensityModel(density)
146147

147-
#MvNormal covariance
148-
Sigma = 1e-2 * I(2)
149-
150-
# Set up our sampler with a joint multivariate Normal proposal.
151-
spl = MALA(x-> MvNormal((1/2) * Sigma * x, Sigma))
148+
# Set up the sampler with a multivariate Gaussian proposal.
149+
sigma = 1e-1
150+
spl = MALA(x -> MvNormal((sigma^2 / 2) .* x, sigma))
152151

153152
# Sample from the posterior.
154153
chain = sample(model, spl, 100000; init_params=ones(2), chain_type=StructArray, param_names=["μ", "σ"])

src/MALA.jl

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ transition(::MALA, model, params) = GradientTransition(model, params)
2424
# Store the new draw, its log density and its gradient
2525
GradientTransition(model::DensityModel, params) = GradientTransition(params, logdensity_and_gradient(model, params)...)
2626

27+
propose(rng::Random.AbstractRNG, ::MALA, model) = error("please specify initial parameters")
2728

2829
function propose(
2930
rng::Random.AbstractRNG,

test/runtests.jl

+3-4
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,9 @@ using ForwardDiff
107107

108108
@testset "MALA" begin
109109

110-
Sigma = 1e-2 * I(2)
111-
112-
# Set up our sampler with initial parameters.
113-
spl1 = MALA(x-> MvNormal((1/2) * Sigma * x, Sigma))
110+
# Set up the sampler.
111+
sigma = 1e-1
112+
spl1 = MALA(x -> MvNormal((sigma^2 / 2) .* x, sigma))
114113

115114
# Sample from the posterior with initial parameters.
116115
chain1 = sample(model, spl1, 100000; init_params=ones(2), chain_type=StructArray, param_names=["μ", "σ"])

0 commit comments

Comments
 (0)