From 0a0853deedc90831572cff381b3649005955e849 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Fri, 27 Oct 2023 09:39:30 +0200 Subject: [PATCH] Rename `init_params` keyword argument to `initial_params` (#33) * Rename `init_params` keyword argument to `initial_params` * 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> --- Project.toml | 4 ++-- docs/src/index.md | 2 +- src/abstractmcmc.jl | 4 ++-- test/simple.jl | 32 ++++++++++++++++++++++++-------- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Project.toml b/Project.toml index 319ceae..377338d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "EllipticalSliceSampling" uuid = "cad2338a-1db2-11e9-3401-43bc07c9ede2" authors = ["David Widmann "] -version = "1.1.0" +version = "2.0.0" [deps] AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001" @@ -11,7 +11,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] -AbstractMCMC = "3.2, 4" +AbstractMCMC = "5" ArrayInterface = "7" Distributions = "0.22, 0.23, 0.24, 0.25" julia = "1.6" diff --git a/docs/src/index.md b/docs/src/index.md index 7dcbd12..4b6e4b7 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -55,7 +55,7 @@ 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. +You can define the starting point of your chain using the `initial_params` keyword argument. For more details regarding `sample` and `steps` please check the documentation of [AbstractMCMC.jl](https://github.com/TuringLang/AbstractMCMC.jl). diff --git a/src/abstractmcmc.jl b/src/abstractmcmc.jl index f0c2499..32691a2 100644 --- a/src/abstractmcmc.jl +++ b/src/abstractmcmc.jl @@ -22,11 +22,11 @@ function AbstractMCMC.step( rng::Random.AbstractRNG, model::AbstractMCMC.AbstractModel, ::ESS; - init_params=nothing, + initial_params=nothing, kwargs..., ) # initial sample from the Gaussian prior - f = init_params === nothing ? initial_sample(rng, model) : init_params + f = initial_params === nothing ? initial_sample(rng, model) : initial_params # compute log-likelihood of the initial sample loglikelihood = Distributions.loglikelihood(model, f) diff --git a/test/simple.jl b/test/simple.jl index 1f4696c..5324388 100644 --- a/test/simple.jl +++ b/test/simple.jl @@ -37,14 +37,16 @@ # initial parameter init_x = randn(5) samples = sample( - ESSModel(prior, ℓ), ESS(), alg, 10, 5; progress=false, init_params=init_x + ESSModel(prior, ℓ), ESS(), alg, 10, 5; progress=false, initial_params=init_x ) @test map(first, samples) == init_x end # initial parameter init_x = randn() - samples = sample(ESSModel(prior, ℓ), ESS(), 10; progress=false, init_params=init_x) + samples = sample( + ESSModel(prior, ℓ), ESS(), 10; progress=false, initial_params=init_x + ) @test first(samples) == init_x end @@ -77,14 +79,16 @@ # initial parameter init_x = randn(5) samples = sample( - ESSModel(prior, ℓ), ESS(), alg, 10, 5; progress=false, init_params=init_x + ESSModel(prior, ℓ), ESS(), alg, 10, 5; progress=false, initial_params=init_x ) @test map(first, samples) == init_x end # initial parameter init_x = randn() - samples = sample(ESSModel(prior, ℓ), ESS(), 10; progress=false, init_params=init_x) + samples = sample( + ESSModel(prior, ℓ), ESS(), 10; progress=false, initial_params=init_x + ) @test first(samples) == init_x end @@ -118,7 +122,13 @@ # initial parameter init_x = [randn(1) for _ in 1:5] samples = sample( - ESSModel(prior, ℓvec), ESS(), alg, 10, 5; progress=false, init_params=init_x + ESSModel(prior, ℓvec), + ESS(), + alg, + 10, + 5; + progress=false, + initial_params=init_x, ) @test map(first, samples) == init_x end @@ -126,7 +136,7 @@ # initial parameter init_x = randn(1) samples = sample( - ESSModel(prior, ℓvec), ESS(), 10; progress=false, init_params=init_x + ESSModel(prior, ℓvec), ESS(), 10; progress=false, initial_params=init_x ) @test first(samples) == init_x end @@ -161,7 +171,13 @@ # initial parameter init_x = [randn(1) for _ in 1:5] samples = sample( - ESSModel(prior, ℓvec), ESS(), alg, 10, 5; progress=false, init_params=init_x + ESSModel(prior, ℓvec), + ESS(), + alg, + 10, + 5; + progress=false, + initial_params=init_x, ) @test map(first, samples) == init_x end @@ -169,7 +185,7 @@ # initial parameter init_x = randn(1) samples = sample( - ESSModel(prior, ℓvec), ESS(), 10; progress=false, init_params=init_x + ESSModel(prior, ℓvec), ESS(), 10; progress=false, initial_params=init_x ) @test first(samples) == init_x end