Commit 29a75642 authored by Peter Jentsch's avatar Peter Jentsch
Browse files

add more tests

parent 5b083556
This diff is collapsed.
......@@ -27,7 +27,6 @@ LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Loess = "4345ca2d-374a-55d4-8d30-97f9976e7612"
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
LsqFit = "2fda8390-95c7-5789-9bda-21331edee243"
NamedTupleTools = "d9ec5142-1e00-5aa0-9d6a-321866360f50"
NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
OnlineStats = "a15396b6-48d5-5d58-9928-6d29437db91e"
......
......@@ -25,12 +25,12 @@ const univarate_test_list = (
# (:η, range(0.0, 0.01; length = len)),
# (:κ, range(0.5, 1.5; 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(1, 15; length = len)),
# (:ξ, range(1, 15; length = len)),
# (:notification_parameter, range(0.00, 0.05; 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]),
)
......
using CovidAlertVaccinationModel
using OnlineStats
using Plots
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 ymo_vac = [0.255,0.278,0.602]
const ymo_attack_rate = [10.376,5.636,7.2]./100
using CovidAlertVaccinationModel:vaccination_data,ymo_vac,ymo_attack_rate
const samples = 10
function solve_and_plot_parameters()
p = CovidAlertVaccinationModel.get_parameters()
......
......@@ -14,26 +14,21 @@ Runs the model with default parameters.
"""
function bench()
p = get_parameters()
model_sol = ModelSolution(p.sim_length,p,p.num_households)
recording = DebugRecorder(p.sim_length)
output = solve!(model_sol,recording)
abm(p,recording)
return recording
end
"""
Runs the model 8 times using all threads.
Runs the model once for each thread, using all threads.
"""
function threaded_bench()
ThreadsX.map(t -> bench(),1:20)
end
using Distributed
"""
Runs the model 8 times using processes.
"""
function dist_bench()
pmap(t -> bench(),1:20)
pmap(t -> bench(),1:nprocs())
end
"""
......@@ -42,11 +37,5 @@ Run the model with given parameter tuple and output recorder. See `get_parameter
function abm(parameters, recorder)
model_sol = ModelSolution(parameters.sim_length,parameters,parameters.num_households)
output = solve!(model_sol,recorder )
# total_weighted_degree = map(modelsol.index_vectors) do age_group_indices
# return mean(map(i -> weighted_degree(i,modelsol.inf_network),age_group_indices))
# end
# @show total_weighted_degree
return model_sol
end
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 = (
sim_length = 600,
sim_length = 500,
num_households = 5000,
I_0_fraction = 0.003,
β_y = 0.00077,
β_m = 0.00065,
β_o = 0.75,
β_y = 0.00078,
β_m = 0.00063,
β_o = 0.755,
α_y = 0.4,
α_m = 0.4,
α_o = 0.4,
recovery_rate = 1/5,
π_base_y = -1.4,
π_base_m = -1.4,
π_base_y = -1.39,
π_base_m = -1.44,
π_base_o = -0.95,
η = 0.0,
κ = 0.0,
ω = 0.005,
ω = 0.0055
,
ω_en = 0.00,
γ = 0.0,
ξ = 5.0,
......@@ -86,14 +87,6 @@ mutable struct ModelSolution{T,InfNet,SocNet,WSMixingDist,RestMixingDist}
ws_mixing_tuple_preshift = deepcopy(workschool_mixing)
rest_mixing_tuple_preshift = deepcopy(rest_mixing)
# for md in ws_mixing_tuple_preshift
# 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
# end
# for md in rest_mixing_tuple_preshift
# 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
# end
map_symmetrize(m_tuple) = map(md -> symmetrize_means(pop_sizes,md), m_tuple)
ws_matrix_tuple = map_symmetrize(ws_mixing_tuple_preshift)
......
......@@ -63,8 +63,8 @@ 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)
......@@ -97,20 +97,20 @@ function plot_fitting_posteriors(fname,particles_tuple,parameters)
avg_populations = [0.0,0.0,0.0]
names = keys(particles_tuple)
samples = collect(zip(particles_tuple...))
for p_set in sample(samples,30)
for p_set in sample(samples,50)
p_set_named = NamedTuple{names}(p_set)
display(p_set_named)
sol = abm(merge(parameters,p_set_named),output_recorder)
avg_populations .+= length.(sol.index_vectors)
fit!(stat_recorder,output_recorder)
end
avg_populations ./= 30
avg_populations ./= 50
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)
hist = StatsBase.fit(Histogram,v; nbins = 50)
plot!(plt,hist;legend = false,xlabel = k)
end
p = plot(plts...; size = (1400,800),bottommargin = 5Plots.mm)
......
......@@ -73,7 +73,7 @@ function approximate_mixing_matricies_graph(p,sol)
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
@testset "weights dict and graph match" begin
p = get_parameters()
sol = abm(p,nothing)
graph_deg_matrix,graph_wdeg_matrix = approximate_mixing_matricies_graph(p,sol)
......@@ -86,7 +86,7 @@ end
using OnlineStats
@testset "contact vector generation" for _ in samples
@testset "contact vector generation" begin
model = ModelSolution(1, get_parameters(), 1_000_000) #big
@unpack demographics, index_vectors, rest_matrix_tuple,ws_matrix_tuple = model
......
using CovidAlertVaccinationModel:vaccination_data,ymo_vac,ymo_attack_rate
using OnlineStats
using Plots
const samples = 10
using Random
@testset "default parameters output" begin
p = CovidAlertVaccinationModel.get_parameters()
display(p)
out,avg_populations = mean_solve(samples, p,DebugRecorder)
p = plot_model(nothing,[nothing],[out],p.infection_introduction_day,p.immunization_begin_day)
ymo_vaccination_ts = mean.(out.daily_immunized_by_age)
total_postinf_vaccination = sum.(eachrow(ymo_vaccination_ts[:,180:end]))
final_size = sum.(eachrow(mean.(out.daily_unvac_cases_by_age)))
total_preinf_vaccination = sum.(eachrow(ymo_vaccination_ts[:,1:180]))
target_final_size = ymo_attack_rate .*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
println("obs final size: $final_size, target: $target_final_size")
println("obs preinf vac: $total_preinf_vaccination, target: $target_preinf_vac")
println("obs postinf vac: $total_postinf_vaccination,target: $target_postinf_vac")
@test all(abs.(final_size .- target_final_size) .< [40,100,25])
@test all(abs.(total_preinf_vaccination .- target_preinf_vac) .< [50,100,25])
@test all(abs.(total_postinf_vaccination .- target_postinf_vac) .< [100,100,25])
end
@testset "perf" begin
b = @belapsed CovidAlertVaccinationModel.bench()
@test 4.2 < b < 4.85
if Threads.nthreads() == 20
b = @belapsed CovidAlertVaccinationModel.threaded_bench()
@test 10.65 < b < 15.00
else
display("incorrect number of threads, skipping threaded perf test")
end
end
using OnlineStats: neighbors
using CovidAlertVaccinationModel
using RandomNumbers.Xorshifts
using Test
using ThreadsX
using BenchmarkTools
import StatsBase.mean
include("ABM/mixing_test.jl")
# include("ABM/mixing_test.jl")
include("ABM/output_test.jl")
include("IntervalsModel/intervals_model_test.jl")
\ No newline at end of file
No preview for this file type
No preview for this file type
Markdown is supported
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