Commit 0bfd9b1d authored by Peter Jentsch's avatar Peter Jentsch
Browse files

minor optimizations and move to multiprocessing

parent 5ba73f6f
......@@ -520,10 +520,8 @@ uuid = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b"
version = "0.6.3"
[[KissABC]]
deps = ["AbstractMCMC", "Distributions", "MonteCarloMeasurements", "Random"]
git-tree-sha1 = "c6c85d271b03eb65021e3771eb620ed881078f83"
repo-rev = "master"
repo-url = "https://github.com/francescoalemanno/KissABC.jl.git"
deps = ["AbstractMCMC", "Distributed", "Distributions", "MonteCarloMeasurements", "Random"]
path = "/home/peterj/Projects/PRs/KissABC.jl/"
uuid = "9c9dad79-530a-4643-a18b-2704674d4108"
version = "3.0.1"
......@@ -1267,7 +1265,7 @@ uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a"
version = "2.9.12+0"
[[XSLT_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Pkg", "XML2_jll"]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Libgpg_error_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "2b3eac39df218762d2d005702d601cd44c997497"
uuid = "aed1982a-8fda-507f-9586-7b0439959a61"
version = "1.1.33+4"
......
......@@ -12,6 +12,7 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
......
using CovidAlertVaccinationModel
using OnlineStats
using Plots
using StatsBase
using Distributed
addprocs(15)
@everywhere using CovidAlertVaccinationModel
CovidAlertVaccinationModel.fit_parameters(CovidAlertVaccinationModel.get_parameters())
\ No newline at end of file
......@@ -25,15 +25,15 @@ end
Runs the model 8 times using all threads.
"""
function threaded_bench()
ThreadsX.map(t -> bench(),1:8)
ThreadsX.map(t -> bench(),1:20)
end
using Distributed
"""
Runs the model 8 times using processes.
"""
function dist_bench()
pmap(t -> bench(),1:8)
pmap(t -> bench(),1:20)
end
"""
......
......@@ -70,11 +70,11 @@ This is the matrix of distributions, from which the edge weights are sampled. Sp
struct MixingEdges{M}
total_edges::Int
contact_array::Matrix{Vector{GraphEdge}}
sample_cache::Matrix{Vector{Int}}
sample_cache::Matrix{Vector{UInt8}}
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)),contact_array)
sample_cache = map(v-> Vector{UInt8}(undef,length(v)),contact_array)
weights_dict = Dictionary{GraphEdge,UInt8}(;sizehint = total_edges)
new{typeof(sampler_matrix)}(total_edges,contact_array,sample_cache,weights_dict,sampler_matrix)
end
......@@ -87,8 +87,8 @@ function create_mixing_edges(demographic_index_vectors,mixing_matrix,weights_dis
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]))
num_degrees_ji = zeros(Int,length(demographic_index_vectors[j]))
num_degrees_ij = similar(demographic_index_vectors[i])
num_degrees_ji = similar(demographic_index_vectors[j])
generate_contact_vectors!(mixing_matrix[i,j],mixing_matrix[j,i],num_degrees_ij,num_degrees_ji)
m = sum(num_degrees_ij)
......@@ -110,13 +110,12 @@ 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 = [sizehint!(Vector{GraphEdge}(),ne(g)) for i in 1:length(demographic_index_vectors),j in 1:length(demographic_index_vectors)]
contact_array = [sizehint!(Vector{GraphEdge}(),length(demographic_index_vectors[i])*2) 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[i]),Int(demographics[j])], GraphEdge(i,j))
end
sample_cache = map(v-> Vector{Int}(undef,length(v)),contact_array)
return MixingEdges(ne(g),contact_array,weights_distribution_matrix)
end
......@@ -226,8 +225,6 @@ mutable struct WeightedGraph{G,M}
end
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)),mixing_edges.contact_array)
return new{typeof(g),typeof(mixing_edges)}(
g,
mixing_edges,
......
......@@ -27,7 +27,7 @@ function get_parameters()
immunization_delay = 14,
immunization_begin_day =60,
infection_introduction_day = 180,
O_distribution_shift = 0.0,
O_distribution_shift = 0.2,
)
return params
end
......
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