Skip to content

Commit 5a60be8

Browse files
authored
Merge pull request #519 from CodeForPhilly/439-doubling-time-fit-mitigation
Fit the back-cast first admission date with mitigation in mind
2 parents 4ba3bed + 7c3b1b5 commit 5a60be8

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/penn_chime/models.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,40 @@ def __init__(self, p: Parameters):
6464
logger.info('Using doubling_time: %s', p.doubling_time)
6565

6666
intrinsic_growth_rate = get_growth_rate(p.doubling_time)
67-
6867
self.beta = get_beta(intrinsic_growth_rate, gamma, self.susceptible, 0.0)
6968
self.beta_t = get_beta(intrinsic_growth_rate, self.gamma, self.susceptible, p.relative_contact_rate)
7069

71-
self.i_day = 0 # seed to the full length
72-
raw = self.run_projection(p, [(self.beta, p.n_days)])
73-
self.i_day = i_day = int(get_argmin_ds(raw["census_hospitalized"], p.current_hospitalized))
70+
if p.mitigation_date is None:
71+
self.i_day = 0 # seed to the full length
72+
raw = self.run_projection(p, [(self.beta, p.n_days)])
73+
self.i_day = i_day = int(get_argmin_ds(raw["census_hospitalized"], p.current_hospitalized))
7474

75-
self.raw = self.run_projection(p, self.gen_policy(p))
75+
self.raw = self.run_projection(p, self.gen_policy(p))
76+
77+
logger.info('Set i_day = %s', i_day)
78+
else:
79+
projections = {}
80+
best_i_day = -1
81+
best_i_day_loss = float('inf')
82+
for i_day in range(p.n_days):
83+
self.i_day = i_day
84+
raw = self.run_projection(p, self.gen_policy(p))
85+
86+
# Don't fit against results that put the peak before the present day
87+
if raw["census_hospitalized"].argmax() < i_day:
88+
continue
89+
90+
loss = get_loss(raw["census_hospitalized"][i_day], p.current_hospitalized)
91+
if loss < best_i_day_loss:
92+
best_i_day_loss = loss
93+
best_i_day = i_day
94+
self.raw = raw
95+
96+
self.i_day = best_i_day
7697

77-
logger.info('Set i_day = %s', i_day)
78-
p.date_first_hospitalized = p.current_date - timedelta(days=i_day)
7998
logger.info(
8099
'Estimated date_first_hospitalized: %s; current_date: %s; i_day: %s',
81-
p.date_first_hospitalized,
100+
p.current_date - timedelta(days=self.i_day),
82101
p.current_date,
83102
self.i_day)
84103

0 commit comments

Comments
 (0)