return statement in the model definition #1720
-
Hello! I’m trying out Turing and I’m slightly confused about the return statement in the models: @model function gdemo(x, y)
s² ~ InverseGamma(2, 3)
m ~ Normal(0, sqrt(s²))
x ~ Normal(m, sqrt(s²))
y ~ Normal(m, sqrt(s²))
return x, y
end From the docs it seems that the return statement is only useful if you want to draw samples from the prior distribution. Is that the only use for it? So if I want to sample from the posterior, adding the return statement (or not including it) won’t make a difference? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
So the return-statement in Turing.jl just like a standard return-statement in a function. This means that if you do One useful case you might want to check out is the docstring of EDIT: |
Beta Was this translation helpful? Give feedback.
So the return-statement in Turing.jl just like a standard return-statement in a function. This means that if you do
m = gdemo(...); m()
you will get the return values, whatever they might be. The return-statement has nothing to do with the sampling/inference (unless it we hit a "early"return
), hence if you just want to sample from the posterior you don't need it.One useful case you might want to check out is the docstring of
Turing.generated_quantities
. There you'll find an example of how we can exploit the return-statement to do something useful even if you're only interested in posterior inference:)EDIT:
generated_quantites
is "kind of" new and so we haven't documented it properly y…