Skip to content

Commit ce84fc8

Browse files
committed
Add a test that catches a bug in Gibbs
1 parent 24d5556 commit ce84fc8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/mcmc/gibbs.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,25 @@ end
759759
check_numerical(chain, [:m1, :m2], [-0.2, 0.6]; atol=0.1)
760760
end
761761
end
762+
763+
# Test a model that where the sampler needs to link a variable, which consequently
764+
# changes dimension. This used to error because the initial value `VarInfo`,
765+
# obtained from just `VarInfo(model)`, had a value of dimension 2 for `w`, and the one
766+
# coming out of the initial step of the component sampler had a dimension of 1, since it
767+
# the latter was linked. `merge` of the varinfos couldn't handle that.
768+
@testset "linking changes dimension" begin
769+
@model function dirichlet_model()
770+
K = 2
771+
w ~ Dirichlet(K, 1.0)
772+
for i in 1:K
773+
0.1 ~ Normal(w[i], 1.0)
774+
end
775+
end
776+
777+
model = dirichlet_model()
778+
sampler = Gibbs(:w => HMC(0.05, 10))
779+
@test (sample(model, sampler, 10); true)
780+
end
762781
end
763782

764783
end

0 commit comments

Comments
 (0)