-
Notifications
You must be signed in to change notification settings - Fork 36
Closed
Description
# Setup
using DynamicPPL
p1 = PrefixContext{:a}(DefaultContext())
p2 = PrefixContext{:a}(PrefixContext{:b}(DefaultContext()))
p3 = PrefixContext{:a}(SamplingContext(PrefixContext{:b}(DefaultContext())))
p4 = SamplingContext(PrefixContext{:a}(DefaultContext()))
julia> prefix(p1, @varname(x))
a.x
julia> prefix(p2, @varname(x))
b.a.x
julia> prefix(p3, @varname(x))
a.x
julia> prefix(p4, @varname(x))
ERROR: MethodError: no method matching prefix(::SamplingContext{SampleFromPrior, PrefixContext{…}, Random.TaskLocalRNG}, ::VarName{:x, typeof(identity)})
The function `prefix` exists, but no method is defined for this combination of argument types.
Several points:
-
prefix(p1, @varname(x))
is all good. -
It seems to me that it would be more natural for
prefix(p2, @varname(x))
to returna.b.x
as right now this means that nested submodels have the prefixing occurring in the less intuitive way:
using DynamicPPL, Distributions
@model function subsubmodel()
x ~ Normal(0,1)
end
@model function submodel()
x ~ to_submodel(prefix(subsubmodel(), :c), false)
return x
end
@model function parentmodel()
x1 ~ to_submodel(prefix(submodel(), :a), false)
x2 ~ to_submodel(prefix(submodel(), :b), false)
end
keys(VarInfo(parentmodel()))
# 2-element Vector{VarName{sym, typeof(identity)} where sym}:
# c.a.x
# c.b.x
-
The intuitive behaviour for
prefix(p3, @varname(x))
would be to prefix with botha
andb
-
prefix(p4, @varname(x))
should traverse the context tree accordingly. This is related to to_submodel does not correctly handle manually specified prefixes when sampling #785, where the underlying problem is that the model is being evaluated with aDebugContext(SamplingContext(PrefixContext...)))
but the varnames aren't prefixed.
Metadata
Metadata
Assignees
Labels
No labels