-
Notifications
You must be signed in to change notification settings - Fork 31
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
FixedContext and ConditionedContext don't use the same varnames as tilde-pipeline #702
Comments
Bisects to #555, specifically the direct change made to |
It seems that this error arises because here DynamicPPL.jl/ext/DynamicPPLMCMCChainsExt.jl Line 120 in 18af48a
we have that Dict(varname_pairs) = Dict{VarName, Float64}(m[1] => 0.02111050094889288, s => -1.8086057102168398) As can be seen, the However, when the fixed model is evaluated, it calls Lines 434 to 435 in 18af48a
and thus Line 523 in 18af48a
It seems that the call to DynamicPPL.jl/ext/DynamicPPLMCMCChainsExt.jl Lines 140 to 147 in 18af48a
Unfortunately, it doesn't :( In Lines 1608 to 1616 in 18af48a
and so the inner function Lines 1617 to 1627 in 18af48a
|
I remember finding the I would consider this a bug of julia> using Distributions
julia> using DynamicPPL
julia> @model function f()
m = Vector{Float64}(undef, 1)
m .~ Normal()
s ~ Normal()
return (; s=s, m=m)
end
f (generic function with 2 methods)
julia> model = f()
Model{typeof(f), (), (), (), Tuple{}, Tuple{}, DefaultContext}(f, NamedTuple(), NamedTuple(), DefaultContext())
julia> fix(model, (@varname(m[1]) => 0.1))()
(s = 0.07793110036823493, m = [0.8732131942573598]) |
Maybe |
julia> condition(model, (@varname(s) => 1, @varname(m[1]) => 0.1))()
(s = 1, m = [0.199933954170371])
julia> condition(model, (@varname(s) => 1, @varname(m[1]) => 0.1))()
(s = 1, m = [1.5566785471447055]) |
Ooooo nice catch 👍 We might need a call to |
@torfjelde, is there a reason why we use |
My comment was a bit out-of-sync as I was sending it while traveling.
AFAIK this isn't an issue with
It's two-fold:
|
However, this will have performance implications, unfortunately 😕 Looking at the following lines Lines 490 to 514 in 18af48a
the Lines 517 to 533 in 18af48a
which, as we see, calls Now, to fix the aforementioned issue, we could make the However, this would potentially result in these checks becoming run-time instead of compile-time 😬 |
generated_quantities
resamples variables which are dot_assumed
Semi-related but there's also this behaviour: julia> using Distributions, DynamicPPL, Test
julia> @model function f()
m = Vector{Float64}(undef, 2)
m .~ Normal()
s ~ Normal()
return (; s=s, m=m)
end
f (generic function with 2 methods)
julia> fix(model, (@varname(m) => [0.1]))()
(s = -0.2513270918863368, m = [0.1, 0.1]) IMO this should error. |
@torfjelde I have been looking at this a little bit, and I don't entirely understand what you mean with @model function f()
m = Vector{Float64}(undef, 2)
m .~ Normal()
s ~ Normal()
return (; s=s, m=m)
end
# The following should return (s = (something), m = [0.1, (something else)])
fix(f(), (@varname(m[1]) => 0.1))() In such a case, _, _, $vns = $(DynamicPPL.unwrap_right_left_vns)($right, $left, $vn)
for $v in $vns
if $(DynamicPPL.isfixed)($left, $v)
# we don't actually want $left here, we want only the bit of $left that corresponds to $v
# (but I don't know how to do that)
$left = $(DynamicPPL.getfixed_nested)(__context__, $v)
else
# normal tilde pipeline, which is where `m[2]` should go to
end
end I believe this would miss the opposite case where we actually fix the whole array, though: fix(f(), (@varname(m) => [0.1, 0.2]))() because now It seems to me that we can use Maybe I'm approaching this the wrong way? This is the first time I'm digging into the compiler, after all. Let me know 😄 I would have thought that the simplest solution would be to overload the tilde pipeline for |
I don't actually mind this not erroring since it's just following the
Though I agree it would be nice to support this in general, it'll be something of an hassle to support and I'm somewhat skeptical it's worth the maintanence burden.
If we do that, then there's no point in having the
As I mentioned above, this is technically possible and might be the way to go. However, it does mean that we don't have a "nice" distinction anymore that |
Also, worth pointing out that this issue was introduced in #555 . Specifically, the change in the |
One thing we could do is to overload the the tilde-pipeline for I don't like the inconsistency that something like this introudces, but it might be worth it. |
#710 inspects all of this a bit further with a possible way to address this issue. |
The call to
generated_quantities
always returns the values ofs
in the chain, as expected, but each timegenerated_quantities
is run, a new vectorm
is generated.The text was updated successfully, but these errors were encountered: