model_setup.jl 5.03 KB
Newer Older
1
function get_parameters()#(0.0000,0.00048,0.0005,0.16,-1.30,-1.24,-0.8,0.35,0.35,0.35,0.2)
2
    params = (
3
        sim_length = 1300,
4
        num_households = 5000,
5
        I_0_fraction = 0.005,
6
7
8
9
10
11
        β_y =0.00051,
        β_m = 0.00047,
        β_o = 0.07,
        α_y = 0.35,
        α_m = 0.35,
        α_o = 0.35,
12
        recovery_rate = 1/5,
13
14
15
        π_base_y = -1.35,
        π_base_m = -1.35,
        π_base_o = -0.9,
16
        η = 0.0,
17
        κ = 0.0,
18
        ω = 0.00,
19
        ω_en = 0.00,
20
        γ = 0.0,
21
        ξ = 5.0,
22
        notification_parameter = 0.001,
23
        vaccinator_prob = 0.2,
Peter Jentsch's avatar
Peter Jentsch committed
24
        app_user_fraction = 0.0,
25
        notification_threshold = 20,
26
        immunizing = true,
27
        immunization_delay = 14,
28
29
30
        immunization_begin_day = 1060, 
        infection_introduction_day = 1180,
        O_distribution_shift = 0.5,
31
32
33
34
35
    )
    return params
end

function get_u_0(nodes,I_0_fraction,vaccinator_prob)
Peter Jentsch's avatar
Peter Jentsch committed
36
    is_vaccinator = rand(Random.default_rng(Threads.threadid()),nodes) .< vaccinator_prob
37
38
39
40
    status = fill(Susceptible,nodes)
    return status,is_vaccinator
end

Peter Jentsch's avatar
Peter Jentsch committed
41
42
43
44
45
46
47
48
49
function app_users(demographics,app_usage_prob)
    ymo_usage = [
        0.979,
        0.921,
        0.604,  
    ]
    is_app_user = Vector{Bool}(undef,length(demographics))
    @inbounds for i in eachindex(demographics)
        demo = demographics[i]
Peter Jentsch's avatar
Peter Jentsch committed
50
        is_app_user[i] = rand(Random.default_rng(Threads.threadid())) < app_usage_prob*ymo_usage[Int(demo)]
Peter Jentsch's avatar
Peter Jentsch committed
51
52
53
54
55
56
    end
    return is_app_user
end


mutable struct ModelSolution{T,InfNet,SocNet,WSMixingDist,RestMixingDist}
57
58
59
60
61
62
63
    sim_length::Int
    nodes::Int
    params::T
    u_next_inf::Vector{AgentStatus}
    u_next_vac::Vector{Bool}
    u_inf::Vector{AgentStatus}
    u_vac::Vector{Bool}
64
    covid_alert_notifications::Array{Bool,2}
65
    time_of_last_alert::Vector{Int}
66
67
    inf_network::InfNet
    soc_network::SocNet
68
69
70
71
72
    index_vectors::Vector{Vector{Int}}
    demographics::Vector{AgentDemographic}
    app_user::Vector{Bool}
    app_user_list::Vector{Int}
    app_user_index::Vector{Int}
Peter Jentsch's avatar
Peter Jentsch committed
73

74
    status_totals::Vector{Int}
Peter Jentsch's avatar
Peter Jentsch committed
75
    daily_vaccinators::Int
76
    daily_cases_by_age::Vector{Int}
Peter Jentsch's avatar
Peter Jentsch committed
77
    daily_unvac_cases_by_age::Vector{Int}
78
    daily_immunized_by_age::Vector{Int}
79
80
    ws_matrix_tuple::WSMixingDist
    rest_matrix_tuple::RestMixingDist
81
    immunization_countdown::Vector{Int}
82
    @views function ModelSolution(sim_length,params::T,num_households) where T
83
        demographics,base_network,index_vectors = generate_population(num_households)
84
        nodes = length(demographics)
85
        pop_sizes = length.(index_vectors)
86
87
        ws_mixing_tuple_preshift = deepcopy(workschool_mixing)
        rest_mixing_tuple_preshift = deepcopy(rest_mixing)
88

89
        for md in ws_mixing_tuple_preshift
90
            adjust_distributions_mean!(md[1:3,3],params.O_distribution_shift)
91
            adjust_distributions_mean!(md[3,1:2],params.O_distribution_shift)#dont shift OO twice
92
        end
93
        for md in rest_mixing_tuple_preshift
94
            adjust_distributions_mean!( md[1:3,3],params.O_distribution_shift)
95
            adjust_distributions_mean!( md[3,1:2],params.O_distribution_shift) #dont shift OO twice
96
        end
97
98
        map_symmetrize(m_tuple) = map(md -> symmetrize_means(pop_sizes,md), m_tuple)

99
100
        ws_matrix_tuple = map_symmetrize(ws_mixing_tuple_preshift) 
        rest_matrix_tuple = map_symmetrize(rest_mixing_tuple_preshift)
Peter Jentsch's avatar
Peter Jentsch committed
101
        # display(mean.(rest_matrix_tuple.daily))
102

Peter Jentsch's avatar
Peter Jentsch committed
103
        is_app_user = app_users(demographics,params.app_user_fraction)
104
        app_user_list = zeros(nodes)
105
106
107
108
109
        app_user_index = findall(==(true),is_app_user)
        app_user_list[is_app_user] .= collect(1:length(app_user_index))
        
        u_0_inf,u_0_vac = get_u_0(nodes,params.I_0_fraction,params.vaccinator_prob)

110
111
        infected_mixing_graph,soc_mixing_graph = time_dep_mixing_graphs(sim_length,base_network,demographics,index_vectors,ws_matrix_tuple,rest_matrix_tuple)
      
112
        covid_alert_notifications = zeros(Bool,14,length(app_user_index)) #two weeks worth of values
113
        time_of_last_alert = fill(-1,length(app_user_index)) #time of last alert is negative if no alert has been recieved
114

115
        status_totals = [count(==(AgentStatus(i)), u_0_inf) for i in 1:AgentStatus.size]
116
        immunization_countdown = fill(-1, nodes) #immunization countdown is negative if not counting down
117
        return new{T,typeof(infected_mixing_graph),typeof(soc_mixing_graph),typeof(ws_matrix_tuple),typeof(rest_matrix_tuple)}(
118
119
120
121
122
123
124
            sim_length,
            nodes,
            params,
            u_0_inf,
            u_0_vac,
            copy(u_0_inf),
            copy(u_0_vac),
125
            covid_alert_notifications,
126
            time_of_last_alert,
127
128
            infected_mixing_graph,
            soc_mixing_graph,
129
130
131
132
            index_vectors,
            demographics,
            is_app_user,
            app_user_list,
133
134
            app_user_index,
            status_totals,
Peter Jentsch's avatar
Peter Jentsch committed
135
            0,
136
            [0,0,0],
Peter Jentsch's avatar
Peter Jentsch committed
137
            [0,0,0],
Peter Jentsch's avatar
Peter Jentsch committed
138
            [0,0,0],
139
            ws_matrix_tuple,
140
141
            rest_matrix_tuple,
            immunization_countdown
142
143
144
        )
    end
end