Skip to content

Fix a Gibbs bug with models where linking changes variable dimension #2472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Turing"
uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
version = "0.36.1"
version = "0.36.2"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down Expand Up @@ -63,7 +63,7 @@ Distributions = "0.23.3, 0.24, 0.25"
DistributionsAD = "0.6"
DocStringExtensions = "0.8, 0.9"
DynamicHMC = "3.4"
DynamicPPL = "0.33, 0.34"
DynamicPPL = "0.34.1"
EllipticalSliceSampling = "0.5, 1, 2"
ForwardDiff = "0.10.3"
Libtask = "0.8.8"
Expand Down
20 changes: 20 additions & 0 deletions test/mcmc/gibbs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,26 @@ end
check_numerical(chain, [:m1, :m2], [-0.2, 0.6]; atol=0.1)
end
end

# Test a model that where the sampler needs to link a variable, which consequently
# changes dimension. This used to error because the initial value `VarInfo`,
# obtained from just `VarInfo(model)`, had a value of dimension 2 for `w`, and the one
# coming out of the initial step of the component sampler had a dimension of 1, since
# the latter was linked. `merge` of the varinfos couldn't handle that before DPPL
# 0.34.1.
@testset "linking changes dimension" begin
@model function dirichlet_model()
K = 2
w ~ Dirichlet(K, 1.0)
for i in 1:K
0.1 ~ Normal(w[i], 1.0)
end
end

model = dirichlet_model()
sampler = Gibbs(:w => HMC(0.05, 10))
@test (sample(model, sampler, 10); true)
end
end

end
Loading