@@ -74,17 +74,34 @@ include("util.jl")
74
74
end
75
75
76
76
@testset " MCMCChains" begin
77
- spl1 = StaticMH ([ Normal ( 0 , 1 ), Normal ( 0 , 1 )])
78
- spl2 = MetropolisHastings ((μ = StaticProposal ( Normal ( 0 , 1 )), σ = StaticProposal ( Normal ( 0 , 1 ))))
79
-
80
- chain1 = sample (model, spl1, 10_000 ; param_names= [" μ" , " σ" ], chain_type= Chains)
81
- chain2 = sample (model, spl2, 10_000 ; chain_type = Chains )
82
-
77
+ # Array of parameters
78
+ chain1 = sample (
79
+ model, StaticMH ([ Normal ( 0 , 1 ), Normal ( 0 , 1 )]), 10_000 ;
80
+ param_names= [" μ" , " σ" ], chain_type= Chains
81
+ )
82
+ @test chain1 isa Chains
83
83
@test mean (chain1[" μ" ]) ≈ 0.0 atol= 0.1
84
84
@test mean (chain1[" σ" ]) ≈ 1.0 atol= 0.1
85
85
86
+ # NamedTuple of parameters
87
+ chain2 = sample (
88
+ model,
89
+ MetropolisHastings (
90
+ (μ = StaticProposal (Normal (0 ,1 )), σ = StaticProposal (Normal (0 , 1 )))
91
+ ), 10_000 ;
92
+ chain_type= Chains
93
+ )
94
+ @test chain2 isa Chains
86
95
@test mean (chain2[" μ" ]) ≈ 0.0 atol= 0.1
87
96
@test mean (chain2[" σ" ]) ≈ 1.0 atol= 0.1
97
+
98
+ # Scalar parameter
99
+ chain3 = sample (
100
+ DensityModel (x -> loglikelihood (Normal (x, 1 ), data)),
101
+ StaticMH (Normal (0 , 1 )), 10_000 ; param_names= [" μ" ], chain_type= Chains
102
+ )
103
+ @test chain3 isa Chains
104
+ @test mean (chain3[" μ" ]) ≈ 0.0 atol= 0.1
88
105
end
89
106
90
107
@testset " Proposal styles" begin
@@ -194,7 +211,6 @@ include("util.jl")
194
211
end
195
212
196
213
@testset " MALA" begin
197
-
198
214
# Set up the sampler.
199
215
sigma = 1e-1
200
216
spl1 = MALA (x -> MvNormal ((sigma^ 2 / 2 ) .* x, sigma))
@@ -203,9 +219,8 @@ include("util.jl")
203
219
chain1 = sample (model, spl1, 100000 ; init_params= ones (2 ), chain_type= StructArray, param_names= [" μ" , " σ" ])
204
220
205
221
@test mean (chain1. μ) ≈ 0.0 atol= 0.1
206
- @test mean (chain1. σ) ≈ 1.0 atol= 0.1
222
+ @test mean (chain1. σ) ≈ 1.0 atol= 0.1
207
223
end
208
224
209
225
@testset " EMCEE" begin include (" emcee.jl" ) end
210
-
211
226
end
0 commit comments