Skip to content

Commit 90d8288

Browse files
committed
Convert sequence of time-evolving beta parameter to a typed list
1 parent 93edbc2 commit 90d8288

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/penn_chime/models.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,10 @@ def run_projection(self, p):
166166
p.recovered,
167167
self.gamma,
168168
-self.i_day,
169-
self.beta, pre_mitigation_days,
170-
self.beta_t, post_mitigation_days
169+
[
170+
(self.beta, pre_mitigation_days),
171+
(self.beta_t, post_mitigation_days),
172+
]
171173
)
172174

173175
self.dispositions_df = build_dispositions_df(self.raw_df, self.rates, p.market_share, p.current_date)
@@ -233,7 +235,7 @@ def sir(
233235

234236

235237
def gen_sir(
236-
s: float, i: float, r: float, gamma: float, i_day: int, *args
238+
s: float, i: float, r: float, gamma: float, i_day: int, policies: List[Tuple[float, int]]
237239
) -> Generator[Tuple[int, float, float, float], None, None]:
238240
"""Simulate SIR model forward in time yielding tuples.
239241
Parameter order has changed to allow multiple (beta, n_days)
@@ -242,8 +244,7 @@ def gen_sir(
242244
s, i, r = (float(v) for v in (s, i, r))
243245
n = s + i + r
244246
d = i_day
245-
while args:
246-
beta, n_days, *args = args
247+
for beta, n_days in policies:
247248
for _ in range(n_days):
248249
yield d, s, i, r
249250
s, i, r = sir(s, i, r, beta, gamma, n)
@@ -253,11 +254,11 @@ def gen_sir(
253254

254255
def sim_sir_df(
255256
s: float, i: float, r: float,
256-
gamma: float, i_day: int, *args
257+
gamma: float, i_day: int, policies: List[Tuple[float, int]]
257258
) -> pd.DataFrame:
258259
"""Simulate the SIR model forward in time."""
259260
return pd.DataFrame(
260-
data=gen_sir(s, i, r, gamma, i_day, *args),
261+
data=gen_sir(s, i, r, gamma, i_day, policies),
261262
columns=("day", "susceptible", "infected", "recovered"),
262263
)
263264

tests/penn_chime/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_sim_sir():
6464
Rounding to move fast past decimal place issues
6565
"""
6666
raw_df = sim_sir_df(
67-
5, 6, 7, 0.1, 0, 0.1, 40, # s # i # r # gamma # i_day # beta1 # n_days1
67+
5, 6, 7, 0.1, 0, [(0.1, 40)], # s # i # r # gamma # i_day # beta1 # n_days1
6868
)
6969

7070
first = raw_df.iloc[0, :]

0 commit comments

Comments
 (0)