Skip to content

Commit

Permalink
Fix infectious duration issue.
Browse files Browse the repository at this point in the history
Also, make sure infectious duration is at least one day.
  • Loading branch information
clorton committed Jan 16, 2024
1 parent b57c541 commit 9358034
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions tests/test_agentsir.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def test_sir(params):
# consider including +1 since the first action in processing is to decrement the infection timer
initial_infs = prng.choice(community.count, size=params.initial_inf, replace=False)
# prng.normal() _could_ draw negative numbers, consider making the minimum initial timer 1 day
community.itimer[initial_infs] = prng.normal(params.inf_mean, params.inf_std, size=params.initial_inf).round().astype(ITIMER_TYPE_NP)
community.itimer[initial_infs] = (
prng.normal(params.inf_mean, params.inf_std, size=params.initial_inf).round().astype(ITIMER_TYPE_NP).clip(min=1) + 1
)
community.susceptibility[initial_infs] = 0

# We do the dance seen below a couple of times because Numba doesn't know what it can
Expand Down Expand Up @@ -118,7 +120,14 @@ def transmission_inner(susceptibility, itimer, targets, actual, inf_mean, inf_st
target = targets[i]
if np.random.random_sample() < susceptibility[target]:
susceptibility[target] = 0
itimer[target] = ITIMER_TYPE_NP(np.round(np.random.normal(inf_mean, inf_std)))
# Add 1 because the first action in processing is to decrement the infection timer
# So, for example, if the timer is initially 1, it will be set to 0 and the individual
# will be removed from the infected pool before they have a chance to infect anyone.
timer = np.round(np.random.normal(inf_mean, inf_std))
if timer < 1:
timer = 1
timer = timer + 1
itimer[target] = ITIMER_TYPE_NP(timer)

return

Expand Down Expand Up @@ -147,7 +156,14 @@ def transmission_inner(susceptibility, itimer, count, beta, inf_mean, inf_std):
for i in nb.prange(count):
if np.random.random_sample() < (force * susceptibility[i]):
susceptibility[i] = 0
itimer[i] = ITIMER_TYPE_NP(np.round(np.random.normal(inf_mean, inf_std)))
# Add 1 because the first action in processing is to decrement the infection timer
# So, for example, if the timer is initially 1, it will be set to 0 and the individual
# will be removed from the infected pool before they have a chance to infect anyone.
timer = np.round(np.random.normal(inf_mean, inf_std))
if timer < 1:
timer = 1
timer = timer + 1
itimer[i] = ITIMER_TYPE_NP(timer)

return

Expand Down

0 comments on commit 9358034

Please sign in to comment.