Skip to content

Commit

Permalink
made the MH inference tests a bit more predictable by providing
Browse files Browse the repository at this point in the history
initial params
  • Loading branch information
torfjelde committed Jun 26, 2024
1 parent e2a0678 commit 605fbfb
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions test/mcmc/mh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,41 @@ GKernel(var) = (x) -> Normal(x, sqrt.(var))
# c6 = sample(gdemo_default, s6, N)
end
@testset "mh inference" begin
# Set the initial parameters, because if we get unlucky with the initial state,
# these chains are too short to converge to reasonable numbers.
discard_initial = 1000
initial_params = [1.0, 1.0]

Random.seed!(125)
alg = MH()
chain = sample(gdemo_default, alg, 10_000; discard_initial=1000)
chain = sample(gdemo_default, alg, 10_000; discard_initial, initial_params)
check_gdemo(chain; atol=0.1)

Random.seed!(125)
# MH with Gaussian proposal
alg = MH((:s, InverseGamma(2, 3)), (:m, GKernel(1.0)))
chain = sample(gdemo_default, alg, 10_000; discard_initial=1000)
chain = sample(gdemo_default, alg, 10_000; discard_initial, initial_params)
check_gdemo(chain; atol=0.1)

Random.seed!(125)
# MH within Gibbs
alg = Gibbs(MH(:m), MH(:s))
chain = sample(gdemo_default, alg, 10_000; discard_initial=1000)
chain = sample(gdemo_default, alg, 10_000; discard_initial, initial_params)
check_gdemo(chain; atol=0.1)

Random.seed!(125)
# MoGtest
gibbs = Gibbs(
CSMC(15, :z1, :z2, :z3, :z4), MH((:mu1, GKernel(1)), (:mu2, GKernel(1)))
)
chain = sample(MoGtest_default, gibbs, 500; discard_initial=100)
check_MoGtest_default(chain; atol=0.15)
chain = sample(
MoGtest_default,
gibbs,
500;
discard_initial=100,
initial_params=[1.0, 1.0, 0.0, 0.0, 1.0, 4.0],
)
check_MoGtest_default(chain; atol=0.2)
end

# Test MH shape passing.
Expand Down

0 comments on commit 605fbfb

Please sign in to comment.