Skip to content

Commit 676dd21

Browse files
authored
Cleanup model
Cleanup model
2 parents 865cfba + 40165c8 commit 676dd21

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

src/penn_chime/models.py

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,49 +42,30 @@ def __init__(self, p: Parameters):
4242

4343
self.keys = ("susceptible", "infected", "recovered")
4444

45+
# An estimate of the number of infected people on the day that
46+
# the first hospitalized case is seen
47+
#
4548
# Note: this should not be an integer.
46-
# We're appoximating infected from what we do know.
47-
# TODO market_share > 0, hosp_rate > 0
4849
infected = (
4950
1.0 / p.market_share / p.hospitalized.rate
5051
)
5152

5253
susceptible = p.population - infected
5354

54-
intrinsic_growth_rate = get_growth_rate(p.doubling_time)
55-
5655
gamma = 1.0 / p.infectious_days
57-
58-
# Contact rate, beta
59-
beta = (
60-
(intrinsic_growth_rate + gamma)
61-
/ susceptible
62-
* (1.0 - p.relative_contact_rate)
63-
) # {rate based on doubling time} / {initial susceptible}
64-
65-
# r_t is r_0 after distancing
66-
r_t = beta / gamma * susceptible
67-
68-
# Simplify equation to avoid division by zero:
69-
# self.r_naught = r_t / (1.0 - relative_contact_rate)
70-
r_naught = (intrinsic_growth_rate + gamma) / gamma
56+
self.gamma = gamma
7157

7258
self.susceptible = susceptible
7359
self.infected = infected
7460
self.recovered = p.recovered
7561

76-
self.beta = beta
77-
self.gamma = gamma
78-
self.beta_t = get_beta(intrinsic_growth_rate, self.gamma, self.susceptible, p.relative_contact_rate)
79-
self.intrinsic_growth_rate = intrinsic_growth_rate
80-
8162
if p.date_first_hospitalized is None and p.doubling_time is not None:
63+
# Back-projecting to when the first hospitalized case would have been admitted
8264
logger.info('Using doubling_time: %s', p.doubling_time)
83-
self.i_day = 0
84-
self.beta = (
85-
(intrinsic_growth_rate + gamma)
86-
/ susceptible
87-
)
65+
66+
intrinsic_growth_rate = get_growth_rate(p.doubling_time)
67+
68+
self.beta = get_beta(intrinsic_growth_rate, gamma, self.susceptible, 0.0)
8869

8970
self.i_day = 0 # seed to the full length
9071
self.beta_t = self.beta
@@ -94,8 +75,6 @@ def __init__(self, p: Parameters):
9475
self.beta_t = get_beta(intrinsic_growth_rate, self.gamma, self.susceptible, p.relative_contact_rate)
9576
self.run_projection(p)
9677

97-
self.r_t = self.beta_t / gamma * susceptible
98-
self.r_naught = self.beta / gamma * susceptible
9978
logger.info('Set i_day = %s', i_day)
10079
p.date_first_hospitalized = p.current_date - timedelta(days=i_day)
10180
logger.info(
@@ -105,6 +84,7 @@ def __init__(self, p: Parameters):
10584
self.i_day)
10685

10786
elif p.date_first_hospitalized is not None and p.doubling_time is None:
87+
# Fitting spread parameter to observed hospital census (dates of 1 patient and today)
10888
self.i_day = (p.current_date - p.date_first_hospitalized).days
10989
logger.info(
11090
'Using date_first_hospitalized: %s; current_date: %s; i_day: %s',
@@ -131,7 +111,6 @@ def __init__(self, p: Parameters):
131111
self.beta_t = get_beta(intrinsic_growth_rate, self.gamma, self.susceptible, p.relative_contact_rate)
132112
self.run_projection(p)
133113

134-
self.intrinsic_growth_rate = intrinsic_growth_rate
135114
self.population = p.population
136115
else:
137116
logger.info(
@@ -148,6 +127,9 @@ def __init__(self, p: Parameters):
148127
self.susceptible = self.raw_df['susceptible'].values[self.i_day]
149128
self.recovered = self.raw_df['recovered'].values[self.i_day]
150129

130+
self.intrinsic_growth_rate = intrinsic_growth_rate
131+
132+
# r_t is r_0 after distancing
151133
self.r_t = self.beta_t / gamma * susceptible
152134
self.r_naught = self.beta / gamma * susceptible
153135

0 commit comments

Comments
 (0)