Commit 5ba73f6f authored by Peter Jentsch's avatar Peter Jentsch
Browse files

abstract and some acknowledgements

parent 796cbf9f
......@@ -39,9 +39,9 @@ version = "0.1.0"
[[ArrayInterface]]
deps = ["IfElse", "LinearAlgebra", "Requires", "SparseArrays", "Static"]
git-tree-sha1 = "b09fe16aa9dc587cccce838e6cb6d6e1f4831d7f"
git-tree-sha1 = "af516010f3d8c690d2207b12445aaa45da63e9fb"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "3.1.12"
version = "3.1.14"
[[Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
......@@ -68,9 +68,9 @@ version = "0.1.1"
[[BenchmarkTools]]
deps = ["JSON", "Logging", "Printf", "Statistics", "UUIDs"]
git-tree-sha1 = "068fda9b756e41e6c75da7b771e6f89fa8a43d15"
git-tree-sha1 = "01ca3823217f474243cc2c8e6e1d1f45956fe872"
uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
version = "0.7.0"
version = "1.0.0"
[[Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
......@@ -80,9 +80,9 @@ version = "1.0.6+5"
[[CSV]]
deps = ["Dates", "Mmap", "Parsers", "PooledArrays", "SentinelArrays", "Tables", "Unicode"]
git-tree-sha1 = "6d4242ef4cb1539e7ede8e01a47a32365e0a34cd"
git-tree-sha1 = "b83aa3f513be680454437a0eee21001607e5d983"
uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
version = "0.8.4"
version = "0.8.5"
[[Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
......@@ -92,15 +92,15 @@ version = "1.16.0+6"
[[ChainRulesCore]]
deps = ["Compat", "LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "9b0375dc013ab0fc472b37cb8b18eed66b83f76b"
git-tree-sha1 = "b391f22252b8754f4440de1f37ece49d8a7314bb"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "0.9.43"
version = "0.9.44"
[[CheapThreads]]
deps = ["ArrayInterface", "IfElse", "Requires", "Static", "StrideArraysCore", "ThreadingUtilities", "VectorizationBase"]
git-tree-sha1 = "44899e10c2fd8a3c5b907c4b688c04f737d13959"
git-tree-sha1 = "97964dc5503a7c65b7d0f661965e297629f7b533"
uuid = "b630d9fa-e28e-4980-896d-83ce5e2106b2"
version = "0.2.4"
version = "0.2.5"
[[ColorSchemes]]
deps = ["ColorTypes", "Colors", "FixedPointNumbers", "Random", "StaticArrays"]
......@@ -128,9 +128,9 @@ version = "0.3.0"
[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "0900bc19193b8e672d9cd477e6cd92d9e7c02f99"
git-tree-sha1 = "e4e2b39db08f967cc1360951f01e8a75ec441cab"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.29.0"
version = "3.30.0"
[[CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
......@@ -269,9 +269,9 @@ version = "2.1.5+1"
[[Expat_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "1402e52fcda25064f51c77a9655ce8680b76acf0"
git-tree-sha1 = "b3bfd02e98aedfa5cf885665493c5598c350cd2f"
uuid = "2e619515-83b5-522b-bb60-26c02a35a201"
version = "2.2.7+6"
version = "2.2.10+0"
[[ExprTools]]
git-tree-sha1 = "10407a39b87f29d47ebaca8edbc75d7c302ff93e"
......@@ -391,16 +391,16 @@ uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
version = "0.3.12"
[[Gettext_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "8c14294a079216000a0bdca5ec5a447f073ddc9d"
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "9b02998aba7bf074d14de89f9d37ca24a1a0b046"
uuid = "78b55507-aeef-58d4-861c-77aaff3498b1"
version = "0.20.1+7"
version = "0.21.0+0"
[[Glib_jll]]
deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "04690cc5008b38ecbdfede949220bc7d9ba26397"
git-tree-sha1 = "47ce50b742921377301e15005c96e979574e130b"
uuid = "7746bdde-850d-59dc-9ae8-88ece973131d"
version = "2.59.0+4"
version = "2.68.1+0"
[[Grisu]]
git-tree-sha1 = "53bb909d1151e57e2484c3d1b53e19552b887fb2"
......@@ -546,9 +546,9 @@ version = "1.2.1"
[[LabelledArrays]]
deps = ["ArrayInterface", "LinearAlgebra", "MacroTools", "StaticArrays"]
git-tree-sha1 = "df09e970c816637191ef8794ef5c5c9f8950db88"
git-tree-sha1 = "248a199fa42ec62922225334131c9330e1dd72f6"
uuid = "2ee39098-c373-598a-b85f-a56591580800"
version = "1.6.0"
version = "1.6.1"
[[Latexify]]
deps = ["Formatting", "InteractiveUtils", "LaTeXStrings", "MacroTools", "Markdown", "Printf", "Requires"]
......@@ -599,9 +599,9 @@ uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
[[Libffi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "a2cd088a88c0d37eef7d209fd3d8712febce0d90"
git-tree-sha1 = "761a393aeccd6aa92ec3515e428c26bf99575b3b"
uuid = "e9f186c6-92d2-5b65-8a66-fee21dc1b490"
version = "3.2.1+4"
version = "3.2.2+0"
[[Libgcrypt_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgpg_error_jll", "Pkg"]
......@@ -623,15 +623,15 @@ version = "1.36.0+3"
[[Libiconv_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "8e924324b2e9275a51407a4e06deb3455b1e359f"
git-tree-sha1 = "8d22e127ea9a0917bc98ebd3755c8bd31989381e"
uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531"
version = "1.16.0+7"
version = "1.16.1+0"
[[Libmount_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "51ad0c01c94c1ce48d5cad629425035ad030bfd5"
git-tree-sha1 = "9c30530bf0effd46e15e0fdcf2b8636e78cbbd73"
uuid = "4b2f31a3-9ecc-558c-b454-b3730dcb73e9"
version = "2.34.0+3"
version = "2.35.0+0"
[[Libtiff_jll]]
deps = ["Artifacts", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Pkg", "Zlib_jll", "Zstd_jll"]
......@@ -641,9 +641,9 @@ version = "4.1.0+2"
[[Libuuid_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "f879ae9edbaa2c74c922e8b85bb83cc84ea1450b"
git-tree-sha1 = "7f3efec06033682db852f8b3bc3c1d2b0a0ab066"
uuid = "38a345b3-de98-5d2b-a5d3-14cd9215e700"
version = "2.34.0+7"
version = "2.36.0+0"
[[LightGraphs]]
deps = ["ArnoldiMethod", "DataStructures", "Distributed", "Inflate", "LinearAlgebra", "Random", "SharedArrays", "SimpleTraits", "SparseArrays", "Statistics"]
......@@ -663,9 +663,9 @@ version = "0.5.3"
[[LogExpFunctions]]
deps = ["DocStringExtensions", "LinearAlgebra"]
git-tree-sha1 = "ed26854d7c2c867d143f0e07c198fc9e8b721d10"
git-tree-sha1 = "1ba664552f1ef15325e68dc4c05c3ef8c2d5d885"
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
version = "0.2.3"
version = "0.2.4"
[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
......@@ -678,9 +678,9 @@ version = "0.4.6"
[[LoopVectorization]]
deps = ["ArrayInterface", "CheapThreads", "DocStringExtensions", "IfElse", "LinearAlgebra", "OffsetArrays", "Requires", "SLEEFPirates", "Static", "StrideArraysCore", "ThreadingUtilities", "UnPack", "VectorizationBase"]
git-tree-sha1 = "8fb5abd2ac992013fa14b110ca1308c83f8a4098"
git-tree-sha1 = "a999311dacfcd90775069316b2acd2dc26f50625"
uuid = "bdcacae8-1622-11e9-2a5c-532679323890"
version = "0.12.19"
version = "0.12.21"
[[LsqFit]]
deps = ["Distributions", "ForwardDiff", "LinearAlgebra", "NLSolversBase", "OptimBase", "Random", "StatsBase"]
......@@ -835,9 +835,9 @@ version = "1.4.1"
[[PCRE_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "1b556ad51dceefdbf30e86ffa8f528b73c7df2bb"
git-tree-sha1 = "b2a7af664e098055a7529ad1a900ded962bca488"
uuid = "2f80f16e-611a-54ab-bc61-aa92de5b98fc"
version = "8.42.0+4"
version = "8.44.0+0"
[[PDMats]]
deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse"]
......@@ -892,9 +892,9 @@ version = "1.0.10"
[[Plots]]
deps = ["Base64", "Contour", "Dates", "FFMPEG", "FixedPointNumbers", "GR", "GeometryBasics", "JSON", "Latexify", "LinearAlgebra", "Measures", "NaNMath", "PlotThemes", "PlotUtils", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "Requires", "Scratch", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs"]
git-tree-sha1 = "2628e5859819173cef995470af83db42bf411ef8"
git-tree-sha1 = "f3a57a5acc16a69c03539b3684354cbbbb72c9ad"
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
version = "1.14.0"
version = "1.15.2"
[[Polynomials]]
deps = ["Intervals", "LinearAlgebra", "MutableArithmetics", "RecipesBase"]
......@@ -1081,9 +1081,9 @@ uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
[[SpecialFunctions]]
deps = ["ChainRulesCore", "LogExpFunctions", "OpenSpecFun_jll"]
git-tree-sha1 = "9146da51b38e9705b9f5ccfadc3ab10a482cae36"
git-tree-sha1 = "c467f25b6ec4167ea3a9a4351c66c2e1cba5da33"
uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
version = "1.4.0"
version = "1.4.1"
[[SplittablesBase]]
deps = ["Setfield", "Test"]
......@@ -1126,9 +1126,9 @@ version = "0.9.8"
[[StrideArraysCore]]
deps = ["ArrayInterface", "Requires", "ThreadingUtilities", "VectorizationBase"]
git-tree-sha1 = "72429259dd8bbab3ee6ac78e3967e5409460cfc1"
git-tree-sha1 = "e35f915af1cc51753978259b439bec82b88b84c1"
uuid = "7792a7ef-975c-4747-a70f-980b88e8d1da"
version = "0.1.9"
version = "0.1.10"
[[StructArrays]]
deps = ["Adapt", "DataAPI", "Tables"]
......@@ -1225,9 +1225,9 @@ uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
[[VectorizationBase]]
deps = ["ArrayInterface", "Hwloc", "IfElse", "Libdl", "LinearAlgebra", "Static"]
git-tree-sha1 = "24a5c54dab1907b0f2f086e5d15c65522c7e8ce1"
git-tree-sha1 = "ca88893ecfadf1f55e473c30a2eac8dd835da839"
uuid = "3d5dd08c-fd9d-11e8-17fa-ed2836048c2f"
version = "0.20.3"
version = "0.20.10"
[[VectorizedRNG]]
deps = ["Distributed", "Random", "UnPack", "VectorizationBase"]
......@@ -1262,9 +1262,9 @@ version = "0.5.3"
[[XML2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "afd2b541e8fd425cd3b7aa55932a257035ab4a70"
git-tree-sha1 = "1acf5bdf07aa0907e0a37d3718bb88d4b687b74a"
uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a"
version = "2.9.11+0"
version = "2.9.12+0"
[[XSLT_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Pkg", "XML2_jll"]
......@@ -1410,9 +1410,9 @@ uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
[[Zstd_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "2c1332c54931e83f8f94d310fa447fd743e8d600"
git-tree-sha1 = "cc4bf3fdde8b7e3e9fa0351bdeedba1cf3b7f6e6"
uuid = "3161d3a3-bdf6-5164-811a-617609db77b4"
version = "1.4.8+0"
version = "1.5.0+0"
[[ZygoteRules]]
deps = ["MacroTools"]
......
......@@ -4,10 +4,11 @@
Adjust the means of the distributions in `distribution_matrix` by `mean_shift_percentage`.
"""
function adjust_distributions_mean(distribution_matrix::AbstractArray{T},mean_shift_percentage) where T<:Distribution
return map(distribution_matrix) do dist
new_mean = mean(dist)*(1 + mean_shift_percentage)
return from_mean(typeof(dist), new_mean)
function adjust_distributions_mean!(distribution_matrix,mean_shift_percentage)
for i in eachindex(distribution_matrix)
dist = distribution_matrix[i]
new_mean = mean(dist) + mean_shift_percentage
distribution_matrix[i] = from_mean(typeof(dist), new_mean)
end
end
......
......@@ -27,6 +27,7 @@ function get_parameters()
immunization_delay = 14,
immunization_begin_day =60,
infection_introduction_day = 180,
O_distribution_shift = 0.0,
)
return params
end
......@@ -78,15 +79,23 @@ mutable struct ModelSolution{T,InfNet,SocNet,WSMixingDist,RestMixingDist}
ws_matrix_tuple::WSMixingDist
rest_matrix_tuple::RestMixingDist
immunization_countdown::Vector{Int}
function ModelSolution(sim_length,params::T,num_households) where T
@views function ModelSolution(sim_length,params::T,num_households) where T
demographics,base_network,index_vectors = generate_population(num_households)
nodes = length(demographics)
pop_sizes = length.(index_vectors)
map(workschool_mixing) do md
adjust_distributions_mean!(md[1:3,3],params.O_distribution_shift)
adjust_distributions_mean!(md[3,1:3],params.O_distribution_shift)
end
map(rest_mixing) do md
adjust_distributions_mean!( md[1:3,3],params.O_distribution_shift)
adjust_distributions_mean!( md[3,1:3],params.O_distribution_shift)
end
map_symmetrize(m_tuple) = map(md -> symmetrize_means(pop_sizes,md), m_tuple)
ws_matrix_tuple = map_symmetrize(workschool_mixing)
ws_matrix_tuple = map_symmetrize(workschool_mixing)
rest_matrix_tuple = map_symmetrize(rest_mixing)
is_app_user = app_users(demographics,params.app_user_fraction)
app_user_list = zeros(nodes)
app_user_index = findall(==(true),is_app_user)
......
......@@ -55,30 +55,93 @@ function fit_all_parameters(p_tuple)
ymo_vaccination_ts = output.daily_immunized_by_age
total_preinfection_vaccination = sum.(eachrow(ymo_vaccination_ts))
# return sum((normalize_by_pop(total_preinfection_vaccination .- target_ymo_vac)).^2)
# + sum(normalize_by_pop((total_postinf_vaccination .- target_ymo_vac)).^2)
# + sum(normalize_by_pop((final_size .- target_final_size)).^2)
display(final_size)
display( sum.(eachrow(ymo_vaccination_ts[:,1:end])))
display( length.(model.index_vectors))
return sum(normalize_by_pop((final_size .- target_final_size)).^2)
end
display(cost((0.0,0.0005,0.0005,1.0,-3.0,-3.0,-0.2,0.25,0.25,0.0)))
# out = smc(priors,cost; verbose = true, nparticles = 1000, parallel = true)#this one has better NaN handling
return NamedTuple{p_names}(ntuple(i -> out.P[i].particles,length(p_names)))
end
function fit_distribution_parameters(p_tuple)
p_names = (:ω,:β_y,:π_base_y,:π_base_m,:π_base_o,:α_y,:α_m,:α_o,:O_distribution_shift)
priors = Factored(
Uniform(0.0,0.01),
Uniform(0.0,0.5),
Uniform(-5.0,3.0),
Uniform(-5.0,3.0),
Uniform(-5.0,3.0),
TriangularDist(23.0, 44.0, 34.0),
TriangularDist(22.0, 54.0, 40.0),
TriangularDist(9.0, 59.0, 39.0),
Uniform(0.0,0.2),
)
#simulation begins in july
#60 days for opinion dynamics to stabilize, then immunization begins in september,
#infection introduced at beginning of december
sim_length = 300
p_tuple_adjust = merge(p_tuple,
(
sim_length = sim_length,
I_0_fraction = 0.005,
immunization_begin_day = 60,
infection_introduction_day = 180,
immunizing = true,
)
)
function cost(p)
p_mergedbeta = merge(p_tuple_adjust, (β_m = p[2],β_o = p[2], )) #assume one beta
output,model = solve_w_parameters(p_mergedbeta, p_names,p)
target_ymo_vac = ymo_vac .* sum(vaccination_data[1:end]) .* length.(model.index_vectors)
ymo_vaccination_ts = output.daily_immunized_by_age
normalize_by_pop(v) = v./length.(model.index_vectors)
total_postinf_vaccination = sum.(eachrow(ymo_vaccination_ts[:,180:end]))
final_size = sum.(eachrow(output.daily_unvac_cases_by_age))
target_final_size = ymo_attack_rate .* length.(model.index_vectors)
target_ymo_vac = ymo_vac .* sum(vaccination_data[1:4]) .* length.(model.index_vectors)
ymo_vaccination_ts = output.daily_immunized_by_age
total_preinfection_vaccination = sum.(eachrow(ymo_vaccination_ts))
return sum((normalize_by_pop(total_preinfection_vaccination .- target_ymo_vac)).^2)
+ sum(normalize_by_pop((total_postinf_vaccination .- target_ymo_vac)).^2)
+ sum(normalize_by_pop((final_size .- target_final_size)).^2)
# display(final_size)
# display( sum.(eachrow(ymo_vaccination_ts[:,1:end])))
# display( length.(model.index_vectors))
# return sum(normalize_by_pop((final_size .- target_final_size)).^2)
end
out = smc(priors,cost; verbose = true, nparticles = 1000, parallel = true)#this one has better NaN handling
# display(cost((0.0,0.0005,-3.0,-3.0,-0.2,0.25,0.25,0.0,0.1)))
#
out = smc(priors,cost; verbose = true, nparticles = 300, parallel = true)
return NamedTuple{p_names}(ntuple(i -> out.P[i].particles,length(p_names)))
end
function fit_parameters(default_parameters)
# pre_inf_behaviour_parameters_path =joinpath(PACKAGE_FOLDER,"abm_parameter_fits","pre_inf_behaviour_parameters.dat")
# post_inf_behaviour_parameters_path = joinpath(PACKAGE_FOLDER,"abm_parameter_fits","post_inf_behaviour_parameters.dat")
fit_all_parameters_path = joinpath(PACKAGE_FOLDER,"abm_parameter_fits","fit_all_parameters.dat")
fit_dist_parameters_path = joinpath(PACKAGE_FOLDER,"abm_parameter_fits","fit_dist_parameters.dat")
output = fit_all_parameters(default_parameters)
serialize(fit_all_parameters_path,output)
output = fit_distribution_parameters(default_parameters)
# serialize(fit_all_parameters_path,output)
fitted_parameter_tuple = deserialize(fit_all_parameters_path)
fitted_sol,avg_populations = plot_fitting_posteriors("post_inf_fitting",fitted_parameter_tuple,default_parameters)
# fitted_parameter_tuple = deserialize(fit_all_parameters_path)
# fitted_sol,avg_populations = plot_fitting_posteriors("post_inf_fitting",fitted_parameter_tuple,default_parameters)
final_vac = sum.(eachrow(mean.(fitted_sol.daily_immunized_by_age)))
final_size = sum.(eachrow(mean.(fitted_sol.daily_unvac_cases_by_age)))
display(final_vac./avg_populations)
display(final_size./avg_populations)
# final_vac = sum.(eachrow(mean.(fitted_sol.daily_immunized_by_age)))
# final_size = sum.(eachrow(mean.(fitted_sol.daily_unvac_cases_by_age)))
# display(final_vac./avg_populations)
# display(final_size./avg_populations)
return fitted_sol
end
......@@ -95,14 +158,14 @@ function plot_fitting_posteriors(fname,particles_tuple,parameters)
avg_populations .+= length.(sol.index_vectors)
fit!(stat_recorder,output_recorder)
end
avg_populations ./= 10
p = plot_model(nothing,[nothing],[stat_recorder],parameters.infection_introduction_day,parameters.immunization_begin_day)
savefig(p, "$fname.pdf")
plts = [plot() for i in 1:length(particles_tuple)]
for (plt,(k,v)) in zip(plts,pairs(particles_tuple))
hist = StatsBase.fit(Histogram,v; nbins = 30)
plot!(plt,hist;legend = false,xlabel = k)
plot!(plt,hist;legend = false,xlabel = k)
end
p = plot(plts...; size = (1400,800),bottommargin = 5Plots.mm)
savefig(p,"$(fname)_posteriors.pdf")
......
No preview for this file type
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment