Skip to content

Commit

Permalink
add tests for initialization methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Red-Portal committed Aug 11, 2024
1 parent a2b2f3a commit 183a387
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/multivariate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,32 @@ end
# Gibbsian polar slice sampling
GibbsPolarSlice(10),
]
@testset "initial_params" begin
model = MultiModel(1.0, 1.0, [0.0])
θ, y = MCMCTesting.sample_joint(Random.default_rng(), model)
model′ = AbstractMCMC.LogDensityModel(@set model.y = y)

θ0 = [1.0, 0.1]
chain = sample(
model,
sampler,
10;
initial_params=θ0,
progress=false,
)
@test first(chain).params == θ0
end

@testset "initial_sample" begin
rng = StableRNG(1)
model = MultiModel(1.0, 1.0, [0.0])
θ0 = SliceSampling.initial_sample(rng, model)

rng = StableRNG(1)
chain = sample(rng, model, sampler, 10; progress=false)
@test first(chain).params == θ0
end

@testset "determinism" begin
model = MultiModel(1.0, 1.0, [0.0])
θ, y = MCMCTesting.sample_joint(Random.default_rng(), model)
Expand Down
26 changes: 26 additions & 0 deletions test/univariate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@ end
SliceSteppingOut(1),
SliceDoublingOut(1),
]
@testset "initialization" begin
model = UniModel([0.0])
θ, y = MCMCTesting.sample_joint(Random.default_rng(), model)
model′ = AbstractMCMC.LogDensityModel(@set model.y = y)

θ0 = [1.0]
chain = sample(
model,
sampler,
10;
initial_params=θ0,
progress=false,
)
@test first(chain).params == θ0
end

@testset "initial_sample" begin
rng = StableRNG(1)
model = UniModel([0.0])
θ0 = SliceSampling.initial_sample(rng, model)

rng = StableRNG(1)
chain = sample(rng, model, sampler, 10; progress=false)
@test first(chain).params == θ0
end

@testset "determinism" begin
model = UniModel([0.0])
θ, y = MCMCTesting.sample_joint(Random.default_rng(), model)
Expand Down

0 comments on commit 183a387

Please sign in to comment.