-
Notifications
You must be signed in to change notification settings - Fork 230
Closed
Labels
Description
I'm trying to understand how to sample from the prior and how this contrasts to sampling from a "generative model'.
Do I interpret the example from the documentation correctly?
# define joint distribution p(s, m, x, y)
@model gdemo(x, y) = begin
s ~ InverseGamma(2,3)
m ~ Normal(0,sqrt(s))
x ~ Normal(m, sqrt(s))
y ~ Normal(m, sqrt(s))
return x, y
end
# this samples from p(x,y)
g_prior_sampler = gdemo()
g_prior_sampler()
# this samples p(x|y=-3.4)
c = sample(gdemo(missing, -3.4), NUTS(5000, 0.65))Based on this I played around with the second example:
# define p(s, m, [x_1, ..., x_n])
@model gdemo2(x) = begin
s ~ InverseGamma(2,3)
m ~ Normal(0, sqrt(s))
for i in eachindex(x)
x[i] ~ Normal(m, sqrt(s))
end
return x
end
# sample from p(s, m, x)
g_prior_sampler2 = gdemo2()
g_prior_sampler2() # -> ERROR: MethodError: no methods matching keys(::Symbol)
# I guess the error is because the length of x in not defined.
# However passing the length as extra parameter does not resolve this.
# sample from p(s, m, [x_1, x_2, x_3]) (that's also sampling from the prior)
c = sample(gdemo2([missing, missing, missing]), NUTS(5000, 0.65))
# -> works :)
# sample from p(s, m, [x_1, x_2] | x_3=2.2)
c = sample(gdemo2([missing, missing, 2.2]), NUTS(5000, 0.65))
# -> ERROR: MethodError: no methods matching (::Colon)(::Int64, ::Base.OneTo{Int64})The last case would be very useful in applications with missing data.
(probably related to #446.)