model_setup.jl 5.23 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 = 400,
4
        num_households = 5000,
5
        I_0_fraction = 0.005,
6
7
8
9
10
11
        β_y = 0.00046,
        β_m = 0.00044,
        β_o = 0.6,
        α_y = 0.4,
        α_m = 0.4,
        α_o = 0.4,
12
        recovery_rate = 1/5,
13
14
15
        π_base_y = -1.30,
        π_base_m = -1.31,
        π_base_o = -0.95,
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.6,
Peter Jentsch's avatar
Peter Jentsch committed
24
        app_user_fraction = 0.0,
25
        notification_threshold = 20,
26
        immunizing = true,
27
        immunization_delay = 14,
Peter Jentsch's avatar
Peter Jentsch committed
28
29
        immunization_begin_day = 60, 
        infection_introduction_day = 180,
30
31
32
33
    )
    return params
end

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

Peter Jentsch's avatar
Peter Jentsch committed
40
41
42
43
44
45
46
47
48
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
49
        is_app_user[i] = rand(Random.default_rng(Threads.threadid())) < app_usage_prob*ymo_usage[Int(demo)]
Peter Jentsch's avatar
Peter Jentsch committed
50
51
52
53
54
55
    end
    return is_app_user
end


mutable struct ModelSolution{T,InfNet,SocNet,WSMixingDist,RestMixingDist}
56
57
58
59
60
61
62
    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}
63
    covid_alert_notifications::Array{Bool,2}
64
    time_of_last_alert::Vector{Int}
65
66
    inf_network::InfNet
    soc_network::SocNet
67
68
69
70
71
    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
72

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

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

98
99
        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
100
        # display(mean.(rest_matrix_tuple.daily))
101

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

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

114
        status_totals = [count(==(AgentStatus(i)), u_0_inf) for i in 1:AgentStatus.size]
115
        immunization_countdown = fill(-1, nodes) #immunization countdown is negative if not counting down
Peter Jentsch's avatar
Peter Jentsch committed
116
117
118
119
120
121


        for network in infected_mixing_graph.graph_list[begin] #this also resamples the soc network weights since they point to the same objects, but those are never used
            sample_mixing_graph!(network) #get new contact weights
        end
        
122
        return new{T,typeof(infected_mixing_graph),typeof(soc_mixing_graph),typeof(ws_matrix_tuple),typeof(rest_matrix_tuple)}(
123
124
125
126
127
128
129
            sim_length,
            nodes,
            params,
            u_0_inf,
            u_0_vac,
            copy(u_0_inf),
            copy(u_0_vac),
130
            covid_alert_notifications,
131
            time_of_last_alert,
132
133
            infected_mixing_graph,
            soc_mixing_graph,
134
135
136
137
            index_vectors,
            demographics,
            is_app_user,
            app_user_list,
138
139
            app_user_index,
            status_totals,
Peter Jentsch's avatar
Peter Jentsch committed
140
            0,
141
            [0,0,0],
Peter Jentsch's avatar
Peter Jentsch committed
142
            [0,0,0],
Peter Jentsch's avatar
Peter Jentsch committed
143
            [0,0,0],
144
            ws_matrix_tuple,
145
146
            rest_matrix_tuple,
            immunization_countdown
147
148
149
        )
    end
end