-
Notifications
You must be signed in to change notification settings - Fork 33
Conditioning on submodel variables #857
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
Comments
this is illustrative using DynamicPPL, Distributions
@model function f()
@show "inner, $(__context__)"
x ~ Normal()
y ~ Normal()
return (x, y)
end
@model function g()
@show "outer, $(__context__)"
a ~ to_submodel(f() | (@varname(x) => 1))
end
model = g()
julia> model()
"outer, $(__context__)" = "outer, SamplingContext{SampleFromPrior, DefaultContext, Random.TaskLocalRNG}(Random.TaskLocalRNG(), SampleFromPrior(), DefaultContext())"
"inner, $(__context__)" = "inner, PrefixContext{:a, SamplingContext{SampleFromPrior, ConditionContext{Dict{VarName{:x, typeof(identity)}, Int64}, DefaultContext}, Random.TaskLocalRNG}}(SamplingContext{SampleFromPrior, ConditionContext{Dict{VarName{:x, typeof(identity)}, Int64}, DefaultContext}, Random.TaskLocalRNG}(Random.TaskLocalRNG(), SampleFromPrior(), ConditionContext(Dict(x => 1), DefaultContext())))"
(-0.6695328944144235, 0.1774662210135376) The simplest solution might be to make DynamicPPL.jl/src/context_implementations.jl Lines 106 to 113 in 0810e14
basically here we need to dig into |
* Release 0.36 * AbstractPPL 0.11 + change prefixing behaviour (#830) * AbstractPPL 0.11; change prefixing behaviour * Use DynamicPPL.prefix rather than overloading * Remove VarInfo(VarInfo, params) (#870) * Unify `{untyped,typed}_{vector_,}varinfo` constructor functions (#879) * Unify {Untyped,Typed}{Vector,}VarInfo constructors * Update invocations * NTVarInfo * Fix tests * More fixes * Fixes * Fixes * Fixes * Use lowercase functions, don't deprecate VarInfo * Rewrite VarInfo docstring * Fix methods * Fix methods (really) * Link varinfo by default in AD testing utilities; make test suite run on linked varinfos (#890) * Link VarInfo by default * Tweak interface * Fix tests * Fix interface so that callers can inspect results * Document * Fix tests * Fix changelog * Test linked varinfos Closes #891 * Fix docstring + use AbstractFloat * Fix `condition` and `fix` in submodels (#892) * Fix conditioning in submodels * Simplify contextual_isassumption * Add documentation * Fix some tests * Add tests; fix a bunch of nested submodel issues * Fix fix as well * Fix doctests * Add unit tests for new functions * Add changelog entry * Update changelog Co-authored-by: Hong Ge <[email protected]> * Finish docs * Add a test for conditioning submodel via arguments * Clean new tests up a bit * Fix for VarNames with non-identity lenses * Apply suggestions from code review Co-authored-by: Markus Hauru <[email protected]> * Apply suggestions from code review * Make PrefixContext contain a varname rather than symbol (#896) --------- Co-authored-by: Hong Ge <[email protected]> Co-authored-by: Markus Hauru <[email protected]> --------- Co-authored-by: Markus Hauru <[email protected]> Co-authored-by: Hong Ge <[email protected]> Co-authored-by: Markus Hauru <[email protected]>
This behaviour with submodels is all very reasonable:
Now, let's say we wanted to condition
x
in the inner model. We can do that from the very outermost layer, by conditioning the modelg()
. When looked at from the outside, thex
in the inner model is actuallyvar"a.x"
, so that's what we need to use in the conditioning values. We see that this works perfectly:Now if we instead wanted to condition the submodel itself (rather than the outermost model), one should expect that we can do that without prefixing. However, it doesn't work:
To condition on the inner model, you still have to include the prefix:
This is quite counterintuitive and opens up things like this:
(Note that old
@submodel
had the same issue.)I didn't test
fix
; it might have the same problem.The text was updated successfully, but these errors were encountered: