1- const test_bounds = [Bounds. Ellipsoid, Bounds. MultiEllipsoid]
2- const test_props = [Proposals. Rejection (maxiter= Int (1e6 )), Proposals. RWalk (ratio= 0.9 , walks= 50 ), Proposals. RStagger (ratio= 0.9 , walks= 75 ), Proposals. Slice (slices= 10 ), Proposals. RSlice ()]
1+ const test_bounds = [
2+ Bounds. Ellipsoid,
3+ Bounds. MultiEllipsoid
4+ ]
5+ const test_props = [
6+ Proposals. Rejection (maxiter= Int (1e6 )),
7+ Proposals. RWalk (ratio= 0.5 , walks= 50 ),
8+ Proposals. RStagger (ratio= 0.5 , walks= 50 ),
9+ Proposals. Slice (slices= 10 ),
10+ Proposals. RSlice (slices= 10 )
11+ ]
12+
13+ const MAXZSCORES = Dict (zip (
14+ Iterators. product (test_bounds, test_props),
15+ [3 , 3 , 5 , 6 , 6 , 3 , 5 , 7 , 4 , 3 ]
16+ ))
17+
18+ function test_logz (measured, actual, error, bound, proposal)
19+ diff = measured - actual
20+ zscore = abs (diff) / error
21+ @test measured ≈ actual atol= MAXZSCORES[(bound, proposal)] * error
22+ end
323
424
525@testset " $(nameof (bound)) , $(nameof (typeof (proposal))) " for bound in test_bounds, proposal in test_props
@@ -21,14 +41,7 @@ const test_props = [Proposals.Rejection(maxiter=Int(1e6)), Proposals.RWalk(ratio
2141 @test all (@. (abs (means - expected) < tols))
2242
2343 # logz
24- if proposal isa Proposals. RWalk || proposal isa Proposals. RStagger
25- # bump to 6sigma because RWalk and RStagger _struggle_
26- # better approach for this?? TODO
27- tol = 6 state. logzerr
28- else
29- tol = 5 state. logzerr
30- end
31- @test state. logz ≈ logz atol = tol
44+ test_logz (state. logz, logz, state. logzerr, bound, proposal)
3245 end
3346
3447 @testset " Gaussian Shells" begin
@@ -39,7 +52,7 @@ const test_props = [Proposals.Rejection(maxiter=Int(1e6)), Proposals.RWalk(ratio
3952 chain, state = sample (rng, model, sampler; dlogz= 0.01 )
4053
4154 # logz
42- @test state. logz ≈ logz atol = 5 state . logzerr
55+ test_logz ( state. logz, logz, state . logzerr, bound, proposal)
4356 end
4457
4558 @testset " Gaussian Mixture Model" begin
@@ -56,7 +69,7 @@ const test_props = [Proposals.Rejection(maxiter=Int(1e6)), Proposals.RWalk(ratio
5669 return logaddexp (f1, f2)
5770 end
5871
59- prior (X) = 10 .* X .- 5
72+ prior (X) = muladd .( 10 , X, - 5 )
6073 model = NestedModel (logl, prior)
6174
6275 analytic_logz = log (4 π * σ^ 2 / 100 )
@@ -66,13 +79,8 @@ const test_props = [Proposals.Rejection(maxiter=Int(1e6)), Proposals.RWalk(ratio
6679 chain, state = sample (rng, model, spl; dlogz= 0.01 )
6780 chain_res = sample (rng, chain, Weights (vec (chain[:weights ])), length (chain))
6881
69- diff = state. logz - analytic_logz
70- atol = 6 state. logzerr
71- if diff > atol
72- @warn " logz estimate is poor" bound proposal error = diff tolerance = atol
73- end
82+ test_logz (state. logz, analytic_logz, state. logzerr, bound, proposal)
7483
75- @test state. logz ≈ analytic_logz atol = atol # within 1σ
7684 xmodes = sort! (findpeaks (chain_res[:, 1 , 1 ])[1 : 2 ])
7785 @test xmodes[1 ] ≈ - 1 atol = σ
7886 @test xmodes[2 ] ≈ 1 atol = σ
@@ -88,7 +96,7 @@ const test_props = [Proposals.Rejection(maxiter=Int(1e6)), Proposals.RWalk(ratio
8896
8997 chain, state = sample (rng, model, sampler; dlogz= 0.1 )
9098
91- @test state. logz ≈ logz atol = 5 state . logzerr
99+ test_logz ( state. logz, logz, state . logzerr, bound, proposal)
92100
93101 chain_res = sample (rng, chain, Weights (vec (chain[:weights ])), length (chain))
94102 xmodes = sort! (findpeaks (chain_res[:, 1 , 1 ])[1 : 5 ])
@@ -97,4 +105,3 @@ const test_props = [Proposals.Rejection(maxiter=Int(1e6)), Proposals.RWalk(ratio
97105 @test all (isapprox .(ymodes, 0.1 : 0.2 : 0.9 , atol= 0.2 ))
98106 end
99107end
100-
0 commit comments