|
207 | 207 | val ~ Normal(s, 1) |
208 | 208 | 1.0 ~ Normal(s + m, 1) |
209 | 209 |
|
210 | | - n := m + 1 |
211 | | - xs = M(undef, n) |
| 210 | + n := m |
| 211 | + xs = M(undef, 5) |
212 | 212 | for i in eachindex(xs) |
213 | 213 | xs[i] ~ Beta(0.5, 0.5) |
214 | 214 | end |
|
565 | 565 | end |
566 | 566 | end |
567 | 567 |
|
568 | | - # The below test used to sample incorrectly before |
569 | | - # https://github.com/TuringLang/Turing.jl/pull/2328 |
570 | | - @testset "dynamic model with ESS" begin |
571 | | - @model function dynamic_model_for_ess() |
572 | | - b ~ Bernoulli() |
573 | | - x_length = b ? 1 : 2 |
574 | | - x = Vector{Float64}(undef, x_length) |
575 | | - for i in 1:x_length |
576 | | - x[i] ~ Normal(i, 1.0) |
577 | | - end |
578 | | - end |
579 | | - |
580 | | - m = dynamic_model_for_ess() |
581 | | - chain = sample(m, Gibbs(:b => PG(10), :x => ESS()), 2000; discard_initial=100) |
582 | | - means = Dict(:b => 0.5, "x[1]" => 1.0, "x[2]" => 2.0) |
583 | | - stds = Dict(:b => 0.5, "x[1]" => 1.0, "x[2]" => 1.0) |
584 | | - for vn in keys(means) |
585 | | - @test isapprox(mean(skipmissing(chain[:, vn, 1])), means[vn]; atol=0.1) |
586 | | - @test isapprox(std(skipmissing(chain[:, vn, 1])), stds[vn]; atol=0.1) |
587 | | - end |
588 | | - end |
589 | | - |
590 | | - @testset "dynamic model with dot tilde" begin |
591 | | - @model function dynamic_model_with_dot_tilde( |
592 | | - num_zs=10, (::Type{M})=Vector{Float64} |
593 | | - ) where {M} |
594 | | - z = Vector{Int}(undef, num_zs) |
595 | | - z .~ Poisson(1.0) |
596 | | - num_ms = sum(z) |
597 | | - m = M(undef, num_ms) |
598 | | - return m .~ Normal(1.0, 1.0) |
599 | | - end |
600 | | - model = dynamic_model_with_dot_tilde() |
601 | | - sample(model, Gibbs(:z => PG(10), :m => HMC(0.01, 4)), 100) |
602 | | - end |
603 | | - |
604 | 568 | @testset "Demo model" begin |
605 | 569 | @testset verbose = true "$(model.f)" for model in DynamicPPL.TestUtils.DEMO_MODELS |
606 | 570 | vns = DynamicPPL.TestUtils.varnames(model) |
|
0 commit comments