You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently if one calls `DynamicPPL._setval!(vi, vi.metadata, values, keys)` , then only those values present in `keys` will be set, as expected, but the variables which are _not_ present in `keys` will simply be left as-is. This means that we get the following behavior:
``` julia
julia> using Turing
julia> @model function demo(x)
m ~ Normal(0, 1)
for i in eachindex(x)
x[i] ~ Normal(m, 1)
end
end
demo (generic function with 1 method)
julia> m_missing = demo(fill(missing, 2));
julia> var_info_missing = DynamicPPL.VarInfo(m_missing);
julia> var_info_missing.metadata.m.vals
1-element Array{Float64,1}:
0.7251417347423874
julia> var_info_missing.metadata.x.vals
2-element Array{Float64,1}:
1.2576791054418153
0.764913349211408
julia> var_info_missing.metadata.m.vals # ✓ new value
1-element Array{Float64,1}:
0.0
julia> var_info_missing.metadata.x.vals # ✓ still the same value
2-element Array{Float64,1}:
1.2576791054418153
0.764913349211408
julia> m_missing(var_info_missing) # Re-run the model with new value for `m`
julia> var_info_missing.metadata.x.vals # × still the same and thus not reflecting the change in `m`!
2-element Array{Float64,1}:
1.2576791054418153
0.764913349211408
```
_Personally_ I expected `x` to be resampled since now parts of the model has changed and thus the sample `x` is no longer representative of a sample from the model (under the sampler used).
This PR "fixes" the above so that you get the following behavior:
``` julia
julia> var_info_missing.metadata.x.vals
2-element Array{Float64,1}:
1.2576791054418153
0.764913349211408
julia> DynamicPPL.setval!(var_info_missing, (m = 0.0, ));
julia> var_info_missing.metadata.x.vals
2-element Array{Float64,1}:
1.2576791054418153
0.764913349211408
julia> m_missing(var_info_missing)
julia> var_info_missing.metadata.x.vals
2-element Array{Float64,1}:
-2.0493130638394947
0.3881955730968598
```
This was discoverd when debugging TuringLang/Turing.jl#1352 as I want to move `Turing.predict` over to using `DynamicPPL.setval!` and it also has consequences for `DynamicPPL.generated_quantities` which uses `DynamicPPL.setval!` under the hood and thus suffer from the same issue.
There's an alternative: instead of making this the default-behavior, we could add `kwargs...` to `setval!` which includes `resample_missing::Bool` or something. I'm also completely fine with a solution like that 👍
0 commit comments