Skip to content

Commit

Permalink
Use StableRNG, relax test tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
mhauru committed Dec 3, 2024
1 parent 5f21c84 commit a15ce2f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test/mcmc/gibbs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ using ForwardDiff: ForwardDiff
using Random: Random
using ReverseDiff: ReverseDiff
import Mooncake
using StableRNGs: StableRNG
using Test: @inferred, @test, @test_broken, @test_deprecated, @test_throws, @testset
using Turing
using Turing: Inference
Expand Down Expand Up @@ -463,7 +464,10 @@ end
# https://github.com/TuringLang/Turing.jl/issues/1725
# sample(model, Gibbs(; z=MH(), m=HMC(0.01, 4)), 100);
chn = sample(
model, Gibbs(; z=PG(10), m=HMC(0.01, 4; adtype=adbackend)), num_samples
StableRNG(23),
model,
Gibbs(; z=PG(10), m=HMC(0.01, 4; adtype=adbackend)),
num_samples,
)
# The number of m variables that have a non-zero value in a sample.
num_ms = count(ismissing.(Array(chn[:, (num_zs + 1):end, 1])); dims=2)
Expand All @@ -476,7 +480,7 @@ end
# the posterior is analytically known? Doing 10_000 samples to run the test suite
# is not ideal
# Issue ref: https://github.com/TuringLang/Turing.jl/issues/2402
@test isapprox(mean(num_ms), 8.6087; atol=0.5)
@test isapprox(mean(num_ms), 8.6087; atol=0.8)
@test isapprox(std(num_ms), 1.8865; atol=0.02)
end

Expand Down

0 comments on commit a15ce2f

Please sign in to comment.