Commit 87525aae authored by Peter Jentsch's avatar Peter Jentsch
Browse files

fix up rebase

parent 4f0dde9f
......@@ -66,15 +66,13 @@ Creates the `TimeDepMixingGraph` for our specific model.
Assumes the simulation begins on Thursday arbitrarily.
"""
function time_dep_mixing_graphs(len,base_network,demographics,index_vectors,ws_matrix_tuple,rest_matrix_tuple)
function time_dep_mixing_graphs(len,home_static_edges,demographics,index_vectors,ws_matrix_tuple,rest_matrix_tuple)
#weekly multiply durations by 1/5
daily_shift(dur_dists) = shift_contact_distributions(dur_dists,1/5)
#daily multiply by 1/2
weekly_shift(dur_dists) = shift_contact_distributions(dur_dists,1/2)
home_static_edges = WeightedGraph(base_network,demographics,contact_time_distributions.hh) #network with households and LTC homes
ws_static_edges = WeightedGraph(demographics,index_vectors,ws_matrix_tuple.daily,contact_time_distributions.ws)
ws_weekly_edges = WeightedGraph(demographics,index_vectors,ws_matrix_tuple.twice_a_week,weekly_shift(contact_time_distributions.ws))
ws_justonce_edges = WeightedGraph(demographics,index_vectors,ws_matrix_tuple.otherwise,daily_shift(contact_time_distributions.ws))
......@@ -83,7 +81,6 @@ function time_dep_mixing_graphs(len,base_network,demographics,index_vectors,ws_m
rest_weekly_edges = WeightedGraph(demographics,index_vectors,rest_matrix_tuple.twice_a_week,weekly_shift(contact_time_distributions.rest))
rest_justonce_edges = WeightedGraph(demographics,index_vectors,rest_matrix_tuple.otherwise,daily_shift(contact_time_distributions.rest))
inf_network_list = [home_static_edges,rest_static_edges,ws_justonce_edges,rest_justonce_edges]
soc_network_list = [home_static_edges,rest_static_edges,ws_static_edges]
......@@ -113,7 +110,7 @@ Completely remake all the graphs in `time_dep_mixing_graph.resampled_graphs`.
function remake_all!(t,time_dep_mixing_graph,index_vectors,demographics)
for wg in time_dep_mixing_graph.remade_graphs
empty!(wg)
assemble_graph!(wg,demographics,index_vectors,wg.mixing_matrix,wg.sampler_matrix)
assemble_graph!(wg,demographics,index_vectors,wg.mixing_matrix,wg.degrees_matrix)
end
# display_degree(time_dep_mixing_graph.resampled_graphs[1])
for wg in time_dep_mixing_graph.resampled_graphs
......@@ -153,22 +150,25 @@ struct WeightedGraph{M1,M2}
sampler_matrix::M2
degrees_matrix::Union{Nothing,Matrix{Vector{Int}}}
function WeightedGraph(demographics::AbstractVector,index_vectors,mixing_matrix::M1, sampler_matrix::Matrix{M2}) where {M1,M2}
weight_sample_list = Vector{Tuple{Int,Int,Base.RefValue{UInt8}}}()
weight_sample_list = Vector{Tuple{M2,Base.RefValue{UInt8}}}()
fadjlist = [Vector{HalfWeightedEdge}() for _ in 1:length(demographics)]
degrees_matrix = [similar(index_vectors[i]) for i = 1:3, j = 1:3]
wg = new{M1,M2}(
weight_sample_list,fadjlist,
weight_sample_list,
fadjlist,
mixing_matrix,
sampler_matrix,
degrees_matrix
)
assemble_graph!(wg,demographics,index_vectors,mixing_matrix,sampler_matrix)
assemble_graph!(wg,demographics,index_vectors,mixing_matrix,degrees_matrix)
return wg
end
function WeightedGraph(nv,sampler_matrix::Matrix{M2}) where M2
edges = Vector{Tuple{Int,Int,Base.RefValue{UInt8}}}()
weight_sample_list = Vector{Tuple{M2,Base.RefValue{UInt8}}}()
fadjlist = [Vector{HalfWeightedEdge}() for _ in 1:nv]
wg = new{Nothing,M2}(
edges,fadjlist,
weight_sample_list,
fadjlist,
nothing,
sampler_matrix,
nothing
......@@ -183,18 +183,18 @@ function empty!(wg::WeightedGraph)
empty!(wg.weight_sample_list)
end
function assemble_graph!(g,weights_dict,index_vectors,mixing_matrix,sampler_matrix,degree_matrix; resample_degrees=true)
function assemble_graph!(g,demographics,index_vectors,mixing_matrix,degree_matrix; resample_degrees=true)
for i in 1:3, j in 1:i #diagonal
if i != j
if resample_degrees
generate_contact_vectors!(mixing_matrix[i,j],mixing_matrix[j,i],degree_matrix[i,j],degree_matrix[j,i])
end
edges = fast_chung_lu_bipartite(degree_matrix[i,j],degree_matrix[j,i],index_vectors[i],index_vectors[j])
stubs_a,stubs_b = fast_chung_lu_bipartite(degree_matrix[i,j],degree_matrix[j,i],index_vectors[i],index_vectors[j])
else #from one group to itself we need another algorithm
if resample_degrees
generate_contact_vectors!(mixing_matrix[i,j],degree_matrix[i,j])
end
edges = fast_chung_lu(degree_matrix[i,j],index_vectors[i])
stubs_a,stubs_b = fast_chung_lu(degree_matrix[i,j],index_vectors[i])
end
for (a,b) in zip(stubs_a,stubs_b)
add_edge!(g,a,b,demographics)
......@@ -236,8 +236,8 @@ end
function add_edge!(g::WeightedGraph{T}, a,b, demographics) where {T}
# verts = vertices(g)
# (a in verts && b in verts) || error("uhoh") # edge out of bounds
verts = vertices(g)
(a in verts && b in verts) || error("edge out of bounds") # edge out of bounds
@inbounds a_nbhd = g.fadjlist[a]
@inbounds sampler = g.sampler_matrix[demographics[b],demographics[a]]
......
......@@ -26,6 +26,7 @@ using CSV
using DataFrames
using StaticArrays
import LightGraphs:neighbors,add_edge!
import Base:empty!
export intervalsmodel, hh, ws, rest, abm,multivariate_simulations
......
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