Hi,
This is my first post, so I will try to make it as clear as possible, otherwise point out anything that is unclear.
I am running into an issue with querying probabilities using chains. I tried to reduce it to as small of a problem as possible which has led me to believe it might be a bug/not the intended behavior. Either that, or I am missing something else.
In the code I pasted below, the first 3 results (result1, result2, and result3) all print different values whenever they are rerun as individual cells, even though I would expect them to stay the same since the chain doesnât change.
Afterwards, trying the joint probabilities of x and y, they do stay consistent when rerunning the cell (as one might expect).
So the question:
- Am I doing something wrong here or might this be a bug?
The code below can also be found as a Pluto.jl notebook on github: https://github.com/mgmverburg/Turing_examples/blob/master/potential_query_bug.jl
using Turing, Distributions
@model function gdemo(x, y)
if x === missing || x === nothing
# Initialize `x` if missing
x = Vector{Float64}(undef, 2)
end
n = length(x)
s ~ InverseGamma(2, 3)
m ~ Normal(0, sqrt(s))
x ~ filldist(Normal(m, sqrt(s)), n)
for i in 1:length(y)
y[i] ~ Normal(x[i], sqrt(s))
end
end
model_gdemo = gdemo([1.0, 0.0], [1.5, 0.0])
c2 = sample(model_gdemo, NUTS(0.65), 100)
result1 = prob"y = [1.5] | chain=c2, model = model_gdemo, x = [1.0]"
println(mean(result1))
result2 = prob"y = [1.5] | chain=c2, model = model_gdemo, x = [0.0]"
println(mean(result2))
result3 = prob"y = [1.5] | chain=c2, model = model_gdemo, x = nothing"
println(mean(result3))
result4 = prob"y = [1.5], x = [1.0] | chain=c2, model = model_gdemo"
println(mean(result4))
result5 = prob"y = [1.5], x = [0.0] | chain=c2, model = model_gdemo"
println(mean(result5))
Thanks in advance!