Commit aadbf813 authored by Chris Jewell's avatar Chris Jewell
Browse files

Fixed discretisation error in Rt calculation.

parent 5906375d
...@@ -271,6 +271,11 @@ def next_generation_matrix_fn(covar_data, param): ...@@ -271,6 +271,11 @@ def next_generation_matrix_fn(covar_data, param):
W = tf.constant(covar_data["W"], dtype=DTYPE) W = tf.constant(covar_data["W"], dtype=DTYPE)
N = tf.constant(covar_data["N"], dtype=DTYPE) N = tf.constant(covar_data["N"], dtype=DTYPE)
# Area in 100km^2
area = tf.convert_to_tensor(covariates["area"], DTYPE)
log_area = tf.math.log(area / 100000000.0) # log area in 100km^2
log_area = log_area - tf.reduce_mean(log_area)
w_idx = tf.clip_by_value(tf.cast(t, tf.int64), 0, W.shape[0] - 1) w_idx = tf.clip_by_value(tf.cast(t, tf.int64), 0, W.shape[0] - 1)
commute_volume = tf.gather(W, w_idx) commute_volume = tf.gather(W, w_idx)
xi = tf.where( xi = tf.where(
...@@ -285,18 +290,17 @@ def next_generation_matrix_fn(covar_data, param): ...@@ -285,18 +290,17 @@ def next_generation_matrix_fn(covar_data, param):
), ),
), ),
) )
beta = tf.math.exp(xi) eta = alpha_t_ + beta_area[:, tf.newaxis] * log_area
infec_rate = tf.math.exp(eta) * (
ngm = beta * (
tf.eye(Cstar.shape[0], dtype=state.dtype) tf.eye(Cstar.shape[0], dtype=state.dtype)
+ param["psi"] * commute_volume * Cstar / N[tf.newaxis, :] + param["psi"] * commute_volume * Cstar / N[tf.newaxis, :]
) ) / N[:, tf.newaxis]
ngm = ( infec_prob = (1.0 - tf.math.exp(-ngm))
ngm
* state[..., 0][..., tf.newaxis] expected_new_infec = infec_prob * state[..., 0][..., tf.newaxis]
/ (N[:, tf.newaxis] * tf.math.exp(param["gamma0"])) expected_infec_period = 1.0 / (1.0 - tf.math.exp(tf.math.exp(param['gamma0'])))
) ngm = expected_new_infec * expected_infec_period
return ngm return ngm
return fn return fn
Supports Markdown
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