Skip to content

Commit fc8f7bc

Browse files
committed
Merge from develop
2 parents a0e2c6d + bc8f45b commit fc8f7bc

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM python:3.7.7-slim-buster
22
ENV PARAMETERS=./defaults/webapp.cfg
33
ENV PPE_FOLDER=./defaults/assets/
4-
ENV STREAMLIT_SERVER_PORT=$PORT
4+
ENV PORT=8000
55
WORKDIR /app
66
COPY README.md .
77
COPY setup.cfg .
@@ -14,4 +14,3 @@ COPY st_app.py st_app.py
1414
RUN pip install -q .
1515

1616
CMD STREAMLIT_SERVER_PORT=$PORT streamlit run st_app.py
17-
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Contributing: Operations Support
22

3-
*Coming soon*
3+
- This repo is associated with Penn Medicine's Chime1.0 model, which uses a Streamlit app that is built on an SIR model
4+
- Contributors are encouraged to consider supporting Penn Medicine's Chime2.0 model, which still uses a Streamlit app, but leverages an enhanced Bayesian SEIR model.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Setup file for chime
22
"""
3-
__version__ = "1.1.3" # update VERSION in constants.py
3+
__version__ = "1.1.4" # update VERSION in constants.py
44
__author__ = "Predictive Healthcare @ Penn Medicine"
55

66
from setuptools import setup, find_namespace_packages

src/penn_chime/constants.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
re-run their reports
99
"""
1010
CHANGE_DATE = date(year=2020, month=4, day=8)
11-
VERSION = 'v1.1.3'
11+
VERSION = 'v1.1.4'
1212

1313
DATE_FORMAT = "%b, %d" # see https://strftime.org
1414
DOCS_URL = "https://code-for-philly.gitbook.io/chime"
@@ -17,3 +17,5 @@
1717

1818
FLOAT_INPUT_MIN = 0.0001
1919
FLOAT_INPUT_STEP = 0.1
20+
21+
PREFIT_ADDITIONAL_DAYS = 300

src/penn_chime/model/sir.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import numpy as np
1515
import pandas as pd
1616

17+
from ..constants import PREFIT_ADDITIONAL_DAYS
1718
from .parameters import Parameters
1819

1920

@@ -68,31 +69,42 @@ def __init__(self, p: Parameters):
6869

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

74-
self.raw = self.run_projection(p, self.gen_policy(p))
76+
self.raw = self.run_projection(p, self.get_policies(p))
7577

7678
logger.info('Set i_day = %s', i_day)
7779
else:
78-
projections = {}
7980
best_i_day = -1
8081
best_i_day_loss = float('inf')
81-
for i_day in range(p.n_days):
82-
self.i_day = i_day
83-
raw = self.run_projection(p, self.gen_policy(p))
82+
for self.i_day in range(p.n_days + PREFIT_ADDITIONAL_DAYS):
83+
mitigation_day = -(p.current_date - p.mitigation_date).days
84+
if mitigation_day < -self.i_day:
85+
mitigation_day = -self.i_day
86+
87+
total_days = self.i_day + p.n_days + PREFIT_ADDITIONAL_DAYS
88+
pre_mitigation_days = self.i_day + mitigation_day
89+
post_mitigation_days = total_days - pre_mitigation_days
90+
91+
raw = self.run_projection(p, [
92+
(self.beta, pre_mitigation_days),
93+
(self.beta_t, post_mitigation_days),
94+
]
95+
)
8496

8597
# Don't fit against results that put the peak before the present day
86-
if raw["census_hospitalized"].argmax() < i_day:
98+
if raw["census_hospitalized"].argmax() < self.i_day:
8799
continue
88100

89-
loss = get_loss(raw["census_hospitalized"][i_day], p.current_hospitalized)
101+
loss = get_loss(raw["census_hospitalized"][self.i_day], p.current_hospitalized)
90102
if loss < best_i_day_loss:
91103
best_i_day_loss = loss
92-
best_i_day = i_day
93-
self.raw = raw
104+
best_i_day = self.i_day
94105

95106
self.i_day = best_i_day
107+
self.raw = self.run_projection(p, self.get_policies(p))
96108

97109
logger.info(
98110
'Estimated date_first_hospitalized: %s; current_date: %s; i_day: %s',
@@ -127,7 +139,7 @@ def __init__(self, p: Parameters):
127139
intrinsic_growth_rate = get_growth_rate(p.doubling_time)
128140
self.beta = get_beta(intrinsic_growth_rate, self.gamma, self.susceptible, 0.0)
129141
self.beta_t = get_beta(intrinsic_growth_rate, self.gamma, self.susceptible, p.relative_contact_rate)
130-
self.raw = self.run_projection(p, self.gen_policy(p))
142+
self.raw = self.run_projection(p, self.get_policies(p))
131143

132144
self.population = p.population
133145
else:
@@ -205,7 +217,7 @@ def get_argmin_doubling_time(self, p: Parameters, dts):
205217
self.beta = get_beta(intrinsic_growth_rate, self.gamma, self.susceptible, 0.0)
206218
self.beta_t = get_beta(intrinsic_growth_rate, self.gamma, self.susceptible, p.relative_contact_rate)
207219

208-
raw = self.run_projection(p, self.gen_policy(p))
220+
raw = self.run_projection(p, self.get_policies(p))
209221

210222
# Skip values the would put the fit past peak
211223
peak_admits_day = raw["admits_hospitalized"].argmax()
@@ -219,7 +231,7 @@ def get_argmin_doubling_time(self, p: Parameters, dts):
219231
min_loss = pd.Series(losses).argmin()
220232
return min_loss
221233

222-
def gen_policy(self, p: Parameters) -> Sequence[Tuple[float, int]]:
234+
def get_policies(self, p: Parameters) -> Sequence[Tuple[float, int]]:
223235
if p.mitigation_date is not None:
224236
mitigation_day = -(p.current_date - p.mitigation_date).days
225237
else:

0 commit comments

Comments
 (0)