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

parameter fits

parent 980b9b71
......@@ -15,9 +15,16 @@ function solve_w_parameters(default_p, p_names, new_p_list)
end
function fit_distribution_parameters(p_tuple)
p_names = (:ω,:π_base_y,:π_base_m,:π_base_o,:ζ)
p_names = (:ω,:β_y,:β_m,:β_o,:π_base_y,:π_base_m,:π_base_o,:ζ)
β_y_val = 0.00077
β_m_val = 0.00065
β_o_val = 0.75
priors = Factored(
Uniform(0.0,0.01),
TriangularDist(β_y_val-0.0005,β_y_val+0.0005),
TriangularDist(β_m_val-0.0005,β_m_val+0.0005),
TriangularDist(β_o_val-0.0005,β_o_val+0.0005),
Uniform(-5.0,3.0),
Uniform(-5.0,3.0),
Uniform(-5.0,3.0),
......@@ -26,18 +33,8 @@ function fit_distribution_parameters(p_tuple)
#simulation begins in july
#60 days for opinion dynamics to stabilize, then immunization begins in september,
#infection introduced at beginning of december
sim_length = 400
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)
output,model = solve_w_parameters(p_tuple_adjust, p_names,p)
output,model = solve_w_parameters(p_tuple, p_names,p)
ymo_vaccination_ts = output.daily_immunized_by_age
total_postinf_vaccination = sum.(eachrow(ymo_vaccination_ts[:,181:end]))
......@@ -57,17 +54,17 @@ function fit_distribution_parameters(p_tuple)
+ sum((total_postinf_vaccination .- total_postinf_vaccination).^2)
+ sum((final_size .- target_final_size).^2)
end
# display(cost((0.005,0.00075, 0.00063,0.75,-1.4,-1.4,-0.95)))
# display(cost((0.005,0.00075, 0.00063,0.75,-1.4,-1.4,-0.95,1.25)))
out = smc(priors,cost; verbose = true, nparticles = 250, parallel = true)
out = smc(priors,cost; verbose = true, nparticles = 1000, 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")
# output = fit_distribution_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)
......
......@@ -176,7 +176,7 @@ end
function solve!(modelsol,recordings...)
init_indices = rand(Random.default_rng(Threads.threadid()), 1:modelsol.nodes, round(Int,modelsol.nodes*modelsol.params.I_0_fraction))
@show length(init_indices)
for t in 1:modelsol.sim_length
agents_step!(t,modelsol,init_indices)
#advance agent states based on the new network
......
using CovidAlertVaccinationModel:generate_contact_vectors!
using CovidAlertVaccinationModel:abm,generate_contact_vectors!
using CovidAlertVaccinationModel:ModelSolution,AgentDemographic,mean,get_weight
using CovidAlertVaccinationModel:AgentStatus,get_u_0,get_parameters,solve!, DebugRecorder, WeightedGraph, contact_time_distributions,GraphEdge
using LightGraphs
......@@ -135,8 +135,5 @@ end
for i in eachindex(mixing_dist)
@test mean(mixing_dist[i]) mean(dist[i]) atol = 0.2
end
display(var.(mixing_dist))
display(var.(dist))
display("====")
end
end
\ No newline at end of file
No preview for this file type
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