diff --git a/CovidAlertVaccinationModel/plots/univariate/I_0_fraction.pdf b/CovidAlertVaccinationModel/plots/univariate/I_0_fraction.pdf index 0af51224faa35367b6122e476b1f7d5d48d6d514..68970db963cdcfa9923dfcd75694cceec9f03d9c 100644 Binary files a/CovidAlertVaccinationModel/plots/univariate/I_0_fraction.pdf and b/CovidAlertVaccinationModel/plots/univariate/I_0_fraction.pdf differ diff --git a/CovidAlertVaccinationModel/plots/univariate/app_user_fraction.pdf b/CovidAlertVaccinationModel/plots/univariate/app_user_fraction.pdf index b0c8da49a9568f0bf8590ef82e24cfcd4e6ae6be..f7f5f584e85665a2671fb48a2134e18546353003 100644 Binary files a/CovidAlertVaccinationModel/plots/univariate/app_user_fraction.pdf and b/CovidAlertVaccinationModel/plots/univariate/app_user_fraction.pdf differ diff --git a/CovidAlertVaccinationModel/plots/univariate/base_transmission_probability.pdf b/CovidAlertVaccinationModel/plots/univariate/base_transmission_probability.pdf index 93225a2e61e71757e5e855a1f4199f18f559dbb1..8ecdd552811ffd8105ad3bf499e61140d33af310 100644 Binary files a/CovidAlertVaccinationModel/plots/univariate/base_transmission_probability.pdf and b/CovidAlertVaccinationModel/plots/univariate/base_transmission_probability.pdf differ diff --git a/CovidAlertVaccinationModel/plots/univariate/immunization_loss_prob.pdf b/CovidAlertVaccinationModel/plots/univariate/immunization_loss_prob.pdf index 6a220d1670be9054dfe8e1c970a616734ee46d19..8afbceab4a85f00e0da2c3cd5c9a1f4506b951db 100644 Binary files a/CovidAlertVaccinationModel/plots/univariate/immunization_loss_prob.pdf and b/CovidAlertVaccinationModel/plots/univariate/immunization_loss_prob.pdf differ diff --git a/CovidAlertVaccinationModel/plots/univariate/notification_parameter.pdf b/CovidAlertVaccinationModel/plots/univariate/notification_parameter.pdf index c1c3a4c8b2cf0020a2e5b579c515243010693e81..410478f32830b0963f824ae7e33542f0b5bf5293 100644 Binary files a/CovidAlertVaccinationModel/plots/univariate/notification_parameter.pdf and b/CovidAlertVaccinationModel/plots/univariate/notification_parameter.pdf differ diff --git a/CovidAlertVaccinationModel/plots/univariate/recovery_rate.pdf b/CovidAlertVaccinationModel/plots/univariate/recovery_rate.pdf index d6c13129f124ad6e7719332636042618be5d4ebe..659f7b3f59191f29b728561a1381d44dcf346696 100644 Binary files a/CovidAlertVaccinationModel/plots/univariate/recovery_rate.pdf and b/CovidAlertVaccinationModel/plots/univariate/recovery_rate.pdf differ diff --git "a/CovidAlertVaccinationModel/plots/univariate/\316\263.pdf" "b/CovidAlertVaccinationModel/plots/univariate/\316\263.pdf" index c7691ec3f57870dd15d951f07ae24296ce3f8365..3deb8c1024640bf993288d0f3311ffe8aed2937e 100644 Binary files "a/CovidAlertVaccinationModel/plots/univariate/\316\263.pdf" and "b/CovidAlertVaccinationModel/plots/univariate/\316\263.pdf" differ diff --git "a/CovidAlertVaccinationModel/plots/univariate/\316\267.pdf" "b/CovidAlertVaccinationModel/plots/univariate/\316\267.pdf" index 0a852fc27cd9b1156ce7b04e7933d259a64ce09e..4e766770f2a411cf14855e7b06023c20e3700183 100644 Binary files "a/CovidAlertVaccinationModel/plots/univariate/\316\267.pdf" and "b/CovidAlertVaccinationModel/plots/univariate/\316\267.pdf" differ diff --git "a/CovidAlertVaccinationModel/plots/univariate/\316\272.pdf" "b/CovidAlertVaccinationModel/plots/univariate/\316\272.pdf" index e771c66b1372bd4fd83c8f6bb49fca7a3bdc3b44..9806ce778154acf997f208e9b5c59ad6783c795f 100644 Binary files "a/CovidAlertVaccinationModel/plots/univariate/\316\272.pdf" and "b/CovidAlertVaccinationModel/plots/univariate/\316\272.pdf" differ diff --git "a/CovidAlertVaccinationModel/plots/univariate/\317\200_base.pdf" "b/CovidAlertVaccinationModel/plots/univariate/\317\200_base.pdf" index 8bed630cb02f1c015f2cbd40d92cb0f27efd2461..9ba56f8eba3145b477e2115c1a792745583709ad 100644 Binary files "a/CovidAlertVaccinationModel/plots/univariate/\317\200_base.pdf" and "b/CovidAlertVaccinationModel/plots/univariate/\317\200_base.pdf" differ diff --git "a/CovidAlertVaccinationModel/plots/univariate/\317\211.pdf" "b/CovidAlertVaccinationModel/plots/univariate/\317\211.pdf" index 6219977dc65c78ecc4b42b1a8e2b1775c7bc501c..bcfb757a80963cbfca7bd7ae8ab81d4702b6c741 100644 Binary files "a/CovidAlertVaccinationModel/plots/univariate/\317\211.pdf" and "b/CovidAlertVaccinationModel/plots/univariate/\317\211.pdf" differ diff --git "a/CovidAlertVaccinationModel/plots/univariate/\317\211_en.pdf" "b/CovidAlertVaccinationModel/plots/univariate/\317\211_en.pdf" index 401c5ab3bbd845874e718242c46f5990df7a814c..bb0c23a058a6ceb3d2c0d42c669f0bff3b0fab1a 100644 Binary files "a/CovidAlertVaccinationModel/plots/univariate/\317\211_en.pdf" and "b/CovidAlertVaccinationModel/plots/univariate/\317\211_en.pdf" differ diff --git a/CovidAlertVaccinationModel/src/ABM/mixing_graphs.jl b/CovidAlertVaccinationModel/src/ABM/mixing_graphs.jl index 501a7ef1d9d4bbeffd4b532dd85c1efb7774f71b..652e5f842e05915b4b8fb5cf34bff50e0dfeeda7 100644 --- a/CovidAlertVaccinationModel/src/ABM/mixing_graphs.jl +++ b/CovidAlertVaccinationModel/src/ABM/mixing_graphs.jl @@ -10,7 +10,6 @@ struct GraphEdge b::Int end - """ Define a hash on GraphEdge such that ``hash(a,b) = hash(b,a)`` (hash is commutative). @@ -21,12 +20,13 @@ function Base.hash(e::GraphEdge) end """ -Define symmetric (?) edge equality, matches the hash function. +Define symmetric edge equality, matches the hash function. """ function Base.isequal(e1::GraphEdge,e2::GraphEdge) return isequal(minmax(e1.a,e1.b),minmax(e2.a,e2.b)) end + """ sample_mixing_graph!(mixing_graph::Graph) @@ -36,13 +36,11 @@ Resample all the weights in `mixing_graph` function sample_mixing_graph!(mixing_graph) mixing_edges = mixing_graph.mixing_edges for i in 1:size(mixing_edges.contact_array)[1], j in 1:i #diagonal - rand!(RNG, mixing_edges.sampler_matrix[i,j],mixing_edges.sample_cache[i,j]) - for k in 1:length(mixing_edges.contact_array[i,j][1]) - kth_node_i = mixing_edges.contact_array[i,j][1][k] - kth_node_j = mixing_edges.contact_array[i,j][2][k] - edge_weight_k = mixing_edges.sample_cache[i,j][k] - set!(mixing_edges.weights_dict,GraphEdge(kth_node_i,kth_node_j), edge_weight_k) - end + rand!(RNG, mixing_edges.sampler_matrix[i,j],mixing_edges.sample_cache[i,j]) + for k in 1:length(mixing_edges.contact_array[i,j]) + edge_weight_k = mixing_edges.sample_cache[i,j][k] + set!(mixing_edges.weights_dict, mixing_edges.contact_array[i,j][k], edge_weight_k) + end end end @@ -73,12 +71,12 @@ This is the matrix of distributions, from which the edge weights are sampled. Sp """ struct MixingEdges{M} total_edges::Int - contact_array::Matrix{Tuple{Vector{Int},Vector{Int}}} + contact_array::Matrix{Vector{GraphEdge}} sample_cache::Matrix{Vector{Int}} weights_dict::Dictionary{GraphEdge,UInt8} sampler_matrix::M function MixingEdges(total_edges,contact_array,sampler_matrix::Matrix{M}) where M<:Sampleable{Univariate, Discrete} - sample_cache = map(v-> Vector{Int}(undef,length(v[1])),contact_array) + sample_cache = map(v-> Vector{Int}(undef,length(v)),contact_array) weights_dict = Dictionary{GraphEdge,UInt8}() new{typeof(sampler_matrix)}(total_edges,contact_array,sample_cache,weights_dict,sampler_matrix) end @@ -88,7 +86,7 @@ end This function constructs the `MixingEdges` type for rest and WS graphs. Calls `generate_contact_vectors!(..)` to get the degree distributions for a bipartite graph for each pair of demographics, and then adds edges to MixingEdges.contact_array with the Chung-Lu approach. """ function create_mixing_edges(demographic_index_vectors,mixing_matrix,weights_distribution_matrix) - contact_array =[(Vector{Int}(),Vector{Int}()) for i in 1:length(demographic_index_vectors),j in 1:length(demographic_index_vectors)] + contact_array =[Vector{GraphEdge}() for i in 1:length(demographic_index_vectors),j in 1:length(demographic_index_vectors)] tot = 0 for i in 1:size(mixing_matrix)[1], j in 1:i #diagonal num_degrees_ij = zeros(Int,length(demographic_index_vectors[i])) @@ -103,7 +101,8 @@ function create_mixing_edges(demographic_index_vectors,mixing_matrix,weights_dis sample!(RNG,demographic_index_vectors[j],Weights(num_degrees_ji./m),stubs_j) tot += m end - contact_array[j,i] = (stubs_i,stubs_j) + + contact_array[j,i] = GraphEdge.(stubs_i,stubs_j) end return MixingEdges(tot,contact_array,weights_distribution_matrix) end @@ -113,14 +112,13 @@ end This function constructs the `MixingEdges` type for the home graphs. Simply adds edges to MixingEdges from the graph `g`, since we already create that in `generate_population`. """ function create_mixing_edges(g::SimpleGraph,demographics,demographic_index_vectors,weights_distribution_matrix) - contact_array = [(Vector{Int}(),Vector{Int}()) for i in 1:length(demographic_index_vectors),j in 1:length(demographic_index_vectors)] - for e in edges(g) + contact_array = [sizehint!(Vector{GraphEdge}(),ne(g)) for i in 1:length(demographic_index_vectors),j in 1:length(demographic_index_vectors)] + for e in edges(g) i = src(e) j = dst(e) - push!(contact_array[Int(demographics[j]),Int(demographics[i])][1],i) - push!(contact_array[Int(demographics[j]),Int(demographics[i])][2],j) + push!(contact_array[Int(demographics[j]),Int(demographics[i])], GraphEdge(i,j)) end - sample_cache = map(v-> Vector{Int}(undef,length(v[1])),contact_array) + sample_cache = map(v-> Vector{Int}(undef,length(v)),contact_array) return MixingEdges(ne(g),contact_array,weights_distribution_matrix) end @@ -202,8 +200,9 @@ Add the edges defined by MixingEdges to the actual graph G. Another big bottlene """ function graph_from_mixing_edges(g,mixing_edges) for i in 1:size(mixing_edges.contact_array)[1], j in 1:i #diagonal - for k in 1:length(mixing_edges.contact_array[i,j][1]) - add_edge!(g,mixing_edges.contact_array[i,j][1][k],mixing_edges.contact_array[i,j][2][k]) + for k in 1:length(mixing_edges.contact_array[i,j]) + e = mixing_edges.contact_array[i,j][k] + add_edge!(g,e.a,e.b) end end end @@ -227,7 +226,7 @@ mutable struct WeightedGraph{G,M} function WeightedGraph(g::SimpleGraph,demographics,demographic_index_vectors,weights_distribution_matrix) mixing_edges = create_mixing_edges(g, demographics, demographic_index_vectors,weights_distribution_matrix) weights_dict = Dict{GraphEdge,UInt8}() - sample_cache = map(v-> Vector{Int}(undef,length(v[1])),mixing_edges.contact_array) + sample_cache = map(v-> Vector{Int}(undef,length(v)),mixing_edges.contact_array) return new{typeof(g),typeof(mixing_edges)}( g, mixing_edges,