Skip to content

Commit 2a585fc

Browse files
committed
Add clarifying comment for IS test
1 parent 5ed1230 commit 2a585fc

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

test/mcmc/is.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,23 @@ using Turing
2929
return a, b
3030
end
3131

32-
function expected_loglikelihoods(as, bs)
33-
return logpdf.(Normal.(as, 2), 3) .+ logpdf.(Normal.(bs, 2), 1.5)
34-
end
35-
3632
alg = IS()
3733
N = 1000
3834
model = normal()
3935
chain = sample(StableRNG(468), model, alg, N)
4036
ref = reference(N)
4137

38+
# Note that in general, mean(chain) will differ from mean(ref). This is because the
39+
# sampling process introduces extra calls to rand(), etc. which changes the output.
40+
# These tests therefore are only meant to check that the results are qualitatively
41+
# similar to the reference implementation of IS, and hence the atol is set to
42+
# something fairly large.
4243
@test isapprox(mean(chain[:a]), mean(ref.as); atol=0.1)
4344
@test isapprox(mean(chain[:b]), mean(ref.bs); atol=0.1)
45+
46+
function expected_loglikelihoods(as, bs)
47+
return logpdf.(Normal.(as, 2), 3) .+ logpdf.(Normal.(bs, 2), 1.5)
48+
end
4449
@test isapprox(chain[:loglikelihood], expected_loglikelihoods(chain[:a], chain[:b]))
4550
@test isapprox(chain.logevidence, logsumexp(chain[:loglikelihood]) - log(N))
4651
end

0 commit comments

Comments
 (0)