Commit 688f2ea5 authored by Peter Jentsch's avatar Peter Jentsch
Browse files

added comments

parent c693a91a
graphplot.gif

4.35 MB | W: | H:

graphplot.gif

4.38 MB | W: | H:

graphplot.gif
graphplot.gif
graphplot.gif
graphplot.gif
  • 2-up
  • Swipe
  • Onion skin
......@@ -18,17 +18,17 @@ using NetworkLayout:SFDP
import Base.rand
include("mixing_distributions.jl")
include("agents.jl")
include("mixing_distributions.jl")
include("data.jl")
include("model.jl")
include("plotting.jl")
include("graphs.jl")
const population = 14.57e6
const population = 14.57e6 #population of ontario
const color_palette = palette(:seaborn_bright)
const age_bins = [(0.0, 20.0),(20.0,60.0),(60.0,Inf)]
const color_palette = palette(:seaborn_bright) #color theme for the plots
const age_bins = [(0.0, 20.0),(20.0,60.0),(60.0,Inf)]
const PACKAGE_FOLDER = dirname(dirname(pathof(CovidAlertVaccinationModel)))
const infection_data = parse_cases_data()
const demographic_distribution = get_canada_demographic_distribution()
......@@ -53,7 +53,8 @@ function main()
# @btime solve!($u_0,$base_network,$params,$steps,$r,$pop_list,$index_vectors,vaccinate_uniformly!);
end
function vaccination_rate_test(num_households,vac_per_day,vac_strategy; rng = Xoroshiro128Plus())
#returns the total infected given a certain num_households, vaccines per day, and strategy
function vaccination_rate_test(num_households,vac_per_day,vac_strategy; rng = Xoroshiro128Plus())
agent_model = AgentModel(rng,num_households,2)
u_0 = get_u_0(rng,length(agent_model.demographics))
params = merge(get_parameters(),(vaccines_per_day = vac_per_day,))
......
......@@ -27,24 +27,6 @@ end
struct ZWDist{BaseDistType,T} <: Sampleable{Univariate,Discrete}
α::T
base_dist::BaseDistType
end
function Base.rand(rng::AbstractRNG, s::ZWDist)
if Base.rand(rng) < s.α
return 0
else
return Base.rand(rng,s.base_dist)
end
end
function ZeroPoisson(α,λ)
return ZWDist(α,Poisson(λ))
end
function ZeroGeometric(α,p)
return ZWDist(α,Geometric(p))
end
......
function generate_mixing_graph!(rng,g,population_list,index_vectors,mixing_matrix)
agents_young = population_list[index_vectors[1]]
# g = SimpleGraph(length(population_list))
#add a bipartite graph derived from mixing matrices onto g
#is there a better way to do this?
function generate_mixing_graph!(rng,g,index_vectors,mixing_matrix)
for i in 1:5, j in 1:i #diagonal
agent_contact_dist = mixing_matrix[i,j]
i_to_j_contacts = rand(rng,agent_contact_dist,length(index_vectors[i]))
......@@ -11,10 +10,12 @@ function generate_mixing_graph!(rng,g,population_list,index_vectors,mixing_matri
equalize_degree_lists!(i_to_j_contacts,j_to_i_contacts)
random_bipartite_graph_fast_CL!(rng,g,index_vectors[i],index_vectors[j],i_to_j_contacts,j_to_i_contacts)
# display(g)
end
return g
end
#Remove contacts from the degree list with the larger sum uniformly at random until they are equal
#needed to satisfy constraint that a bipartite graph exists with degree lists l1 and l2
function equalize_degree_lists!(l1,l2)
if sum(l1) > sum(l2)
map(i -> l1[i]-=1, sample(1:length(l1),sum(l1) - sum(l2)))
......@@ -23,7 +24,9 @@ function equalize_degree_lists!(l1,l2)
end
end
#modify g so that nodes specified in anodes and bnodes are connected by a bipartite graph with expected degrees given by aseq and bseq
#implemented from Aksoy, S. G., Kolda, T. G., & Pinar, A. (2017). Measuring and modeling bipartite graphs with community structure
#simple algorithm, might produce parallel edges for small graphs
function random_bipartite_graph_fast_CL!(rng,g,anodes,bnodes,aseq,bseq)
lena = length(aseq)
lenb = length(bseq)
......@@ -37,6 +40,10 @@ function random_bipartite_graph_fast_CL!(rng,g,anodes,bnodes,aseq,bseq)
return g
end
#generate population with households distributed according to household_size_distribution
#Assume 5% of elderly are in LTC roughly, these are divide evenly among a specific number of LTC ltc_homes
#LTC homes and households are assumed to be complete static graphs.
function generate_population(rng,num_households,num_LTC)
household_sizes = Int.(rand(rng,household_size_distribution,num_households))
......@@ -44,8 +51,8 @@ function generate_population(rng,num_households,num_LTC)
# LTC_sizes = rand(LTC_distribution,num_LTC)
prob_adult_is_HCW = 0.01
prob_elderly_in_LTC = 0.05
prob_adult_is_HCW = 0.01 #assume 1% of adults are HCW
prob_elderly_in_LTC = 0.05 #5% of elderly are in LTC
agent_distribution_in_households = Categorical([ #find a better way to do this maybe
demographic_distribution[1],
demographic_distribution[2] * (1 - prob_adult_is_HCW),
......
struct ZWDist{BaseDistType,T} <: Sampleable{Univariate,Discrete}
α::T
base_dist::BaseDistType
end
function Base.rand(rng::AbstractRNG, s::ZWDist)
if Base.rand(rng) < s.α
return 0
else
return Base.rand(rng,s.base_dist)
end
end
function ZeroPoisson(α,λ)
return ZWDist(α,Poisson(λ))
end
function ZeroGeometric(α,p)
return ZWDist(α,Geometric(p))
end
#constant for now anyway..
const home_mixing_matrix = [
Poisson(1.749) Poisson(2.629) Poisson(0.648) Poisson(2.629) Poisson(0.648)
Poisson(0.726) Poisson(1.909) Poisson(0.357) Poisson(1.909) Poisson(0.357)
......
......@@ -47,17 +47,19 @@ end
function solve!(rng,u_0,params,steps,agent_model,vaccination_algorithm!)
solution = vcat([u_0], [fill(Susceptible,length(u_0)) for i in 1:steps])
population_list = agent_model.demographics
index_vectors = agent_model.demographic_index_vectors
base_network = agent_model.base_network
population_list = agent_model.demographics #list of demographic status for each agent
index_vectors = agent_model.demographic_index_vectors #lists of indices of each agent with a given demographic
base_network = agent_model.base_network #static network, households and LTC homes
graphs = [base_network]
for t in 1:steps
graph_t = deepcopy(base_network)
generate_mixing_graph!(rng,graph_t,population_list,index_vectors,workschool_mixing_matrix)
generate_mixing_graph!(rng,graph_t,population_list,index_vectors,rest_mixing_matrix)
push!(graphs,graph_t)
agents_step!(rng,t,solution[t+1],solution[t],population_list,graph_t,params,index_vectors,vaccination_algorithm!)
graph_t = deepcopy(base_network) #copy static network to modify with dynamic workschool/rest contacts
generate_mixing_graph!(rng,graph_t,index_vectors,workschool_mixing_matrix) #add workschool contacts
generate_mixing_graph!(rng,graph_t,index_vectors,rest_mixing_matrix) #add rest contacts
push!(graphs,graph_t) #add the generated graph for this timestep onto the list of graphs
agents_step!(rng,t,solution[t+1],solution[t],population_list,graph_t,params,index_vectors,vaccination_algorithm!)
#advance agent states based on the new network, vaccination process given by vaccination_algorithm!, which is just a function defined as above
end
return solution,graphs
......
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