Commit 3df0dd34 authored by Chris Jewell's avatar Chris Jewell
Browse files

Fix for weekday effect in prediction

Previously, when generating forward predictions, the model used the latest value of
gamma1 for all time points.  This created a prediction artefact depending on what the
last day of the observed timeseries was.   This is now corrected by projecting the weekday
forward in time.
parent 45a79675
......@@ -3,6 +3,7 @@
import numpy as np
import xarray
import pickle as pkl
import pandas as pd
import tensorflow as tf
from covid import model_spec
......@@ -75,11 +76,17 @@ def predict(data, posterior_samples, output_file, initial_step, num_steps):
origin_date = np.array(cases.coords["time"][0])
dates = np.arange(
origin_date + np.timedelta64(initial_step, "D"),
origin_date,
origin_date + np.timedelta64(initial_step + num_steps, "D"),
np.timedelta64(1, "D"),
)
covar_data["weekday"] = xarray.DataArray(
(pd.to_datetime(dates).weekday < 5).astype(model_spec.DTYPE),
coords=[dates],
dims=["prediction_time"],
)
estimated_init_state, predicted_events = predicted_incidence(
samples, initial_state, covar_data, initial_step, num_steps
)
......@@ -89,7 +96,7 @@ def predict(data, posterior_samples, output_file, initial_step, num_steps):
coords=[
np.arange(predicted_events.shape[0]),
covar_data.coords["location"],
dates,
dates[initial_step:],
np.arange(predicted_events.shape[3]),
],
dims=("iteration", "location", "time", "event"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment