-
Notifications
You must be signed in to change notification settings - Fork 3
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
Issue 307: MvNormal removal and tuning #369
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #369 +/- ##
==========================================
+ Coverage 93.07% 93.10% +0.02%
==========================================
Files 50 51 +1
Lines 520 522 +2
==========================================
+ Hits 484 486 +2
Misses 36 36 ☔ View full report in Codecov by Sentry. |
I've added a custom context ( This is very close to working but I am slightly stuck on a type conversion issue (somewhere it sees Note: I spent a rather depressing amount of time wondering through the Turing issues from 2020 here and have started to really wish that Test code: using EpiAware, Turing, Distributions
idd = IDD(Normal(0, 1))
idd_model = generate_latent(idd, 10)
samples = sample(idd_model, Prior(), 1000)
preds_turing = Turing.predict(generate_latent(idd, 20), samples)
preds = EpiAware.EpiAwareUtils.predict(generate_latent(idd, 20), samples)
[ Info: Getting types
[ Info: Predicting
[ Info: DynamicPPL.TypedVarInfo{@NamedTuple{ϵ_t::DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:ϵ_t, Accessors.IndexLens{Tuple{Int64}}}, Int64}, Vector{Normal{Float64}}, Vector{AbstractPPL.VarName{:ϵ_t, Accessors.IndexLens{Tuple{Int64}}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}}, Float64}((ϵ_t = DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:ϵ_t, Accessors.IndexLens{Tuple{Int64}}}, Int64}, Vector{Normal{Float64}}, Vector{AbstractPPL.VarName{:ϵ_t, Accessors.IndexLens{Tuple{Int64}}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}(Dict{AbstractPPL.VarName{:ϵ_t, Accessors.IndexLens{Tuple{Int64}}}, Int64}(ϵ_t[9] => 9, ϵ_t[4] => 4, ϵ_t[6] => 6, ϵ_t[3] => 3, ϵ_t[17] => 17, ϵ_t[18] => 18, ϵ_t[19] => 19, ϵ_t[5] => 5, ϵ_t[11] => 11, ϵ_t[10] => 10, ϵ_t[13] => 13, ϵ_t[8] => 8, ϵ_t[2] => 2, ϵ_t[20] => 20, ϵ_t[1] => 1, ϵ_t[15] => 15, ϵ_t[16] => 16, ϵ_t[12] => 12, ϵ_t[7] => 7, ϵ_t[14] => 14), AbstractPPL.VarName{:ϵ_t, Accessors.IndexLens{Tuple{Int64}}}[ϵ_t[1], ϵ_t[2], ϵ_t[3], ϵ_t[4], ϵ_t[5], ϵ_t[6], ϵ_t[7], ϵ_t[8], ϵ_t[9], ϵ_t[10], ϵ_t[11], ϵ_t[12], ϵ_t[13], ϵ_t[14], ϵ_t[15], ϵ_t[16], ϵ_t[17], ϵ_t[18], ϵ_t[19], ϵ_t[20]], UnitRange{Int64}[1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:10, 11:11, 12:12, 13:13, 14:14, 15:15, 16:16, 17:17, 18:18, 19:19, 20:20], [-0.7082101677945046, 0.5491115966525051, 2.3842630466986257, -2.1310827823622476, 1.4589684465556265, 1.128274758194063, -0.9437569622288362, 0.0670683933861612, -0.6281275543289423, 0.40844270897271584, 0.4500941947995636, -0.02053489398433327, -0.9654168977655161, 0.8234408488431235, -1.9024840086670902, -0.07285840907253294, -0.08607929613724663, 1.2735247017938127, 0.6520883239494453, 0.796122359493298], Normal{Float64}[Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0), Normal{Float64}(μ=0.0, σ=1.0)], Set{DynamicPPL.Selector}[Set(), Set(), Set(), Set(), Set(), Set(), Set(), Set(), Set(), Set(), Set(), Set(), Set(), Set(), Set(), Set(), Set(), Set(), Set(), Set()], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], Dict{String, BitVector}("del" => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "trans" => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])),), Base.RefValue{Float64}(-30.385569079389658), Base.RefValue{Int64}(0))
[ Info: 1
[ Info: 1
[ Info: Reseting value
ERROR: MethodError: no method matching subsumes(::Accessors.IndexLens{Tuple{Int64}}, ::ComposedFunction{Accessors.IndexLens{Tuple{Int64}}, typeof(identity)})
Closest candidates are:
subsumes(::typeof(identity), ::Union{typeof(identity), Accessors.IndexLens, Accessors.PropertyLens, ComposedFunction})
@ AbstractPPL ~/.julia/packages/AbstractPPL/kb4q5/src/varname.jl:296
subsumes(::Union{typeof(identity), Accessors.IndexLens, Accessors.PropertyLens, ComposedFunction}, ::typeof(identity))
@ AbstractPPL ~/.julia/packages/AbstractPPL/kb4q5/src/varname.jl:297
subsumes(::Accessors.PropertyLens, ::ComposedFunction)
@ AbstractPPL ~/.julia/packages/AbstractPPL/kb4q5/src/varname.jl:308
...
Stacktrace:
[1] subsumes(u::AbstractPPL.VarName{:ϵ_t, Accessors.IndexLens{…}}, v::AbstractPPL.VarName{:ϵ_t, ComposedFunction{…}})
@ AbstractPPL ~/.julia/packages/AbstractPPL/kb4q5/src/varname.jl:287
[2] (::Base.Fix2{…})(y::AbstractPPL.VarName{…})
@ Base ./operators.jl:1135
[3] findnext
@ ./array.jl:2155 [inlined]
[4] findfirst
@ ./array.jl:2206 [inlined]
[5] _nested_setindex_maybe!
@ ~/.julia/packages/DynamicPPL/i2EbF/src/varinfo.jl:1398 [inlined]
[6] nested_setindex_maybe!(vi::DynamicPPL.TypedVarInfo{…}, val::Float64, vn::AbstractPPL.VarName{…})
@ DynamicPPL ~/.julia/packages/DynamicPPL/i2EbF/src/varinfo.jl:1384
[7] setval_and_resample!(vi::DynamicPPL.TypedVarInfo{…}, chains::Chains{…}, sample_idx::Int64, chain_idx::Int64)
@ DynamicPPL ~/.julia/packages/DynamicPPL/i2EbF/src/varinfo.jl:1952
[8] (::EpiAware.EpiAwareUtils.var"#32#33"{…})(::Tuple{…})
@ EpiAware.EpiAwareUtils ~/code/Rt-without-renewal/EpiAware/src/EpiAwareUtils/predict.jl:201
[9] iterate
@ ./generator.jl:47 [inlined]
[10] collect(itr::Base.Generator{Base.Iterators.ProductIterator{…}, EpiAware.EpiAwareUtils.var"#32#33"{…}})
@ Base ./array.jl:834
[11] map(f::Function, A::Base.Iterators.ProductIterator{Tuple{UnitRange{Int64}, UnitRange{Int64}}})
@ Base ./abstractarray.jl:3313
[12] transitions_from_chain(rng::Random.TaskLocalRNG, model::DynamicPPL.Model{…}, chain::Chains{…}; sampler::DynamicPPL.SampleFromPrior, context::PredictContext{…})
@ EpiAware.EpiAwareUtils ~/code/Rt-without-renewal/EpiAware/src/EpiAwareUtils/predict.jl:196
[13] predict(rng::Random.TaskLocalRNG, model::DynamicPPL.Model{…}, chain::Chains{…}; include_all::Bool)
@ EpiAware.EpiAwareUtils ~/code/Rt-without-renewal/EpiAware/src/EpiAwareUtils/predict.jl:104
[14] predict
@ ~/code/Rt-without-renewal/EpiAware/src/EpiAwareUtils/predict.jl:96 [inlined]
[15] #predict#24
@ ~/code/Rt-without-renewal/EpiAware/src/EpiAwareUtils/predict.jl:94 [inlined]
[16] predict(model::DynamicPPL.Model{…}, chain::Chains{…})
@ EpiAware.EpiAwareUtils ~/code/Rt-without-renewal/EpiAware/src/EpiAwareUtils/predict.jl:93
[17] top-level scope
@ ~/code/Rt-without-renewal/EpiAware/src/EpiLatentModels/models/test.jl:9
Some type information was truncated. Use `show(err)` to see complete types. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I've localised the problem to |
Any insights @SamuelBrand1 ? |
Agreed. I'm looking at this, it seems odd to me that this doesn't work. |
Plan for this PR is to pull out the predict changes into their own PR and then review/merge this and deal with the predict issues there. |
Ongoing review: I like using We should note that as default |
73ceaa5
to
13e905d
Compare
I have pulled the changes to predict into their own PR and this is now ready to review. I guess once this is merged we need some issues to remove scan (those are probably tied into improving the infection models). |
It would be nice to wait for benchmarks (and we can see if #381 helps first) but I think we should aim to merge this ASAP and fix in post. I think its very unlikely any changes here reduce performance (we can check this in detail when looking to swap out scan). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I was happy with this side of the PR and remain so.
This PR closes #307 by moving to using
filldist
vsMvNormal
.It also:
AR
process via tooling foraccumulate_scan
.accumulate_scan
is a candidate to replacescan
everywhere with this being done by rewritingEpiData
to be a step function with a callable. This would probably need to be connected to a rewrite of the infection modules to make step processes composable. When reviewing please think if this approach has limitations vs the currentscan
method (probably in the carry flexibility (though I note the expectation here is that more complex methods would need to redefine their inits.This PR also serves as another test of the benchmarks to try and isolate the failure in #358.