model_setup.jl 4.6 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 = (
Peter Jentsch's avatar
Peter Jentsch committed
3
        sim_length = 500,
4
        num_households = 5000,
5
        I_0_fraction = 0.003,
6
        β_y = 0.001095,
Peter Jentsch's avatar
Peter Jentsch committed
7
8
        β_m = 0.00061,
        β_o = 0.04,
9
10
11
        α_y = 0.4,
        α_m = 0.4,
        α_o = 0.4,
12
        recovery_rate = 1/5,
Peter Jentsch's avatar
Peter Jentsch committed
13
14
        π_base_y = -1.37,
        π_base_m = -1.46,
15
        π_base_o = -0.95,
Peter Jentsch's avatar
Peter Jentsch committed
16
        η = 0.5,
17
        κ = 0.0,
18
        ω = 0.0053,
Peter Jentsch's avatar
Peter Jentsch committed
19
        ω_en = 0.01,
Peter Jentsch's avatar
Peter Jentsch committed
20
        Γ = 1/7,
21
        ξ = 5.0,
Peter Jentsch's avatar
Peter Jentsch committed
22
        notification_parameter = 0.0005,
23
        vaccinator_prob = 0.6,
Peter Jentsch's avatar
Peter Jentsch committed
24
        app_user_fraction = 0.0,
Peter Jentsch's avatar
Peter Jentsch committed
25
        notification_threshold = 2,
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
        ζ = 1.3
31
32
33
    )
    return params
end
Peter Jentsch's avatar
Peter Jentsch committed
34
function get_app_parameters()
35

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

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


Peter Jentsch's avatar
Peter Jentsch committed
59
mutable struct ModelSolution{T,InfNet,SocNet,WSMixingDist,RestMixingDist,RecorderType}
60
61
62
63
64
65
66
    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}
67
    covid_alert_notifications::Array{Bool,2}
68
    time_of_last_alert::Vector{Int}
69
70
    inf_network::InfNet
    soc_network::SocNet
71
72
73
74
75
    index_vectors::Vector{Vector{Int}}
    demographics::Vector{AgentDemographic}
    app_user::Vector{Bool}
    app_user_list::Vector{Int}
    app_user_index::Vector{Int}
76
    status_totals::Vector{Int}
77
78
    ws_matrix_tuple::WSMixingDist
    rest_matrix_tuple::RestMixingDist
79
    immunization_countdown::Vector{Int}
Peter Jentsch's avatar
Peter Jentsch committed
80
    output_data::RecorderType
Peter Jentsch's avatar
Peter Jentsch committed
81
    @views function ModelSolution(sim_length,params::T,num_households; record_degrees = false) where T
Peter Jentsch's avatar
Peter Jentsch committed
82
        demographics,household_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
        map_symmetrize(m_tuple) = map(md -> symmetrize_means(pop_sizes,md), m_tuple)

90
91
        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
92
        # display(mean.(rest_matrix_tuple.daily))
93

Peter Jentsch's avatar
Peter Jentsch committed
94
        is_app_user = app_users(demographics,params.app_user_fraction)
95
        app_user_list = zeros(nodes)
96
97
98
        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
99
        u_0_inf,u_0_vac = get_u_0(nodes,params.vaccinator_prob)
100

Peter Jentsch's avatar
Peter Jentsch committed
101
        infected_mixing_graph,soc_mixing_graph = time_dep_mixing_graphs(sim_length,household_network,demographics,index_vectors,ws_matrix_tuple,rest_matrix_tuple)
102
      
103
        covid_alert_notifications = zeros(Bool,14,length(app_user_index)) #two weeks worth of values
104
        time_of_last_alert = fill(-1,length(app_user_index)) #time of last alert is negative if no alert has been recieved
105

106
        status_totals = [count(==(AgentStatus(i)), u_0_inf) for i in 1:AgentStatus.size]
107
        immunization_countdown = fill(-1, nodes) #immunization countdown is negative if not counting down
Peter Jentsch's avatar
Peter Jentsch committed
108
109
        output_data = Recorder(0,sim_length; record_degrees)
        
Peter Jentsch's avatar
Peter Jentsch committed
110
111
112
        return new{T,typeof(infected_mixing_graph),
        typeof(soc_mixing_graph),typeof(ws_matrix_tuple),
        typeof(rest_matrix_tuple), typeof(output_data)}(
113
114
115
116
117
118
119
            sim_length,
            nodes,
            params,
            u_0_inf,
            u_0_vac,
            copy(u_0_inf),
            copy(u_0_vac),
120
            covid_alert_notifications,
121
            time_of_last_alert,
122
123
            infected_mixing_graph,
            soc_mixing_graph,
124
125
126
127
            index_vectors,
            demographics,
            is_app_user,
            app_user_list,
128
129
            app_user_index,
            status_totals,
130
            ws_matrix_tuple,
131
            rest_matrix_tuple,
Peter Jentsch's avatar
Peter Jentsch committed
132
133
            immunization_countdown,
            output_data
134
135
136
        )
    end
end