Watts-May SEIR with lasting partnerships
The SEIR epidemic of Watts and May.
- Class:
WattsMayConcurrencySystem - Import:
from skcomplex.systems.biology.epidemiology import WattsMayConcurrencySystem - Field:
biology/epidemiology - Topics:
concurrency,partnerships,seir,delay,hiv - References:
- Watts and May 1992
- Masuda, Miller, and Holme 2021
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.biology.epidemiology import WattsMayConcurrencySystem
trajectory = WattsMayConcurrencySystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
infected |
0.01 |
c |
2.0 |
beta |
0.2 |
tau |
1.0 |
T |
0.5 |
nu |
0.1 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | continuous |
| Space | none |
| Laws | rate |
| Randomness | unknown |
| Domains | real |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class WattsMayConcurrencySystem(BaseSystem):
"""The SEIR epidemic of Watts and May.
Partnerships that last longer spread the infection faster.
A susceptible person is infected at the rate `pi(t) = c beta [I / (S + E + I) + int exp(-(t - t') / tau) pi(t' - T)
S(t' - T) / (S + E + I)(t') dt']`, by a new partner who is infectious or by a current partner who turned infectious
during the partnership. The mean number of current partners is `c tau`, so a longer partnership raises the mean
degree of the momentary network, and the infection rate grows with `tau` at fixed `c` and `beta`. The system has the
fractions `population.S`, `population.E`, `population.I`, `population.R`, and the infection memory `population.J`.
Args:
infected:
The initial fraction of infectious people.
c:
The rate of acquiring new partners.
beta:
The probability of infection by an infectious partner over a partnership.
tau:
The mean duration of a partnership.
T:
The duration of the exposed period.
nu:
The rate at which the infectious develop the disease.
label:
The label of the system, which names it when it is nested in another one.
solver:
The solver of the problem, or `'auto'` for the one the system chooses.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Examples:
>>> from skcomplex.systems.biology.epidemiology import WattsMayConcurrencySystem
>>> WattsMayConcurrencySystem(tau=3.0).prepare().system_.interactions[0].tau
3.0
"""
field = 'biology/epidemiology'
topics = ('concurrency', 'partnerships', 'seir', 'delay', 'hiv')
references = ('Watts and May 1992', 'Masuda, Miller, and Holme 2021')
until = 40.0
dt = 0.25
def __init__(
self,
infected: float = 0.01,
*,
c: float = 2.0,
beta: float = 0.2,
tau: float = 1.0,
T: float = 0.5,
nu: float = 0.1,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.infected = infected
self.c = c
self.beta = beta
self.tau = tau
self.T = T
self.nu = nu
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of the SEIR epidemic of Watts and May.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
population = PartnershipEpidemicElement(
'population',
S=1 - self.infected,
I=self.infected,
values={'I[-1]': 0.0, 'J[-1]': 0.0},
)
infection = PartnershipInfectionInteraction(
'infection',
target='population',
c=self.c,
beta=self.beta,
tau=self.tau,
T=self.T,
nu=self.nu,
)
self.system_ = System(self.label, elements=[population], interactions=[infection])
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
PartnershipEpidemicElement, fromElement
Interactions:
PartnershipInfectionInteraction, fromInteraction
class PartnershipEpidemicElement(Element):
"""Population of Watts and May, as fractions of susceptible, exposed, infectious, and removed people.
The infection memory `J` is the infection by current partners who turned infectious after the partnership formed.
Args:
label:
The label of the population.
S:
The initial fraction of susceptible people.
E:
The initial fraction of exposed people.
I:
The initial fraction of infectious people.
R:
The initial fraction of people who developed the disease.
J:
The initial infection memory of current partnerships.
values:
Further values by name, such as the infectious before the start `'I[-1]'`.
Examples:
>>> from skcomplex.systems.biology.epidemiology import PartnershipEpidemicElement
>>> PartnershipEpidemicElement('population').S
0.99
"""
def __init__(
self,
label: str,
*,
S: Annotated[float, FRACTION] = 0.99,
E: Annotated[float, FRACTION] = 0.0,
I: Annotated[float, FRACTION] = 0.01,
R: Annotated[float, FRACTION] = 0.0,
J: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
values: Mapping[str, object] | None = None,
) -> None:
super().__init__(label, values=values)
self.S = S
self.E = E
self.I = I
self.R = R
self.J = J
class PartnershipInfectionInteraction(Interaction):
"""Infection of Watts and May along lasting partnerships, with a fixed exposed period.
Susceptible people `S` acquire new partners at the rate `c`, each infecting with the probability `beta` over the
partnership, and are infected at the rate `pi = c beta (I / A + J)` with the active population `A = S + E + I`. The
first term is the infection by a new partner who is infectious, and the memory `J` is the infection by a current
partner who turned infectious after the partnership formed, `dJ/dt = pi(t - T) S(t - T) / A - J / tau`, where
partnerships last a mean time `tau`. The exposed `E` turn infectious after the fixed time `T`, and the infectious
`I` develop the disease, which ends their sexual activity, at the rate `nu`, into `R`.
Args:
label:
The label of the interaction.
target:
The path of the population.
c:
The rate of acquiring new partners.
beta:
The probability of infection by an infectious partner over a partnership.
tau:
The mean duration of a partnership.
T:
The duration of the exposed period.
nu:
The rate at which the infectious develop the disease.
Examples:
>>> from skcomplex.systems.biology.epidemiology import PartnershipInfectionInteraction
>>> PartnershipInfectionInteraction('infection', target='population').tau
1.0
"""
def __init__(
self,
label: str,
*,
target: Role,
c: Annotated[float, RealSet.closed_open(0, oo)] = 2.0,
beta: Annotated[float, FRACTION] = 0.2,
tau: Annotated[float, RealSet.open(0, oo)] = 1.0,
T: Annotated[float, RealSet.open(0, oo)] = 0.5,
nu: Annotated[float, RealSet.closed_open(0, oo)] = 0.1,
) -> None:
super().__init__(label)
self.target = target
self.c = c
self.beta = beta
self.tau = tau
self.T = T
self.nu = nu
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the infection by new and current partners, the exposed period, and the progression.
Args:
context:
The namespace of the population.
"""
super()._prepare(context)
s, t = context.target, context.t
S, E, I, R, J = s.S, s.E, s.I, s.R, s.J
active = S + E + I
infection = context.c * context.beta * (I / active + J) * S
past = [state(t=t - context.T) for state in (S, E, I, J)]
past_active = past[0] + past[1] + past[2]
matured = context.c * context.beta * (past[2] / past_active + past[3]) * past[0]
self.laws_ = [
RateLaw(S.diff(t), -infection),
RateLaw(E.diff(t), infection - matured),
RateLaw(I.diff(t), matured - context.nu * I),
RateLaw(R.diff(t), context.nu * I),
RateLaw(J.diff(t), matured / active - J / context.tau),
]
Equations
The equations are those that symbolic returns for the system with its default parameters.
population.S: diff(S_population(t), t) == -beta_infection*c_infection*(I_population(t)/(E_population(t) + I_population(t) + S_population(t)) + J_population(t))*S_population(t)
population.E: diff(E_population(t), t) == -beta_infection*c_infection*(I_population(-T_infection + t)/(E_population(-T_infection + t) + I_population(-T_infection + t) + S_population(-T_infection + t)) + J_population(-T_infection + t))*S_population(-T_infection + t) + beta_infection*c_infection*(I_population(t)/(E_population(t) + I_population(t) + S_population(t)) + J_population(t))*S_population(t)
population.I: diff(I_population(t), t) == beta_infection*c_infection*(I_population(-T_infection + t)/(E_population(-T_infection + t) + I_population(-T_infection + t) + S_population(-T_infection + t)) + J_population(-T_infection + t))*S_population(-T_infection + t) - nu_infection*I_population(t)
population.R: diff(R_population(t), t) == nu_infection*I_population(t)
population.J: diff(J_population(t), t) == beta_infection*c_infection*(I_population(-T_infection + t)/(E_population(-T_infection + t) + I_population(-T_infection + t) + S_population(-T_infection + t)) + J_population(-T_infection + t))*S_population(-T_infection + t)/(E_population(t) + I_population(t) + S_population(t)) - J_population(t)/tau_infection