Skip to content

Commit c290883

Browse files
committed
added two new modulations
1 parent b7ee044 commit c290883

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

src/params/modulations.jl

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@ function evalmodulation(f::TanhModulation, state::AbstractSimState, ::AbstractSi
2424
tanh_modulation(fear, f.loc, f.scale, 1.0, f.limit_value)
2525
end
2626

27+
struct TwoTanhModulations <: InfectionModulation
28+
weight_detected::Float64
29+
weight_deaths::Float64
30+
weight_days::Float64
31+
loc1::Float64
32+
scale1::Float64
33+
limit_value1::Float64
34+
loc2::Float64
35+
scale2::Float64
36+
limit_value2::Float64
37+
38+
TwoTanhModulations(;weight_detected::Real=0, weight_deaths::Real=0, weight_days::Real=0, loc1::Real=0, scale1::Real=0, limit_value1::Real=0, loc2::Real=0, scale2::Real=0, limit_value2::Real=0) =
39+
0 <= limit_value2 <= limit_value1 <= 1 && loc1 < loc2 ? new(weight_detected, weight_deaths, weight_days, loc1, scale1, limit_value1, loc2, scale2, limit_value2) : error("initial_value1 and initial_value2 must be from 0 to 1 and initial_value2 must be not larger than initial_value1, got ($initial_value1, $initial_value2), also loc2 must be after loc1, got ($loc1, $loc2)")
40+
end
41+
42+
function evalmodulation(f::TwoTanhModulations, state::AbstractSimState, ::AbstractSimParams)::Float64
43+
num_days = time(state)
44+
num_detected = numdetected(state)
45+
num_deaths = numdead(state)
46+
fear = num_detected * f.weight_detected + num_deaths * f.weight_deaths + num_days * f.weight_days
47+
modulation1 = tanh_modulation(fear, f.loc1, f.scale1, 1.0, f.limit_value1)
48+
tanh_modulation(fear, f.loc2, f.scale2, modulation1, f.limit_value2)
49+
end
50+
2751
struct IncreasingTanhModulation <: InfectionModulation
2852
weight_detected::Float64
2953
weight_deaths::Float64
@@ -45,6 +69,31 @@ function evalmodulation(f::IncreasingTanhModulation, state::AbstractSimState, ::
4569
tanh_modulation(fear, f.loc, f.scale, f.initial_value, 1.0)
4670
end
4771

72+
struct IncreasingTwoTanhModulations <: InfectionModulation
73+
weight_detected::Float64
74+
weight_deaths::Float64
75+
weight_days::Float64
76+
loc1::Float64
77+
scale1::Float64
78+
initial_value1::Float64
79+
loc2::Float64
80+
scale2::Float64
81+
initial_value2::Float64
82+
83+
IncreasingTwoTanhModulations(;weight_detected::Real=0, weight_deaths::Real=0, weight_days::Real=0, loc1::Real=0, scale1::Real=0, initial_value1::Real=0, loc2::Real=0, scale2::Real=0, initial_value2::Real=0) =
84+
0 <= initial_value1 <= initial_value2 <= 1 && loc1 < loc2 ? new(weight_detected, weight_deaths, weight_days, loc1, scale1, initial_value1, loc2, scale2, initial_value2) : error("initial_value1 and initial_value2 must be from 0 to 1 and initial_value2 must be not smaller than initial_value1, got ($initial_value1, $initial_value2), also loc2 must be after loc1, got ($loc1, $loc2)")
85+
end
86+
87+
function evalmodulation(f::IncreasingTwoTanhModulations, state::AbstractSimState, ::AbstractSimParams)::Float64
88+
num_days = time(state)
89+
num_detected = numdetected(state)
90+
num_deaths = numdead(state)
91+
92+
fear = num_detected * f.weight_detected + num_deaths * f.weight_deaths + num_days * f.weight_days
93+
modulation1 = tanh_modulation(fear, f.loc1, f.scale1, f.initial_value1, f.initial_value2)
94+
tanh_modulation(fear, f.loc2, f.scale2, modulation1, 1.0)
95+
end
96+
4897
evalmodulation(modulation::Nothing, state::AbstractSimState, params::AbstractSimParams)::Float64 = 1.0
4998

5099
function infectionsuccess(modulation::InfectionModulation, state::AbstractSimState, params::AbstractSimParams, event::Event)::Bool
@@ -77,7 +126,9 @@ end
77126
# This all to avoid using @eval and others
78127
const modulations = Dict{String, Type{T} where T}(
79128
"TanhModulation" => TanhModulation,
80-
"IncreasingTanhModulation" => IncreasingTanhModulation
129+
"TwoTanhModulations" => TwoTanhModulations,
130+
"IncreasingTanhModulation" => IncreasingTanhModulation,
131+
"IncreasingTwoTanhModulations" => IncreasingTwoTanhModulations
81132
)
82133

83134
make_infection_modulation(::Nothing) = nothing

0 commit comments

Comments
 (0)