Skip to content

Commit 715a022

Browse files
committed
implemented solution for death compartment problems
1 parent 70d8d7f commit 715a022

File tree

2 files changed

+105
-50
lines changed

2 files changed

+105
-50
lines changed

notebooks/bigHIVmodel.ipynb

Lines changed: 72 additions & 39 deletions
Large diffs are not rendered by default.

src/tapm/HIVandSTI/model_HIVandSTI.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"Ia_STI": 0.15 * N_0, # Infected asymptomatic
4242
"Is_STI": 0.15 * N_0, # Infected symptomatic
4343
"T_STI": 0.05 * N_0, # Tested and treated
44+
"D_STI": 0.0 * N_0, # Deceased from STI
4445

4546
# Hazard
4647
#"H": [0.0, 0.0, 0.0, 0.0] * N_0, # hazard
@@ -212,7 +213,7 @@ def foi_HIV(y, args):
212213
I_eff = args["epsilonP"]*y["IP"] \
213214
+ jnp.dot(args["h"], jnp.array([y["I1"], y["I2"], y["I3"], y["I4"]])) \
214215
+ args["epsilon"]*(y["A1"] + y["A2"] + y["A3"] + y["A4"])
215-
foi = args["Lambda"] * args["c"] * contact_matrix(args) @ (I_eff/args["N_0"])
216+
foi = args["Lambda"] * args["c"] * contact_matrix(y, args) @ (I_eff/alive_fraction_HIV(y))
216217

217218
return foi
218219

@@ -230,12 +231,12 @@ def foi_STI(y, args):
230231
"""
231232

232233
I_eff = y["Ia_STI"] + y["Is_STI"]
233-
foi = args["beta_STI"] * (1 - m(args, y)*(1 - prep_fraction(y)) ) * contact_matrix(args) @ I_eff
234+
foi = args["beta_STI"] * (1 - m(args, y)*(1 - prep_fraction(y)) ) * contact_matrix(y, args) @ (I_eff/alive_fraction_STI(y))
234235
return foi
235236

236-
def contact_matrix(args):
237+
def contact_matrix(y, args):
237238
# this is the matrix named M_ll' in the paper from GannaRozhnova
238-
mixing = args["omega"] * jnp.tile(args["c"]*args["N_0"], [4,1]) / jnp.dot(args["c"], args["N_0"])
239+
mixing = args["omega"] * jnp.tile(args["c"]*alive_fraction_HIV(y), [4,1]) / jnp.dot(args["c"], alive_fraction_HIV(y))
239240
diagonal = (1-args["omega"])*jnp.identity(4)
240241

241242
return mixing + diagonal
@@ -260,6 +261,24 @@ def prep_fraction(y):
260261
"""
261262
return jnp.sum( jnp.array([y["SP"], y["IP"]]) )
262263

264+
def alive_fraction_HIV(y):
265+
"""
266+
Calculates fraction of people alive in the HIV model.
267+
268+
Returns:
269+
Value as float64.
270+
"""
271+
return jnp.sum( jnp.array([y[comp] for comp in ["S", "SP", "I1", "IP", "I2", "I3", "I4", "A1", "A2", "A3", "A4"]]) )
272+
273+
def alive_fraction_STI(y):
274+
"""
275+
Calculates fraction of people alive in the STI model.
276+
277+
Returns:
278+
Value as float64.
279+
"""
280+
return jnp.sum( jnp.array([y[comp] for comp in ["S_STI", "Ia_STI", "Is_STI", "T_STI"]]) )
281+
263282
def lambda_a(y, args):
264283
"""
265284
Calculates STI testing rate for asymtomatic infected.
@@ -294,7 +313,6 @@ def add_flows(starts, ends, rates):
294313
# list of all compartments in one category
295314
Is = ["I1", "I2", "I3", "I4", "D"]
296315
As = ["A1", "A2", "A3", "A4", "D"]
297-
298316

299317
# HIV dynamics-------------------------------------------------------------------------------------------------------------------------------
300318
cm.flow("S", "I1", foi_HIV(y, args))
@@ -316,18 +334,22 @@ def add_flows(starts, ends, rates):
316334
# STI dynamics-------------------------------------------------------------------------------------------------------------------------------------------------
317335
cm.flow("S_STI", "Ia_STI", (args["Psi"]) * foi_STI(y, args)) # Susceptible to asymptomatic
318336
cm.flow("S_STI", "Is_STI", (1-args["Psi"]) * foi_STI(y, args)) # Susceptible to symptomatic
319-
cm.flow("Ia_STI", "S_STI", args["gamma_STI"]) # Asymptomatic to susceptible (recovery)
320-
cm.flow("Ia_STI", "T_STI", lambda_a(y,args)) # Asymptomatic to tested and treatment
321-
cm.flow("Is_STI", "T_STI", lambda_s(y,args)) # Symptomatic to tested and treatment
322-
cm.flow("T_STI", "S_STI", args["gammaT_STI"]) # Treatment to susceptible (immunity loss)
323-
cm.dy["S_STI"] -= args["Sigma"] # Influx
337+
cm.flow("Ia_STI", "S_STI", args["gamma_STI"]) # Asymptomatic to susceptible (recovery)
338+
cm.flow("Ia_STI", "T_STI", lambda_a(y,args)) # Asymptomatic to tested and treatment
339+
cm.flow("Is_STI", "T_STI", lambda_s(y,args)) # Symptomatic to tested and treatment
340+
cm.flow("T_STI", "S_STI", args["gammaT_STI"]) # Treatment to susceptible (immunity loss)
341+
cm.dy["S_STI"] -= args["Sigma"] # Influx
324342
cm.dy["Ia_STI"] += args["Psi"] * args["Sigma"] # Influx
325343
cm.dy["Is_STI"] += (1-args["Psi"]) * args["Sigma"] # Influx
344+
# INFO: Deaths from HIV also now in STI, however only susceptible people die
345+
cm.flow("S_STI", "D_STI", args["rhos"][-1] * y["I4"] / y["S_STI"]) # Deaths from HIV also have to be included in STI model
346+
cm.flow("S_STI", "D_STI", args["gammas"][-1] * y["A4"] / y["S_STI"])# Deaths from HIV also have to be included in STI model
347+
326348

327349
# Vital dynamics-----------------------------------------------------------------------------------------------------------------------------------------------
328350
# both HIV and STI
329351
for comp in cm.dy.keys():
330-
if comp not in ["D", "H"]:
352+
if comp not in ["H"]:
331353
cm.dy[comp] -= args["mu"] * y[comp] # deaths
332354
for comp in ["S", "S_STI"]:
333355
cm.dy[comp] += args["mu"] * args["N_0"] # recruitment ("births")

0 commit comments

Comments
 (0)