model_setup.jl 4.47 KB
Newer Older
1 2 3 4 5
 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)
    
    sim_length = 500
    infection_introduction_day = 180

6
    params = (
7
        sim_length = sim_length,
8
        num_households = 5000,
9
        I_0_fraction = 0.003,
10
        β_y = 0.00122,
11
        β_m = 0.00068,
12
        β_o = 0.047,
13 14 15
        α_y = 0.4,
        α_m = 0.4,
        α_o = 0.4,
16
        recovery_rate = 1/5,
17 18 19
        π_base_y = -1.11,
        π_base_m = -1.16,
        π_base_o = -0.71,
Peter Jentsch's avatar
Peter Jentsch committed
20
        η = 0.5,
21
        κ = 0.0,
22
        ω = 0.0061,
Peter Jentsch's avatar
Peter Jentsch committed
23
        ω_en = 0.05,
24
        Γ = 0.906,
25
        ξ = 5.0,
Peter Jentsch's avatar
Peter Jentsch committed
26
        notification_parameter = 0.0005,
27
        vaccinator_prob = 0.6,
Peter Jentsch's avatar
Peter Jentsch committed
28
        app_user_fraction = 0.0,
Peter Jentsch's avatar
Peter Jentsch committed
29
        notification_threshold = 2,
30
        immunizing = true,
31
        immunization_delay = 14,
32 33
        immunization_intervals = [Intervals.Interval(60,81), Intervals.Interval(infection_introduction_day, sim_length)], 
        infection_introduction_day = infection_introduction_day,
34
        EN_intervals = Intervals.Interval(0.0,sim_length) ,
35
        ζ = 1.7
36 37 38
    )
    return params
end
Peter Jentsch's avatar
Peter Jentsch committed
39
function get_app_parameters()
Peter Jentsch's avatar
Peter Jentsch committed
40
    return merge(get_parameters(),(app_user_fraction = 0.3,))
Peter Jentsch's avatar
Peter Jentsch committed
41
end
Peter Jentsch's avatar
Peter Jentsch committed
42
function get_u_0(nodes,vaccinator_prob)
Peter Jentsch's avatar
Peter Jentsch committed
43
    is_vaccinator = rand(Random.default_rng(Threads.threadid()),nodes) .< vaccinator_prob
44 45 46 47
    status = fill(Susceptible,nodes)
    return status,is_vaccinator
end

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


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

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

Peter Jentsch's avatar
Peter Jentsch committed
95
        is_app_user = app_users(demographics,params.app_user_fraction)
Peter Jentsch's avatar
Peter Jentsch committed
96

Peter Jentsch's avatar
Peter Jentsch committed
97
        u_0_inf,u_0_vac = get_u_0(nodes,params.vaccinator_prob)
98

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

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