np.random.seed(33) Bihar = SIR("Bihar", 99_000_000, dT0=T_pred[-1], Rt0=Rt_pred[-1], lower_CI=T_CI_lower[-1], upper_CI=T_CI_upper[-1], mobility=0) Bihar.run(14) t_pred = [dates[-1] + pd.Timedelta(days=i) for i in range(len(Bihar.dT))] plt.daily_cases(dates, T_pred[1:], T_CI_upper[1:], T_CI_lower[1:], new_cases_ts[1:], anomaly_dates, anomalies, CI, prediction_ts = [ (Bihar.dT, Bihar.lower_CI, Bihar.upper_CI, None, "predicted cases") ])\ .title("\nBihar: New Daily Cases")\ .annotate(f"data from {str(dates[0]).split()[0]} to {str(dates[-1]).split()[0]}; predictions until {str(t_pred[-1]).split()[0]}")\ .xlabel("date").ylabel("cases")\ .show() # now, do district-level estimation smoothing = 10 state_cases["geo_reported"] = state_cases.geo_reported.str.strip() district_time_series = state_cases.groupby( ["geo_reported", "date_reported"])["date_reported"].count().sort_index() migration = np.zeros((len(district_names), len(district_names))) estimates = [] max_len = 1 + max(map(len, district_names)) with tqdm(etl.normalize(district_names)) as districts: for district in districts: districts.set_description(f"{district :<{max_len}}")
] model = lambda: Model.single_unit(name=state, RR0=Rt_pred[-1], population=pop, infectious_period=infectious_period, I0=T_pred[-1], lower_CI=T_CI_lower[-1], upper_CI=T_CI_upper[-1], random_seed=33) forward_pred_period = 9 t_pred = [ dates[-1] + pd.Timedelta(days=i) for i in range(forward_pred_period + 1) ] current = model().run(forward_pred_period) target = simulate_PID_controller(model(), 0, forward_pred_period) plt.Rt(dates, Rt_pred, Rt_CI_upper, Rt_CI_lower, CI, ymin = 0, ymax = 5, yaxis_colors = False)\ .adjust(left = 0.10, right = 0.95, bottom = 0.15, top = 0.95)\ .xlabel("date")\ .ylabel("$R_t$")\ .show() plt.daily_cases(dates, T_pred, T_CI_upper, T_CI_lower, new_cases_ts, anomaly_dates, anomalies, CI, prediction_ts = [ (current[0].delta_T[1:], current[0].lower_CI[1:], current[0].upper_CI[1:], "orange", r"projection with current $R_t$"), (target[0].delta_T[1:], target[0].lower_CI[1:], target[0].upper_CI[1:], "green", r"projection with $R_t \rightarrow 0.9$") ])\ .adjust(left = 0.10, right = 0.95, bottom = 0.15, top = 0.95)\ .xlabel("date")\ .ylabel("cases")\ .show()
.ylabel("$R_t$\n", rotation=0, labelpad=30)\ .annotate(f"\n{window}-day smoothing window, gamma-prior Bayesian estimation method")\ .show() logger.info("running case-forward prediction") prediction_period = 14 * days I0 = (~cases.confirmed.isna()).sum() - (~cases.recovered.isna()).sum() - ( ~cases.died.isna()).sum() IDN = SIR(name = "IDN", population = 8_819_500, dT0 = T_pred[-1], Rt0 = Rt_pred[-1], upper_CI = T_CI_upper[-1], lower_CI = T_CI_lower[-1], mobility = 0, random_seed = 0, I0 = I0)\ .run(prediction_period) plt.daily_cases(dates, T_pred, T_CI_upper, T_CI_lower, new_cases_ts, anomaly_dates, anomalies, CI, prediction_ts = [ (IDN.dT[:-1], IDN.lower_CI[1:], IDN.upper_CI[1:], plt.PRED_PURPLE, "predicted cases") ])\ .title("\nSouth Sulawesi: Daily Cases")\ .xlabel("\ndate")\ .ylabel("cases\n")\ .annotate("\nBayesian training process on empirical data, with anomalies identified")\ .show() # makassar estimates mak_cases = cases[cases.regency == "Makassar"] mak_new_cases = mak_cases.confirmed.value_counts().sort_index() logger.info("running city-level Rt estimate") (dates, Rt_pred, Rt_CI_upper, Rt_CI_lower, T_pred, T_CI_upper, T_CI_lower, total_cases, new_cases_ts, anomalies, anomaly_dates)\ = analytical_MPVS(mak_new_cases, CI = CI, smoothing = smoothing, totals = False) plt.Rt(dates, Rt_pred, Rt_CI_upper, Rt_CI_lower, CI)\ .title("\nMakassar: Reproductive Number Estimate")\ .xlabel("\ndate")\
.xlabel("\ndate")\ .ylabel("$R_t$\n", rotation=0, labelpad=30)\ .annotate(f"\n{window}-day smoothing window, gamma-prior Bayesian estimation method")\ .show() logger.info("running case-forward prediction") prediction_period = 14*days IDN = SIR(name = "IDN", population = 267.7e6, dT0 = T_pred[-1], Rt0 = RR_pred[-1], upper_CI = T_CI_upper[-1], lower_CI = T_CI_lower[-1], mobility = 0, random_seed = 0)\ .run(prediction_period) plt.daily_cases(dates, T_pred[1:], T_CI_upper[1:], T_CI_lower[1:], new_cases_ts[1:], anomaly_dates, anomalies, CI, prediction_ts = [ (IDN.dT[:-1], IDN.lower_CI[1:], IDN.upper_CI[1:], None, "predicted cases") ])\ .title("\nDKI Jakarta: Daily Cases")\ .xlabel("\ndate")\ .ylabel("cases\n")\ .annotate("\nBayesian training process on empirical data, with anomalies identified")\ .show() logger.info("district-level projections") district_cases = dkij.groupby(["district", "date_positiveresult"])["id"].count().sort_index() districts = dkij.district.unique() migration = np.zeros((len(districts), len(districts))) estimates = [] max_len = 1 + max(map(len, districts)) with tqdm(districts) as progress: for district in districts: progress.set_description(f"{district :<{max_len}}") (dates, RR_pred, RR_CI_upper, RR_CI_lower, *_) = analytical_MPVS(district_cases.loc[district], CI = CI, smoothing = smoothing, totals=False)
(dates, Rt_pred, Rt_CI_upper, Rt_CI_lower, T_pred, T_CI_upper, T_CI_lower, total_cases, new_cases_ts, anomalies, anomaly_dates)\ = analytical_MPVS(age_ts.sum(level = 1), CI = CI, smoothing = smoothing, totals = False) MAK = SIR(name="MAK", population=1.339e6, dT0=T_pred[-1], Rt0=Rt_pred[-1], upper_CI=T_CI_upper[-1], lower_CI=T_CI_lower[-1], mobility=0, random_seed=0, I0=age_ts.sum(level=1).sum()).run(30) plt.daily_cases(dates, T_pred, T_CI_upper, T_CI_lower, new_cases_ts, anomaly_dates, anomalies, CI, prediction_ts = [ (MAK.dT[:-1], MAK.lower_CI[1:], MAK.upper_CI[1:], plt.PRED_PURPLE, "current social distancing"), (*rt1_10x, "orange", "10% increase in school-age $R_t$"), (*rt1_25x, "mediumseagreen", "25% increase in school-age $R_t$"), (*rt1_50x, "hotpink", "50% increase in school-age $R_t$"), ])\ .xlabel("\ndate")\ .ylabel("cases\n") # .title("\nMakassar Daily Cases - school reopening scenarios")\ # .annotate("\nBayesian training process on empirical data, with anomalies identified") (_, r) = plt.xlim() plt.xlim(left=pd.Timestamp("Sep 1, 2020"), right=r) plt.ylim(bottom=10, top=1000) plt.vlines(dates[-1], ymin=1, ymax=1000, color="black", linestyles="solid") plt.semilogy() plt.show()