Skip to content
Snippets Groups Projects
Commit a7519605 authored by Peter Jentsch's avatar Peter Jentsch
Browse files

add mixing check to tests, some new graphs

parent 2390d7e6
No related branches found
No related tags found
No related merge requests found
Showing
with 106 additions and 75 deletions
No preview for this file type
using CovidAlertVaccinationModel using CovidAlertVaccinationModel
using CovidAlertVaccinationModel:get_parameters
using OnlineStats using OnlineStats
using ThreadsX using ThreadsX
using Plots using Plots
const samples = 5 const samples = 10
##Univariate tests ##Univariate tests
const len = 4 #number of points to evaluate const len = 10 #number of points to evaluate
gr() gr()
const default_parameters = (
sim_length = 600,
num_households = 5000,
I_0_fraction = 0.005,
base_transmission_probability = 0.001,
recovery_rate = 1/7,
immunization_loss_prob = 0.0055, #mean time of 6 months
π_base = -4.0,
η = 0.0,
κ = 1.0,
ω = 0.001,
ρ = [0.0,0.0,0.0],
ω_en = 0.00,
ρ_en = [0.0,0.0,0.0],
γ = 0.0,
β = 5.0,
notification_parameter = 0.001,
vaccinator_prob = 0.2,
app_user_fraction = 0.4,
notification_threshold = 2,
immunizing = true,
immunization_delay = 14,
immunization_begin_delay = 50,
infection_introduction_delay = 100
)
#add beta #add beta
#run model without vaccination #run model without vaccination
#use derivative of log of no infections to calibrate p #use derivative of log of no infections to calibrate p
...@@ -42,31 +17,32 @@ const default_parameters = ( ...@@ -42,31 +17,32 @@ const default_parameters = (
# #
const univarate_test_list = ( const univarate_test_list = (
(:I_0_fraction, range(0.0, 0.05; length = len)), # (:I_0_fraction, range(0.0, 0.05; length = len)),
(:base_transmission_probability, range(0.0002, 0.002; length = len)), # (:base_transmission_probability, range(0.0002, 0.002; length = len)),
(:recovery_rate, range(0.1, 0.5; length = len)), # (:recovery_rate, range(0.1, 0.5; length = len)),
(:immunization_loss_prob, range(0.00, 0.05; length = len)), # (:immunization_loss_prob, range(0.00, 0.05; length = len)),
(:π_base, range(-4.5, -3.5; length = len)), # (:π_base, range(-4.5, -3.5; length = len)),
(:η, range(0.0, 0.01; length = len)), # (:η, range(0.0, 0.01; length = len)),
(:κ, range(0.5, 1.5; length = len)), # (:κ, range(0.5, 1.5; length = len)),
(:ω, range(0.0, 0.01; length = len)), # (:ω, range(0.0, 0.01; length = len)),
(:ω_en, range(0.0, 0.5; length = len)), # (:ω_en, range(0.0, 0.5; length = len)),
(:γ, range(0.0, 0.5; length = len)), # (:γ, range(0.0, 0.5; length = len)),
(:β, range(2, 30; length = len)), (:ξ, range(1, 15; length = len)),
(:notification_parameter, range(0.00, 0.05; length = len)), # (:notification_parameter, range(0.00, 0.05; length = len)),
(:app_user_fraction, range(0.05, 0.25; length = len)), # (:app_user_fraction, range(0.05, 0.25; length = len)),
(:notification_threshold, (1:len)), # (:notification_threshold, (1:len)),
(:immunization_delay, [7,10,14,20]), # (:immunization_delay, [7,10,14,20]),
) )
const univariate_path = "CovidAlertVaccinationModel/plots/univariate/" const univariate_path = "CovidAlertVaccinationModel/plots/univariate/"
function univarate_test(variable, variable_range) function univarate_test(variable, variable_range)
default_parameters = get_parameters()
parameter_range_list = [merge(default_parameters,NamedTuple{(variable,)}((value,))) for value in variable_range] parameter_range_list = [merge(default_parameters,NamedTuple{(variable,)}((value,))) for value in variable_range]
solve_fn(p) = mean_solve(samples, p,DebugRecorder) solve_fn(p) = mean_solve(samples, p,DebugRecorder)[1]
univariate_outlist = ThreadsX.map(solve_fn, parameter_range_list) univariate_outlist = ThreadsX.map(solve_fn, parameter_range_list)
p = plot_model(variable,parameter_range_list,univariate_outlist,default_parameters.infection_introduction_delay,default_parameters.immunization_begin_delay) p = plot_model(variable,parameter_range_list,univariate_outlist,default_parameters.infection_introduction_day,default_parameters.immunization_begin_day)
return p return p
end end
......
using CovidAlertVaccinationModel using CovidAlertVaccinationModel
using OnlineStats using OnlineStats
using Plots using Plots
const samples = 1 const samples = 10
const vaccination_data = [0.0,0.043,0.385,0.424,0.115,0.03,0.005] #by month starting in august const vaccination_data = [0.0,0.043,0.385,0.424,0.115,0.03,0.005] #by month starting in august
const ymo_vac = [0.255,0.278,0.602] const ymo_vac = [0.255,0.278,0.602]
...@@ -10,23 +10,27 @@ const ymo_attack_rate = [10.376,5.636,7.2]./100 ...@@ -10,23 +10,27 @@ const ymo_attack_rate = [10.376,5.636,7.2]./100
function solve_and_plot_parameters() function solve_and_plot_parameters()
p = CovidAlertVaccinationModel.get_parameters() p = CovidAlertVaccinationModel.get_parameters()
display(p)
out,avg_populations = mean_solve(samples, p,DebugRecorder) out,avg_populations = mean_solve(samples, p,DebugRecorder)
p = plot_model(nothing,[nothing],[out],p.infection_introduction_day,p.immunization_begin_day) p = plot_model(nothing,[nothing],[out],p.infection_introduction_day,p.immunization_begin_day)
ymo_vaccination_ts = mean.(out.daily_immunized_by_age) ymo_vaccination_ts = mean.(out.daily_immunized_by_age)
total_postinf_vaccination = sum.(eachrow(ymo_vaccination_ts[:,1180:end])) total_postinf_vaccination = sum.(eachrow(ymo_vaccination_ts[:,180:end]))
final_size = sum.(eachrow(mean.(out.daily_unvac_cases_by_age))) final_size = sum.(eachrow(mean.(out.daily_unvac_cases_by_age)))
total_preinf_vaccination = sum.(eachrow(ymo_vaccination_ts[:,1:1180])) total_preinf_vaccination = sum.(eachrow(ymo_vaccination_ts[:,1:180]))
target_final_size = ymo_attack_rate .*avg_populations target_final_size = ymo_attack_rate .*avg_populations
target_preinf_vac = ymo_vac .* sum(vaccination_data[1:4]) .* avg_populations target_preinf_vac = ymo_vac .* sum(vaccination_data[1:4]) .* avg_populations
target_postinf_vac = ymo_vac .* sum(vaccination_data[5:end]) .*avg_populations target_postinf_vac = ymo_vac .* sum(vaccination_data[5:end]) .*avg_populations
display((final_size,target_final_size)) println("obs final size: $final_size, target: $target_final_size")
display((total_preinf_vaccination,target_preinf_vac)) println("obs preinf vac: $total_preinf_vaccination, target: $target_preinf_vac")
display((total_postinf_vaccination,target_postinf_vac)) println("obs postinf vac: $total_postinf_vaccination,target: $target_postinf_vac")
display(sum.(eachrow(ymo_vaccination_ts)) ./avg_populations)
total_final_size = sum.(eachrow(mean.(out.daily_cases_by_age)))
println("vac + unvac cases proportion: $(total_final_size./avg_populations))")
display(sum.(eachrow(ymo_vaccination_ts)) ./avg_populations)
savefig(p,"timeseries.pdf") savefig(p,"timeseries.pdf")
return out return out
......
File added
File added
function get_parameters()#(0.0000,0.00048,0.0005,0.16,-1.30,-1.24,-0.8,0.35,0.35,0.35,0.2) function get_parameters()#(0.0000,0.00048,0.0005,0.16,-1.30,-1.24,-0.8,0.35,0.35,0.35,0.2)
params = ( params = (
sim_length = 500, sim_length = 400,
num_households = 5000, num_households = 5000,
I_0_fraction = 0.005, I_0_fraction = 0.005,
β_y = 0.00042, β_y = 0.00046,
β_m = 0.00042, β_m = 0.00044,
β_o = 0.1, β_o = 0.6,
α_y = 0.35, α_y = 0.4,
α_m = 0.35, α_m = 0.4,
α_o = 0.35, α_o = 0.4,
recovery_rate = 1/5, recovery_rate = 1/5,
π_base_y = -1.0, π_base_y = -1.30,
π_base_m = -1.0, π_base_m = -1.31,
π_base_o = -1.0, π_base_o = -0.95,
η = 0.0, η = 0.0,
κ = 0.0, κ = 0.0,
ω = 0.00, ω = 0.00,
...@@ -20,14 +20,13 @@ function get_parameters()#(0.0000,0.00048,0.0005,0.16,-1.30,-1.24,-0.8,0.35,0.35 ...@@ -20,14 +20,13 @@ function get_parameters()#(0.0000,0.00048,0.0005,0.16,-1.30,-1.24,-0.8,0.35,0.35
γ = 0.0, γ = 0.0,
ξ = 5.0, ξ = 5.0,
notification_parameter = 0.001, notification_parameter = 0.001,
vaccinator_prob = 0.2, vaccinator_prob = 0.6,
app_user_fraction = 0.0, app_user_fraction = 0.0,
notification_threshold = 20, notification_threshold = 20,
immunizing = true, immunizing = true,
immunization_delay = 14, immunization_delay = 14,
immunization_begin_day = 60, immunization_begin_day = 60,
infection_introduction_day = 180, infection_introduction_day = 180,
O_distribution_shift = 0.0,
) )
return params return params
end end
...@@ -86,14 +85,14 @@ mutable struct ModelSolution{T,InfNet,SocNet,WSMixingDist,RestMixingDist} ...@@ -86,14 +85,14 @@ mutable struct ModelSolution{T,InfNet,SocNet,WSMixingDist,RestMixingDist}
ws_mixing_tuple_preshift = deepcopy(workschool_mixing) ws_mixing_tuple_preshift = deepcopy(workschool_mixing)
rest_mixing_tuple_preshift = deepcopy(rest_mixing) rest_mixing_tuple_preshift = deepcopy(rest_mixing)
for md in ws_mixing_tuple_preshift # for md in ws_mixing_tuple_preshift
adjust_distributions_mean!(md[1:3,3],params.O_distribution_shift) # adjust_distributions_mean!(md[1:3,3],params.O_distribution_shift)
adjust_distributions_mean!(md[3,1:2],params.O_distribution_shift)#dont shift OO twice # adjust_distributions_mean!(md[3,1:2],params.O_distribution_shift)#dont shift OO twice
end # end
for md in rest_mixing_tuple_preshift # for md in rest_mixing_tuple_preshift
adjust_distributions_mean!( md[1:3,3],params.O_distribution_shift) # adjust_distributions_mean!( md[1:3,3],params.O_distribution_shift)
adjust_distributions_mean!( md[3,1:2],params.O_distribution_shift) #dont shift OO twice # adjust_distributions_mean!( md[3,1:2],params.O_distribution_shift) #dont shift OO twice
end # end
map_symmetrize(m_tuple) = map(md -> symmetrize_means(pop_sizes,md), m_tuple) map_symmetrize(m_tuple) = map(md -> symmetrize_means(pop_sizes,md), m_tuple)
ws_matrix_tuple = map_symmetrize(ws_mixing_tuple_preshift) ws_matrix_tuple = map_symmetrize(ws_mixing_tuple_preshift)
......
...@@ -157,5 +157,5 @@ function plot_model(varname,univariate_series, output_list::Vector{T},infection_ ...@@ -157,5 +157,5 @@ function plot_model(varname,univariate_series, output_list::Vector{T},infection_
vline!(p,[infection_begin]; label = "infection begin", line =:dot) vline!(p,[infection_begin]; label = "infection begin", line =:dot)
vline!(p,[vac_begin]; label = "vaccination begin",line = :dot) vline!(p,[vac_begin]; label = "vaccination begin",line = :dot)
end end
return plot(plts...;layout = (l,1),size=(800,400*l),leftmargin = 12Plots.mm) return plot(plts...;layout = (l,1),size=(800,400*l),leftmargin = 12Plots.mm, legend = :outerright)
end end
...@@ -106,7 +106,7 @@ Base.@propagate_inbounds @views function update_vaccination_opinion_state!(t,mod ...@@ -106,7 +106,7 @@ Base.@propagate_inbounds @views function update_vaccination_opinion_state!(t,mod
random_soc_network = sample(Random.default_rng(Threads.threadid()), soc_network.graph_list[t]) random_soc_network = sample(Random.default_rng(Threads.threadid()), soc_network.graph_list[t])
if !isempty(neighbors(random_soc_network,i)) if !isempty(neighbors(random_soc_network,i))
for _ = 1:10 for _ = 1:1
random_neighbour = sample(Random.default_rng(Threads.threadid()), neighbors(random_soc_network.g,i)) random_neighbour = sample(Random.default_rng(Threads.threadid()), neighbors(random_soc_network.g,i))
if u_vac[random_neighbour] == u_vac[i] if u_vac[random_neighbour] == u_vac[i]
......
using CovidAlertVaccinationModel using CovidAlertVaccinationModel
using CovidAlertVaccinationModel:ModelSolution,AgentDemographic,mean,AgentStatus,get_u_0,get_parameters,solve!, DebugRecorder using CovidAlertVaccinationModel:ModelSolution,AgentDemographic,mean,AgentStatus,get_u_0,get_parameters,solve!, DebugRecorder, WeightedGraph
using Random using Random
using Plots using Plots
using ThreadsX using ThreadsX
...@@ -30,5 +30,57 @@ const model_sizes = [1000,5000] ...@@ -30,5 +30,57 @@ const model_sizes = [1000,5000]
end end
end end
function approximate_mixing_matricies_weights_dict(p,sol)
mean_mixing_degree = zeros(3,3)
mean_mixing_weighted_degree = zeros(3,3)
for g_list in sol.inf_network.graph_list
for (k,g) in enumerate(g_list)
for e in keys(g.mixing_edges.weights_dict)
demo_i = sol.demographics[e.a]
demo_j = sol.demographics[e.b]
mean_mixing_degree[Int(demo_i), Int(demo_j)] += 1
mean_mixing_degree[Int(demo_j), Int(demo_i)] += 1
mean_mixing_weighted_degree[Int(demo_i), Int(demo_j)] += get_weight(g,GraphEdge(e.a,e.b))
mean_mixing_weighted_degree[Int(demo_j), Int(demo_i)] += get_weight(g,GraphEdge(e.a,e.b))
end
end
end
mean_mixing_degree ./= (p.sim_length .* length.(sol.index_vectors) * 2)
mean_mixing_weighted_degree ./= (p.sim_length .* length.(sol.index_vectors) * 2)
return mean_mixing_degree, mean_mixing_weighted_degree
end
function approximate_mixing_matricies_graph(p,sol)
mean_mixing_degree = zeros(3,3)
mean_mixing_weighted_degree = zeros(3,3)
for g_list in sol.inf_network.graph_list
for g in g_list
for e in edges(g.g)
demo_i = sol.demographics[src(e)]
demo_j = sol.demographics[dst(e)]
mean_mixing_degree[Int(demo_i), Int(demo_j)] += 1#get_weight(g,GraphEdge(node_i,node_j)) /2
mean_mixing_degree[Int(demo_j), Int(demo_i)] += 1#get_weight(g,GraphEdge(node_i,node_j)) /2
mean_mixing_weighted_degree[Int(demo_i), Int(demo_j)] += get_weight(g,GraphEdge(src(e),dst(e)))
mean_mixing_weighted_degree[Int(demo_j), Int(demo_i)] += get_weight(g,GraphEdge(src(e),dst(e)))
end
end
end
mean_mixing_degree ./= (p.sim_length .* length.(sol.index_vectors) * 2)
mean_mixing_weighted_degree ./= (p.sim_length .* length.(sol.index_vectors) * 2)
return mean_mixing_degree, mean_mixing_weighted_degree
end
@testset "weights dict and graph match" for _ in samples
p = get_parameters()
sol = abm(p,nothing)
graph_deg_matrix,graph_wdeg_matrix = approximate_mixing_matricies_graph(p,sol)
dict_deg_matrix,dict_wdeg_matrix = approximate_mixing_matricies_weights_dict(p,sol)
@test all(graph_deg_matrix . dict_deg_matrix)
@test all(graph_wdeg_matrix . dict_wdeg_matrix)
end
@testset "degree distribution generation" for _ in samples
end
\ No newline at end of file
No preview for this file type
No preview for this file type
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment