Skip to content

Commit

Permalink
Add init_params keyword argument (#26)
Browse files Browse the repository at this point in the history
* Update abstractmcmc.jl

* Update interface.jl

* Update src/interface.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Modified proposal and added basic tests

* Update src/abstractmcmc.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Correct typos

* Mentionned keyword argument in docs, patch bump and test fix

* Update test/simple.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Fix tests

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 19, 2022
1 parent ca39ed3 commit 65feb50
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "EllipticalSliceSampling"
uuid = "cad2338a-1db2-11e9-3401-43bc07c9ede2"
authors = ["David Widmann <david.widmann@it.uu.se>"]
version = "0.4.5"
version = "0.4.6"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
2 changes: 2 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ AbstractMCMC.steps(
gives you access to an iterator from which you can generate an unlimited
number of samples.

You can define the starting point of your chain using the `init_params` keyword argument.

For more details regarding `sample` and `steps` please check the documentation of
[AbstractMCMC.jl](https://github.com/TuringLang/AbstractMCMC.jl).

Expand Down
8 changes: 6 additions & 2 deletions src/abstractmcmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ end

# first step of the elliptical slice sampler
function AbstractMCMC.step(
rng::Random.AbstractRNG, model::AbstractMCMC.AbstractModel, ::ESS; kwargs...
rng::Random.AbstractRNG,
model::AbstractMCMC.AbstractModel,
::ESS;
init_params=nothing,
kwargs...,
)
# initial sample from the Gaussian prior
f = initial_sample(rng, model)
f = init_params === nothing ? initial_sample(rng, model) : init_params

# compute log-likelihood of the initial sample
loglikelihood = Distributions.loglikelihood(model, f)
Expand Down
24 changes: 24 additions & 0 deletions test/simple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
@test mean(mean, samples) μ atol = 0.05
@test mean(var, samples) σ² atol = 0.05
end

# initial parameter
init_x = randn()
samples = sample(ESSModel(prior, ℓ), ESS(), 10; progress=false, init_params=init_x)
@test first(samples) == init_x
end

@testset "Scalar model with nonzero mean" begin
Expand Down Expand Up @@ -62,6 +67,11 @@
@test mean(mean, samples) μ atol = 0.05
@test mean(var, samples) σ² atol = 0.05
end

# initial parameter
init_x = randn()
samples = sample(ESSModel(prior, ℓ), ESS(), 10; progress=false, init_params=init_x)
@test first(samples) == init_x
end

@testset "Scalar model (vectorized)" begin
Expand Down Expand Up @@ -91,6 +101,13 @@
@test mean(mean, samples) μ atol = 0.05
@test mean(var, samples) σ² atol = 0.05
end

# initial parameter
init_x = randn(1)
samples = sample(
ESSModel(prior, ℓvec), ESS(), 10; progress=false, init_params=init_x
)
@test first(samples) == init_x
end

@testset "Scalar model with nonzero mean (vectorized)" begin
Expand Down Expand Up @@ -120,5 +137,12 @@
@test mean(mean, samples) μ atol = 0.05
@test mean(var, samples) σ² atol = 0.05
end

# initial parameter
init_x = randn(1)
samples = sample(
ESSModel(prior, ℓvec), ESS(), 10; progress=false, init_params=init_x
)
@test first(samples) == init_x
end
end

2 comments on commit 65feb50

@devmotion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/52775

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.6 -m "<description of version>" 65feb501e5780a05a8c06125f9f9c9dbabcf968d
git push origin v0.4.6

Please sign in to comment.