mixing_distributions.jl 2.56 KB
 Peter Jentsch committed Apr 21, 2021 1 2 3 4 5 6 `````` """ adjust_distributions_mean(distribution_matrix::AbstractArray{T},mean_shift_percentage::Number) Adjust the means of the distributions in `distribution_matrix` by `mean_shift_percentage`. """ `````` Peter Jentsch committed May 25, 2021 7 8 9 10 ``````function adjust_distributions_mean!(distribution_matrix,mean_shift_percentage) for i in eachindex(distribution_matrix) dist = distribution_matrix[i] new_mean = mean(dist) + mean_shift_percentage `````` Peter Jentsch committed May 27, 2021 11 `````` `````` Peter Jentsch committed May 25, 2021 12 `````` distribution_matrix[i] = from_mean(typeof(dist), new_mean) `````` Peter Jentsch committed May 27, 2021 13 `````` `````` Peter Jentsch committed Apr 09, 2021 14 15 16 `````` end end `````` Peter Jentsch committed Apr 21, 2021 17 18 19 20 21 ``````""" symmetrize_means(population_sizes::Vector{Int},mixing_matrix::Matrix{<:Distribution}) Symmetrize `mixing_matrix` such that it satisifes the conditions needed for `generate_contact_vectors!(..)`, given `population_sizes`. """ `````` Peter Jentsch committed Apr 09, 2021 22 23 24 25 26 27 28 29 30 31 ``````function symmetrize_means(population_sizes,mixing_matrix::Matrix{<:Distribution}) mixing_means = mean.(mixing_matrix) symmetrized_means = zeros((length(population_sizes),length(population_sizes))) for i in 1:length(population_sizes), j in 1:length(population_sizes) symmetrized_means[i,j] = 0.5*(mixing_means[i,j] + population_sizes[j]/population_sizes[i] * mixing_means[j,i]) end return map(((dst,sym_mean),)->from_mean(typeof(dst),sym_mean), zip(mixing_matrix,symmetrized_means)) end `````` Peter Jentsch committed Apr 21, 2021 32 33 ``````""" This is a namedtuple with entries `hh,ws,rest` which define matrices of Poisson distributions, with parameters given by IntervalsModel. `````` Peter Jentsch committed Apr 09, 2021 34 `````` `````` Peter Jentsch committed Apr 21, 2021 35 36 ``````See `load_contact_time_distributions()`. """ `````` Peter Jentsch committed Apr 18, 2021 37 ``````const contact_time_distributions = load_contact_time_distributions() `````` Peter Jentsch committed Apr 09, 2021 38 `````` `````` Peter Jentsch committed Jul 22, 2021 39 40 41 ``````function shift_contact_distributions(sampler_matrix::AbstractMatrix{T},proportion) where T<:Distributions.PoissonADSampler return map(sampler_matrix) do sampler μ_old = sampler.μ `````` Peter Jentsch committed Jul 22, 2021 42 `````` return Poisson(μ_old*proportion) `````` Peter Jentsch committed Jul 22, 2021 43 44 `````` end end `````` Peter Jentsch committed Apr 09, 2021 45 `````` `````` Peter Jentsch committed Apr 21, 2021 46 47 48 ````````` Given alphas given in `unemployment_matrix` computes the zero weight for each pair of demographic contacts given individual zero weights. ``` `````` Peter Jentsch committed Apr 09, 2021 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 ``````function alpha_matrix(alphas) M = zeros(length(alphas),length(alphas)) for i in 1:length(alphas), j in 1:length(alphas) M[i,j] = alphas[i] + alphas[j] - alphas[j]*alphas[i] end return M end const unemployment_matrix = alpha_matrix( ( Y = 0.11, M = 0.14, O = 0.87 ) ) `````` Peter Jentsch committed Apr 21, 2021 65 66 67 ``````""" Sample initial_workschool_mixing_matrix, which is the workschool distributions symmetrized for the full Canadian population, rather than subsets (as used in the ABM). This is used in IntervalsModel. """ `````` Peter Jentsch committed Apr 09, 2021 68 ``````@views function ws_sample(age) `````` Peter Jentsch committed May 18, 2021 69 `````` return rand.(Random.default_rng(Threads.threadid()),initial_workschool_mixing_matrix[age,:]) * (rand(Random.default_rng(Threads.threadid())) < (5/7)) `````` Peter Jentsch committed Apr 09, 2021 70 ``end``