@@ -35,14 +35,15 @@ include("interface.jl")
35
35
@test Logging. current_logger () === CURRENT_LOGGER
36
36
37
37
# test output type and size
38
- @test chain isa Vector{MyTransition}
38
+ @test chain isa Vector{<: MyTransition }
39
39
@test length (chain) == N
40
40
41
41
# test some statistical properties
42
- @test mean (x. a for x in chain) ≈ 0.5 atol= 6e-2
43
- @test var (x. a for x in chain) ≈ 1 / 12 atol= 5e-3
44
- @test mean (x. b for x in chain) ≈ 0.0 atol= 5e-2
45
- @test var (x. b for x in chain) ≈ 1 atol= 6e-2
42
+ tail_chain = @view chain[2 : end ]
43
+ @test mean (x. a for x in tail_chain) ≈ 0.5 atol= 6e-2
44
+ @test var (x. a for x in tail_chain) ≈ 1 / 12 atol= 5e-3
45
+ @test mean (x. b for x in tail_chain) ≈ 0.0 atol= 5e-2
46
+ @test var (x. b for x in tail_chain) ≈ 1 atol= 6e-2
46
47
end
47
48
48
49
@testset " Juno" begin
@@ -118,26 +119,28 @@ include("interface.jl")
118
119
end
119
120
120
121
Random. seed! (1234 )
121
- chains = sample (MyModel (), MySampler (), MCMCThreads (), 10_000 , 1000 ;
122
+ N = 10_000
123
+ chains = sample (MyModel (), MySampler (), MCMCThreads (), N, 1000 ;
122
124
chain_type = MyChain)
123
125
124
126
# test output type and size
125
- @test chains isa Vector{MyChain}
127
+ @test chains isa Vector{<: MyChain }
126
128
@test length (chains) == 1000
127
- @test all (x -> length (x. as) == length (x. bs) == 10_000 , chains)
129
+ @test all (x -> length (x. as) == length (x. bs) == N , chains)
128
130
129
131
# test some statistical properties
130
- @test all (x -> isapprox (mean (x. as), 0.5 ; atol= 1e-2 ), chains)
131
- @test all (x -> isapprox (var (x. as), 1 / 12 ; atol= 5e-3 ), chains)
132
- @test all (x -> isapprox (mean (x. bs), 0 ; atol= 5e-2 ), chains)
133
- @test all (x -> isapprox (var (x. bs), 1 ; atol= 5e-2 ), chains)
132
+ @test all (x -> isapprox (mean (@view x. as[ 2 : end ] ), 0.5 ; atol= 1e-2 ), chains)
133
+ @test all (x -> isapprox (var (@view x. as[ 2 : end ] ), 1 / 12 ; atol= 5e-3 ), chains)
134
+ @test all (x -> isapprox (mean (@view x. bs[ 2 : end ] ), 0 ; atol= 5e-2 ), chains)
135
+ @test all (x -> isapprox (var (@view x. bs[ 2 : end ] ), 1 ; atol= 5e-2 ), chains)
134
136
135
137
# test reproducibility
136
138
Random. seed! (1234 )
137
- chains2 = sample (MyModel (), MySampler (), MCMCThreads (), 10_000 , 1000 ;
139
+ chains2 = sample (MyModel (), MySampler (), MCMCThreads (), N , 1000 ;
138
140
chain_type = MyChain)
139
141
140
- @test all (((x, y),) -> x. as == y. as && x. bs == y. bs, zip (chains, chains2))
142
+ @test all (c1. as[i] === c2. as[i] for (c1, c2) in zip (chains, chains2), i in 1 : N)
143
+ @test all (c1. bs[i] === c2. bs[i] for (c1, c2) in zip (chains, chains2), i in 1 : N)
141
144
142
145
# Unexpected order of arguments.
143
146
str = " Number of chains (10) is greater than number of samples per chain (5)"
@@ -173,27 +176,30 @@ include("interface.jl")
173
176
include (" interface.jl" )
174
177
end
175
178
179
+ N = 10_000
176
180
Random. seed! (1234 )
177
- chains = sample (MyModel (), MySampler (), MCMCDistributed (), 10_000 , 1000 ;
181
+ chains = sample (MyModel (), MySampler (), MCMCDistributed (), N , 1000 ;
178
182
chain_type = MyChain)
179
183
180
184
# Test output type and size.
181
- @test chains isa Vector{MyChain}
185
+ @test chains isa Vector{<: MyChain }
186
+ @test all (c. as[1 ] === missing for c in chains)
182
187
@test length (chains) == 1000
183
- @test all (x -> length (x. as) == length (x. bs) == 10_000 , chains)
188
+ @test all (x -> length (x. as) == length (x. bs) == N , chains)
184
189
185
190
# Test some statistical properties.
186
- @test all (x -> isapprox (mean (x. as), 0.5 ; atol= 1e-2 ), chains)
187
- @test all (x -> isapprox (var (x. as), 1 / 12 ; atol= 5e-3 ), chains)
188
- @test all (x -> isapprox (mean (x. bs), 0 ; atol= 5e-2 ), chains)
189
- @test all (x -> isapprox (var (x. bs), 1 ; atol= 5e-2 ), chains)
191
+ @test all (x -> isapprox (mean (@view x. as[ 2 : end ] ), 0.5 ; atol= 1e-2 ), chains)
192
+ @test all (x -> isapprox (var (@view x. as[ 2 : end ] ), 1 / 12 ; atol= 5e-3 ), chains)
193
+ @test all (x -> isapprox (mean (@view x. bs[ 2 : end ] ), 0 ; atol= 5e-2 ), chains)
194
+ @test all (x -> isapprox (var (@view x. bs[ 2 : end ] ), 1 ; atol= 5e-2 ), chains)
190
195
191
196
# Test reproducibility.
192
197
Random. seed! (1234 )
193
- chains2 = sample (MyModel (), MySampler (), MCMCDistributed (), 10_000 , 1000 ;
198
+ chains2 = sample (MyModel (), MySampler (), MCMCDistributed (), N , 1000 ;
194
199
chain_type = MyChain)
195
200
196
- @test all (((x, y),) -> x. as == y. as && x. bs == y. bs, zip (chains, chains2))
201
+ @test all (c1. as[i] === c2. as[i] for (c1, c2) in zip (chains, chains2), i in 1 : N)
202
+ @test all (c1. bs[i] === c2. bs[i] for (c1, c2) in zip (chains, chains2), i in 1 : N)
197
203
198
204
# Unexpected order of arguments.
199
205
str = " Number of chains (10) is greater than number of samples per chain (5)"
@@ -213,7 +219,7 @@ include("interface.jl")
213
219
chain1 = sample (MyModel (), MySampler (), 100 ; sleepy = true )
214
220
chain2 = sample (MyModel (), MySampler (), 100 ; sleepy = true , chain_type = MyChain)
215
221
216
- @test chain1 isa Vector{MyTransition}
222
+ @test chain1 isa Vector{<: MyTransition }
217
223
@test chain2 isa MyChain
218
224
end
219
225
@@ -229,10 +235,15 @@ include("interface.jl")
229
235
break
230
236
end
231
237
238
+ # don't save missing values
239
+ t. a === missing && continue
240
+
232
241
push! (as, t. a)
233
242
push! (bs, t. b)
234
243
end
235
244
245
+ @test length (as) == length (bs) == 998
246
+
236
247
@test mean (as) ≈ 0.5 atol= 1e-2
237
248
@test var (as) ≈ 1 / 12 atol= 5e-3
238
249
@test mean (bs) ≈ 0.0 atol= 5e-2
0 commit comments