Epidemiology
Epidemiology systems of infection and recovery.
The systems are compartmental, network, metapopulation, and agent-based.
ActiveHostElement(label, *, i=0.0, a=0.1, lam=0.3, mu=0.1, space=None)
Bases: Element
Node of an activity-driven network, susceptible or infected, in discrete time.
The node is susceptible at i = 0 and infected at i = 1.
One interaction recovers an infected node with probability mu in a step, and another infects a susceptible node
with probability lam by every infected neighbour along the edges of the previous step. A third joins the node to
other nodes with the probability a, its activity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the node or of the group of nodes. |
required |
i
|
Annotated[float | Array, closed_open(0, oo)]
|
Whether the node is infected. |
0.0
|
a
|
Annotated[float | Array, closed_open(0, oo)]
|
The activity, the probability of firing at a step. |
0.1
|
lam
|
Annotated[float | Array, closed_open(0, oo)]
|
The probability of infection along one edge. |
0.3
|
mu
|
Annotated[float | Array, closed_open(0, oo)]
|
The probability of recovery at a step. |
0.1
|
space
|
BaseSpace | None
|
The network whose nodes hold one member each, or |
None
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import ActiveHostElement
>>> ActiveHostElement('node').mu
0.1
Source code in src/skcomplex/systems/biology/epidemiology/_adaptive.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
ActivityDrivenEpidemicsSystem(n=500, *, m=2, exponent=2.2, least=0.01, lam=0.9, mu=0.1, infected=0.05, seed=1, label='system', solver='auto', backend='auto')
Bases: BaseSystem
SIS spreading on an activity-driven temporal network, whose edges last one step.
At every step every node fires with probability its activity, drawn from a^-exponent above least, and joins m
random nodes. The infection travels along the edges of a step, which disappear at the next step, so it spreads only
when lam / mu exceeds a threshold set by the moments of the activity, 2 <a> / (m (<a> + sqrt(<a^2>))) in the
limit of small probabilities, and not by the degrees of the network aggregated over time. The system has the states
hosts.i and activities hosts.a of the group hosts on the nodes, and the variable group contacts on the edges
of every step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The number of nodes. |
500
|
m
|
int
|
The number of edges an active node creates. |
2
|
exponent
|
float
|
The exponent of the power-law distribution of activities. |
2.2
|
least
|
float
|
The smallest activity. |
0.01
|
lam
|
float
|
The probability of infection along one edge. |
0.9
|
mu
|
float
|
The probability of recovery at a step. |
0.1
|
infected
|
float
|
The initial share of infected nodes. |
0.05
|
seed
|
int | None
|
The seed of the activities and the initial infections. |
1
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import ActivityDrivenEpidemicsSystem
>>> float(ActivityDrivenEpidemicsSystem(n=10, seed=0).prepare().system_.elements[0].a.min()) >= 0.01
True
Source code in src/skcomplex/systems/biology/epidemiology/_adaptive.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
AdaptiveSISSystem(n=200, k=6.0, *, beta=0.4, gamma=1.0, w=1.0, infected=0.2, seed=1, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The SIS epidemic where susceptible nodes cut their edges to infected neighbours.
Every edge between a susceptible and an infected node is rewired at rate w: the susceptible end keeps it and joins
it to another susceptible node. Rewiring isolates the infected nodes and raises the epidemic threshold above its
value on the fixed network, while the susceptible nodes cluster. The system has the states hosts.i of the variable
group hosts on the nodes and the variable group contacts on the edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The number of nodes. |
200
|
k
|
float
|
The mean degree of the initial Erdős-Rényi network. |
6.0
|
beta
|
float
|
The infection rate per edge to an infected neighbour. |
0.4
|
gamma
|
float
|
The recovery rate. |
1.0
|
w
|
float
|
The rewiring rate of an edge between a susceptible and an infected node. |
1.0
|
infected
|
float
|
The initial share of infected nodes. |
0.2
|
seed
|
int | None
|
The seed of the network and of the initial infections. |
1
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import AdaptiveSISSystem
>>> [component.label for component in AdaptiveSISSystem(n=20).prepare().system_.elements]
['hosts', 'contacts']
Source code in src/skcomplex/systems/biology/epidemiology/_adaptive.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
AgentBasedSIRSystem(width=50, height=50, *, people=500, infected=5, d=0.8, beta=0.6, gamma=0.02, mu=0.0, alpha=0.0, incubation=0.0, lockdown_start=0.0, lockdown_length=0.0, lockdown_d=0.1, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
People who walk on a grid and infect those in their cell.
The basic system infects with probability beta and recovers with probability gamma. Its final size depends on
beta and gamma separately, not only on their ratio, because walking limits the contacts. Mortality mu, waning
immunity alpha, an incubation of incubation steps, and a lockdown that lowers the probability of moving to
lockdown_d extend it. The system has the group people.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
The number of columns of the grid. |
50
|
height
|
int
|
The number of rows of the grid. |
50
|
people
|
int
|
The number of people. |
500
|
infected
|
int
|
The initial number of infected people. |
5
|
d
|
float
|
The probability of moving at every step. |
0.8
|
beta
|
float
|
The probability that an infectious person infects the susceptible persons of its cell. |
0.6
|
gamma
|
float
|
The probability of recovering at every step. |
0.02
|
mu
|
float
|
The probability of dying at every step of the infection. |
0.0
|
alpha
|
float
|
The probability of losing immunity at every step. |
0.0
|
incubation
|
float
|
The number of steps an infected person stays exposed before it becomes infectious, counting the step of the exposure. |
0.0
|
lockdown_start
|
float
|
The step at which the lockdown starts. |
0.0
|
lockdown_length
|
float
|
The number of steps of the lockdown, 0 for none. |
0.0
|
lockdown_d
|
float
|
The probability of moving during the lockdown. |
0.1
|
random_state
|
int | Generator | None
|
The seed or generator of the initial cells and infections. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import AgentBasedSIRSystem
>>> system = AgentBasedSIRSystem(people=100, infected=3, random_state=0).prepare().system_
>>> int(system.elements[0].health.sum())
6
Source code in src/skcomplex/systems/biology/epidemiology/_agents.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
CaseCountElement(label, *, children=0.0, adults=0.0)
Bases: Element
Daily infections of children and of adults, counted the step after they happen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the element. |
required |
children
|
float
|
The children infected in the step before. |
0.0
|
adults
|
float
|
The adults infected in the step before. |
0.0
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import CaseCountElement
>>> CaseCountElement('cases').children
0.0
Source code in src/skcomplex/systems/biology/epidemiology/_differentiable_covid.py
121 122 123 124 125 126 127 128 129 130 | |
CaseCountInteraction(label, *, target, source, children)
Bases: Interaction
Count of the agents infected in the last step, among children and among adults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the counts. |
required |
source
|
Role
|
The path of the group of agents. |
required |
children
|
NDArray[float64]
|
1 for every agent that is a child, 0 for an adult. |
required |
Examples:
>>> import numpy as np
>>> from skcomplex.systems.biology.epidemiology import CaseCountInteraction
>>> CaseCountInteraction('count', target='cases', source='people', children=np.ones(2)).source
'people'
Source code in src/skcomplex/systems/biology/epidemiology/_differentiable_covid.py
233 234 235 236 237 238 239 240 241 242 243 244 | |
ColocationInteraction(label, *, people, p=0.05, gamma=0.1, closed=False)
Bases: Interaction
Daily movement of people between home and work, and infection at locations.
A step is half a day: in even steps every person is at home and in odd steps at the workplace, unless workplaces
are closed, the time-labelled visits of the bipartite graph of people and locations of EpiSims. At every step a
susceptible person is infected with the probability 1 - (1 - p)^k by the k infected people at the same location,
and an infected person recovers with the probability gamma.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
people
|
Role
|
The path of the agent group of people. |
required |
p
|
float
|
The probability of transmission per infected contact and step. |
0.05
|
gamma
|
float
|
The probability of recovery per step. |
0.1
|
closed
|
bool
|
Whether the workplaces are closed, so people stay at home. |
False
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import ColocationInteraction
>>> ColocationInteraction('contacts', people='people', p=0.02).p
0.02
Source code in src/skcomplex/systems/biology/epidemiology/_cities.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
visit(system)
Move every person to the location of the half day, then infect and recover.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemView
|
The system. |
required |
Source code in src/skcomplex/systems/biology/epidemiology/_cities.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
CommuterElement(label, *, home=0.0, work=0.0, health=0.0, node=0, size=None, space=None)
Bases: Element
Person of a synthetic city with an SIR health state.
The person sleeps at home and spends the day at a workplace.
The home and the workplace are the locations the person visits, the edges of the person in the bipartite graph of people and locations. Health is 0 susceptible, 1 infected, or 2 recovered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the person or of the group of people. |
required |
home
|
Annotated[float | Array, NN]
|
The location of the home. |
0.0
|
work
|
Annotated[float | Array, NN]
|
The location of the workplace or school. |
0.0
|
health
|
Annotated[float | Array, NN]
|
The health state. |
0.0
|
node
|
int | IntArray
|
The location the person is at, a node of the network of locations. |
0
|
size
|
int | None
|
The number of people, or |
None
|
space
|
BaseSpace | None
|
The network of locations, or |
None
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import CommuterElement
>>> CommuterElement('person', home=3.0, work=12.0).work
12.0
Source code in src/skcomplex/systems/biology/epidemiology/_cities.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
CovidAgentElement(label, *, s=1, i=0, r=0, new=0, beta_household=0.9, beta_school=0.6, beta_company=0.3, psi=1.0, gamma=0.2, size=None)
Bases: Element
Agent of the differentiable COVID-19 model, susceptible, infected, or recovered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the agent or the group. |
required |
s
|
Annotated[float | Array, BINARY]
|
1 for a susceptible agent. |
1
|
i
|
Annotated[float | Array, BINARY]
|
1 for an infected agent. |
0
|
r
|
Annotated[float | Array, BINARY]
|
1 for a recovered agent. |
0
|
new
|
Annotated[float | Array, BINARY]
|
1 for an agent infected in the last step. |
0
|
beta_household
|
Annotated[float | Array, closed_open(0, oo)]
|
The transmission of households. |
0.9
|
beta_school
|
Annotated[float | Array, closed_open(0, oo)]
|
The transmission of schools. |
0.6
|
beta_company
|
Annotated[float | Array, closed_open(0, oo)]
|
The transmission of companies. |
0.3
|
psi
|
Annotated[float | Array, closed_open(0, oo)]
|
The susceptibility of the agent. |
1.0
|
gamma
|
Annotated[float | Array, closed(0, 1)]
|
The probability per day that an infected agent recovers. |
0.2
|
size
|
int | None
|
The number of members, or |
None
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import CovidAgentElement
>>> CovidAgentElement('agent', i=1).i
1
Source code in src/skcomplex/systems/biology/epidemiology/_differentiable_covid.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
CovidTransmissionInteraction(label, *, target, contacts, temperature=0.1, hard=False)
Bases: Interaction
Infection and recovery of agents by relaxed Bernoulli draws, Eq. 6 of Quera-Bofarull et al. (2023).
A susceptible agent is infected with the probability 1 - exp(-psi sum_L beta_L I_L), where I_L is the share of
infected agents among the other members of its place of kind L, household, school, or company, read through a
weighted sum with the weights 1 / (n_L - 1) of co-members. An infected agent recovers with the probability
gamma. Both are Bernoulli draws with a temperature, which every backend but JAX draws exactly, and JAX relaxes so
runs have gradients in the transmissions. The interaction declares its draws reparameterized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the group of agents. |
required |
contacts
|
tuple[csr_array | NDArray[float64], ...]
|
The weights of the co-members of every agent at its places, one matrix per kind of place. |
required |
temperature
|
float
|
The temperature of the relaxed draws on JAX. |
0.1
|
hard
|
bool
|
Whether JAX runs draw exact agents with the gradients of the relaxation. |
False
|
Examples:
>>> import numpy as np
>>> from skcomplex.systems.biology.epidemiology import CovidTransmissionInteraction
>>> CovidTransmissionInteraction('spread', target='people', contacts=(np.eye(2),), temperature=0.1).temperature
0.1
Source code in src/skcomplex/systems/biology/epidemiology/_differentiable_covid.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
DegreeClassElement(label, *, rho=0.01, lam=0.2, k=1.0, P=1.0, size=None)
Bases: Element
Infected density of the nodes of one degree, in heterogeneous mean field.
A node of degree k recovers at rate 1 and is infected at rate lam k Theta, where
Theta = sum_k k P(k) rho_k / <k> is the probability that an edge points to an infected node, a total over the
degree classes, so d rho_k / dt = -rho_k + lam k (1 - rho_k) Theta. The classes are the members of a group, and
the recovery and the infection are interactions of the group, which HeterogeneousMeanFieldSISSystem adds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the class or the group of classes. |
required |
rho
|
Annotated[float | Array, closed_open(0, oo)]
|
The initial infected density. |
0.01
|
lam
|
Annotated[float | Array, closed_open(0, oo)]
|
The spreading rate, the ratio of the infection and recovery rates. |
0.2
|
k
|
Annotated[float | Array, open(0, oo)]
|
The degree of the class. |
1.0
|
P
|
Annotated[float | Array, closed_open(0, oo)]
|
The probability |
1.0
|
size
|
int | None
|
The number of degree classes, or |
None
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import DegreeClassElement
>>> DegreeClassElement('network', k=[1.0, 2.0], P=[0.5, 0.5], size=2).size
2
Source code in src/skcomplex/systems/biology/epidemiology/_networks.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
DelayedSIRSSystem(first=0.01, second=0.0, *, a=2.0, recovery=6, e=0.005, label='system', solver='auto', backend='auto')
Bases: BaseSystem
Two cities with recurrent outbreaks of a disease.
The disease has fixed infection and immunity periods.
With one infected step and recovery immune steps, each city follows x' = a x (1 - x - x(t-1) - ... -
x(t-recovery)), which reduces to the logistic map without immunity. Outbreaks recur like relaxation oscillations,
and the visits of a fraction e of the infected couple the two cities, whose outbreaks lock in or out of phase. The
system has the centers first and second.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
first
|
float
|
The initial infected fraction of the first city. |
0.01
|
second
|
float
|
The initial infected fraction of the second city. |
0.0
|
a
|
float
|
The rate of transmission per contact. |
2.0
|
recovery
|
int
|
The number of steps a recovered individual stays immune, at most 12. |
6
|
e
|
float
|
The fraction of the infected who visit the other city. |
0.005
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import DelayedSIRSSystem
>>> DelayedSIRSSystem().prepare().system_.elements[0].x
0.01
Source code in src/skcomplex/systems/biology/epidemiology/_recurrent.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
DifferentiableCovidAbmSystem(n_households=100, *, n_schools=4, n_companies=10, beta_household=0.9, beta_school=0.6, beta_company=0.3, gamma=0.2, initial_infected=10, temperature=0.1, hard=False, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
Differentiable agents of a COVID-19 epidemic, after Quera-Bofarull et al. (2023).
The model of Quera-Bofarull et al. (2023, arXiv 2305.15340), a small version of GradABM-JUNE: a seeded synthetic
population of households of two adults and two children, where children go to schools and adults to companies.
Agents are susceptible, infected, or recovered, and are infected and recover by the relaxed Bernoulli draws of
CovidTransmissionInteraction, Eq. 6, with a transmission beta_L per kind of place. NumPy runs draw exact agents
and JAX runs relax the draws, so the system holds the tag differentiable and variational calibration fits the
three transmissions through its JAX run. Time runs in days. The system has the group people, the element cases
with the infections of children and adults of the day before, and the observable daily_infections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_households
|
int
|
The number of households. |
100
|
n_schools
|
int
|
The number of schools. |
4
|
n_companies
|
int
|
The number of companies. |
10
|
beta_household
|
float
|
The transmission of households. |
0.9
|
beta_school
|
float
|
The transmission of schools. |
0.6
|
beta_company
|
float
|
The transmission of companies. |
0.3
|
gamma
|
float
|
The probability per day that an infected agent recovers. |
0.2
|
initial_infected
|
int
|
The number of agents infected at the start. |
10
|
temperature
|
float
|
The temperature of the relaxed draws on JAX. |
0.1
|
hard
|
bool
|
Whether JAX runs draw exact agents with the gradients of the relaxation. |
False
|
random_state
|
int | Generator | None
|
The seed or generator of the population and of the initial infections. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import DifferentiableCovidAbmSystem
>>> DifferentiableCovidAbmSystem(n_households=10).get_tags().differentiable
True
Source code in src/skcomplex/systems/biology/epidemiology/_differentiable_covid.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
EpidemicCenterElement(label, *, x=0.0, a=2.2, recovery=6, e=0.005, values=None)
Bases: Element
City in a discrete-time SIRS epidemic.
An infection lasts one step and immunity recovery steps.
The state keeps the infected fractions of the last 12 steps, so the recovery time is at most 12.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the center. |
required |
x
|
Annotated[float, closed_open(0, oo)]
|
The initial fraction of infected individuals. |
0.0
|
a
|
Annotated[float, closed_open(0, oo)]
|
The rate of transmission per contact. |
2.2
|
recovery
|
Annotated[int, NN]
|
The number of steps a recovered individual stays immune, at most 12. |
6
|
e
|
Annotated[float, closed_open(0, oo)]
|
The fraction of the infected of the center who visit another center. |
0.005
|
values
|
Mapping[str, object] | None
|
Further values by name, such as the past fractions |
None
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import EpidemicCenterElement
>>> EpidemicCenterElement('city', x=0.01).recovery
6
Source code in src/skcomplex/systems/biology/epidemiology/_recurrent.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
EpisimsCitySystem(people=1000, *, household=3.0, workplace=20.0, p=0.05, gamma=0.1, infected=5, closed=False, seed=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
A synthetic city in the spirit of EpiSims.
People infect those they meet at home and at work.
EpiSims models a city as a bipartite graph of people and locations whose edges are visits labelled with their times,
and spreads disease between people at the same location. Here every person belongs to a household of mean size
household and a workplace or school of mean size workplace, the people sleep at home and work by day, and the
disease spreads by SIR contacts at every location. The locations form a network whose edges join a home to the
workplaces of its members, the projection of the bipartite graph onto the locations. Households spread the disease
within families and workplaces between them, so closing the workplaces, one of the interventions EpiSims was built
to compare, confines outbreaks to households. The system has the homes, workplaces, and health states of the agent
group people on the locations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
people
|
int
|
The number of people. |
1000
|
household
|
float
|
The mean size of a household. |
3.0
|
workplace
|
float
|
The mean size of a workplace or school. |
20.0
|
p
|
float
|
The probability of transmission per infected contact and half day. |
0.05
|
gamma
|
float
|
The probability of recovery per half day. |
0.1
|
infected
|
int
|
The initial number of infected people. |
5
|
closed
|
bool
|
Whether the workplaces are closed. |
False
|
seed
|
int | None
|
The seed of the households, the workplaces, and the initial infections. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import EpisimsCitySystem
>>> EpisimsCitySystem(100).prepare().system_.elements[0].size
100
Source code in src/skcomplex/systems/biology/epidemiology/_cities.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
HeterogeneousMeanFieldSIRSystem(exponent=2.5, k_min=3, k_max=100, *, beta=0.1, mu=1.0, infected=0.0001, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The SIR epidemic on an uncorrelated network of power-law degrees.
It is in heterogeneous mean field.
The degrees run from k_min to k_max with P(k) ~ k^-exponent. An outbreak grows when beta / mu > <k> / (<k^2>
- <k>), a threshold close to <k> / <k^2> on heterogeneous networks, which vanishes on scale-free networks as
k_max grows. Below it the epidemic dies out after infecting a share of the order of the initial one, and above it
a finite share of the population ends recovered. The hubs are infected first. The system has the densities
network.s, network.i, and network.r of the degree classes from k_min to k_max, members of the group
network, and the shares infected and recovered of the whole population, the last one the final epidemic size
at the end of the outbreak.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exponent
|
float
|
The exponent of the degree distribution. |
2.5
|
k_min
|
int
|
The smallest degree. |
3
|
k_max
|
int
|
The largest degree. |
100
|
beta
|
float
|
The rate of transmission along one contact. |
0.1
|
mu
|
float
|
The recovery rate. |
1.0
|
infected
|
float
|
The initial infected density of every class. |
0.0001
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import HeterogeneousMeanFieldSIRSystem
>>> HeterogeneousMeanFieldSIRSystem(k_min=2, k_max=5).prepare().system_.elements[0].size
4
Source code in src/skcomplex/systems/biology/epidemiology/_outbreaks.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
HeterogeneousMeanFieldSISSystem(exponent=2.5, k_min=3, k_max=30, *, lam=0.2, rho=0.01, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The SIS epidemic on a power-law network, in heterogeneous mean field.
The degrees run from k_min to k_max with P(k) ~ k^-exponent. The infection persists above the epidemic
threshold lam_c = <k> / <k^2>, which vanishes on scale-free networks as k_max grows, and dies out below it. The
system has the densities network.rho of the degree classes from k_min to k_max, members of the group
network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exponent
|
float
|
The exponent of the degree distribution. |
2.5
|
k_min
|
int
|
The smallest degree. |
3
|
k_max
|
int
|
The largest degree. |
30
|
lam
|
float
|
The spreading rate, the ratio of the infection and recovery rates. |
0.2
|
rho
|
float
|
The initial infected density of every class. |
0.01
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import HeterogeneousMeanFieldSISSystem
>>> HeterogeneousMeanFieldSISSystem(k_min=2, k_max=5).prepare().system_.elements[0].size
4
Source code in src/skcomplex/systems/biology/epidemiology/_networks.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
HostElement(label, *, i=0.0, w=1.0, space=None)
Bases: Element
Node of a network that is susceptible or infected, in continuous time.
It is susceptible at i = 0 and infected at i = 1.
A SpreadingInteraction infects and recovers it, and a rewiring interaction rewires its edges at its rate w.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the node or of the group of nodes. |
required |
i
|
Annotated[float | Array, closed_open(0, oo)]
|
Whether the node is infected. |
0.0
|
w
|
Annotated[float | Array, closed_open(0, oo)]
|
The rate at which the node, while susceptible, rewires an edge to an infected neighbour. |
1.0
|
space
|
BaseSpace | None
|
The network whose nodes hold one member each, or |
None
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import HostElement
>>> HostElement('node').w
1.0
Source code in src/skcomplex/systems/biology/common/networks/_host.py
45 46 47 48 49 50 51 52 53 54 55 | |
ImmunityLossInteraction(label, *, recovered, susceptible, xi=0.05, stochastic=False)
Bases: ReactionInteraction
Loss of immunity, the reaction R -> S at the rate xi R.
The reaction moves individuals from recovered back to susceptible.
It is a ReactionInteraction between the states x of the two compartments its roles bind, a rate equation, or
in stochastic mode a random event that moves one individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
recovered
|
Role
|
The path of the recovered compartment. |
required |
susceptible
|
Role
|
The path of the susceptible compartment. |
required |
xi
|
Annotated[float, closed_open(0, oo)]
|
The rate at which immunity wanes. |
0.05
|
stochastic
|
bool
|
Whether losses of immunity are random events. |
False
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import ImmunityLossInteraction
>>> ImmunityLossInteraction('waning', recovered='R', susceptible='S', xi=0.05).xi
0.05
Source code in src/skcomplex/systems/biology/epidemiology/_factories.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
ImmunizingDegreeClassElement(label, *, s=0.999, i=0.001, r=0.0, beta=0.1, mu=1.0, k=1.0, P=1.0, size=None)
Bases: Element
Susceptible, infected, and recovered densities of the nodes of one degree.
The densities are in heterogeneous mean field.
A susceptible node of degree k is infected at rate beta k theta and an infected node recovers at rate mu, so
d i_k / dt = -mu i_k + beta k s_k theta and d r_k / dt = mu i_k. On an uncorrelated network, the probability
that a contact of a susceptible node is infected is theta = sum_k (k - 1) P(k) i_k / <k>, a total over the
degree classes, since an infected neighbour of degree k has at most k - 1 other contacts. The classes are the
members of a group, and the infections and the recoveries are interactions of the group, which
HeterogeneousMeanFieldSIRSystem adds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the class or the group of classes. |
required |
s
|
Annotated[float | Array, closed_open(0, oo)]
|
The initial susceptible density. |
0.999
|
i
|
Annotated[float | Array, closed_open(0, oo)]
|
The initial infected density. |
0.001
|
r
|
Annotated[float | Array, closed_open(0, oo)]
|
The initial recovered density. |
0.0
|
beta
|
Annotated[float | Array, closed_open(0, oo)]
|
The rate of transmission along one contact. |
0.1
|
mu
|
Annotated[float | Array, open(0, oo)]
|
The recovery rate. |
1.0
|
k
|
Annotated[float | Array, open(0, oo)]
|
The degree of the class. |
1.0
|
P
|
Annotated[float | Array, closed_open(0, oo)]
|
The probability |
1.0
|
size
|
int | None
|
The number of degree classes, or |
None
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import ImmunizingDegreeClassElement
>>> ImmunizingDegreeClassElement('network', k=[1.0, 2.0, 3.0], P=[0.5, 0.3, 0.2], size=3).size
3
Source code in src/skcomplex/systems/biology/epidemiology/_outbreaks.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
InfectionInteraction(label, *, susceptible, infected, beta=0.001, stochastic=False)
Bases: ReactionInteraction
Mass-action infection, the reaction S + I -> 2 I at the rate beta S I.
The reaction moves individuals from susceptible to infected.
It is a ReactionInteraction between the states x of the two compartments its roles bind, a rate equation, or
in stochastic mode a random event that moves one individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
susceptible
|
Role
|
The path of the susceptible compartment. |
required |
infected
|
Role
|
The path of the infected compartment. |
required |
beta
|
Annotated[float, closed_open(0, oo)]
|
The transmission rate. |
0.001
|
stochastic
|
bool
|
Whether infections are random events. |
False
|
Examples:
>>> from skcomplex.systems.biology.common.kinetics import CompartmentElement
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.biology.epidemiology import InfectionInteraction
>>> system = System(
... elements=[CompartmentElement('S', x=99.0), CompartmentElement('I', x=1.0)],
... interactions=[InfectionInteraction('infection', susceptible='S', infected='I', beta=0.01)],
... )
>>> trajectory = system.prepare().simulate(until=5.0, dt=0.1)
>>> round(float(trajectory.get_values('S.x')[-1] + trajectory.get_values('I.x')[-1]), 6)
100.0
Source code in src/skcomplex/systems/biology/epidemiology/_factories.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
MetapopulationSystem(graph=None, *, population=1000.0, infected=10.0, beta=0.3, gamma=0.1, D=0.01, label='system', solver='auto', backend='auto')
Bases: NetworkDynamicalSystem
SIR epidemics in subpopulations at the nodes of a network.
Individuals who travel link the subpopulations.
The infection starts in the first node and spreads to the others with the travellers. The total number of
individuals stays constant. The system has the compartments cities.S, cities.I, and cities.R, one value per
node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
object
|
The NetworkX graph, or |
None
|
population
|
float
|
The initial number of individuals of every node. |
1000.0
|
infected
|
float
|
The initial number of infected individuals in the first node. |
10.0
|
beta
|
float
|
The infection rate. |
0.3
|
gamma
|
float
|
The recovery rate. |
0.1
|
D
|
float
|
The rate at which an individual hops along one edge. |
0.01
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> import networkx as nx
>>> from skcomplex.systems.biology.epidemiology import MetapopulationSystem
>>> MetapopulationSystem(nx.path_graph(4)).prepare().simulate(until=0.0).get_values('cities.S').shape
(1, 4)
Source code in src/skcomplex/systems/biology/epidemiology/_networks.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
NetworkSIRSystem(graph=None, *, residents=20, tau=0.05, days=14.0, m=0.05, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
SIR epidemics in cities at the nodes of a network.
Travellers carry the epidemics between cities.
Every node starts with the same number of susceptible residents, and one resident of a random node is infected. The
system has the group travellers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
object
|
The NetworkX graph of the cities, or |
None
|
residents
|
int
|
The initial number of travellers per node. |
20
|
tau
|
float
|
The probability of infecting a susceptible traveller of the same node at every step. |
0.05
|
days
|
float
|
The number of steps an infection lasts. |
14.0
|
m
|
float
|
The probability of moving to a neighbouring node at every step. |
0.05
|
random_state
|
int | Generator | None
|
The seed or generator of the first infection. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> import networkx as nx
>>> from skcomplex.systems.biology.epidemiology import NetworkSIRSystem
>>> NetworkSIRSystem(nx.cycle_graph(5), residents=3).prepare().system_.elements[0].size
15
Source code in src/skcomplex/systems/biology/epidemiology/_agents.py
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 | |
PairFormationSISSystem(n=400, k=2, *, beta=None, gamma=0.5, sigma=None, pressure=1.5, turnover=2.0, infected=0.05, seed=1, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The SIS epidemic on partnerships that dissolve and are replaced at once.
Every person keeps k partners at any time, on a random regular network. A partnership dissolves at the rate
sigma, and the person who keeps it finds a new partner at once, at random. An infectious person infects a
susceptible partner at the rate beta and recovers at the rate gamma. By default the infection pressure k beta
and the rate k sigma of new partners per person are held fixed at pressure and turnover, so k = 1 is serial
monogamy and a larger k is concurrency at the same contact rate. Concurrency lets the infection pass on before the
partnership that brought it ends, so the epidemic grows faster and reaches more people. The system has the states
people.i of the variable group people on the nodes and the variable group partnerships on the edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The number of people, even when |
400
|
k
|
int
|
The number of concurrent partners of every person. |
2
|
beta
|
float | None
|
The infection rate per partnership, or |
None
|
gamma
|
float
|
The recovery rate. |
0.5
|
sigma
|
float | None
|
The dissolution rate of a partnership, or |
None
|
pressure
|
float
|
The infection pressure of a person whose partners are all infectious, used when |
1.5
|
turnover
|
float
|
The rate of new partners per person, used when |
2.0
|
infected
|
float
|
The initial share of infectious people. |
0.05
|
seed
|
int | None
|
The seed of the network and of the initial infections. |
1
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import PairFormationSISSystem
>>> PairFormationSISSystem(n=20, k=4).prepare().system_.interactions[0].beta
0.375
Source code in src/skcomplex/systems/biology/epidemiology/_concurrency.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
PartnershipEpidemicElement(label, *, S=0.99, E=0.0, I=0.01, R=0.0, J=0.0, values=None)
Bases: 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the population. |
required |
S
|
Annotated[float, FRACTION]
|
The initial fraction of susceptible people. |
0.99
|
E
|
Annotated[float, FRACTION]
|
The initial fraction of exposed people. |
0.0
|
I
|
Annotated[float, FRACTION]
|
The initial fraction of infectious people. |
0.01
|
R
|
Annotated[float, FRACTION]
|
The initial fraction of people who developed the disease. |
0.0
|
J
|
Annotated[float, closed_open(0, oo)]
|
The initial infection memory of current partnerships. |
0.0
|
values
|
Mapping[str, object] | None
|
Further values by name, such as the infectious before the start |
None
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import PartnershipEpidemicElement
>>> PartnershipEpidemicElement('population').S
0.99
Source code in src/skcomplex/systems/biology/epidemiology/_concurrency.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
PartnershipInfectionInteraction(label, *, target, c=2.0, beta=0.2, tau=1.0, T=0.5, nu=0.1)
Bases: 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the population. |
required |
c
|
Annotated[float, closed_open(0, oo)]
|
The rate of acquiring new partners. |
2.0
|
beta
|
Annotated[float, FRACTION]
|
The probability of infection by an infectious partner over a partnership. |
0.2
|
tau
|
Annotated[float, open(0, oo)]
|
The mean duration of a partnership. |
1.0
|
T
|
Annotated[float, open(0, oo)]
|
The duration of the exposed period. |
0.5
|
nu
|
Annotated[float, closed_open(0, oo)]
|
The rate at which the infectious develop the disease. |
0.1
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import PartnershipInfectionInteraction
>>> PartnershipInfectionInteraction('infection', target='population').tau
1.0
Source code in src/skcomplex/systems/biology/epidemiology/_concurrency.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
PathogenElement(label, *, eta=0.0)
Bases: Element
Pathogen whose strength StrainDrawInteraction draws anew every season.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the pathogen. |
required |
eta
|
Annotated[object, closed_open(0, 1)]
|
The strength of the strain of the current season. |
0.0
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import PathogenElement
>>> PathogenElement('pathogen').eta
0.0
Source code in src/skcomplex/systems/biology/epidemiology/_records.py
44 45 46 47 48 49 50 51 | |
PersonElement(label, *, health=SUSCEPTIBLE, d=0.8, beta=0.6, gamma=0.01, mu=0.0, alpha=0.0, lockdown_start=0.0, lockdown_length=0.0, lockdown_d=0.1, values=None, size=None, space=None)
Bases: Element
Person of the agent-based SIR system.
The person has incubation, mortality, waning immunity, and lockdown.
A MovementInteraction walks a living person to a neighbouring cell with probability d, or lockdown_d during
the lockdown, which lasts lockdown_length steps from lockdown_start. Rules of the person, which
AgentBasedSIRSystem adds, move the health of the person. An infectious person infects, with probability beta,
every susceptible person in its cell, who becomes exposed. An infectious person recovers with probability gamma
or dies with probability mu, and a recovered person loses immunity with probability alpha. Health is 0
susceptible, 1 exposed, 2 infected, 3 recovered, or 4 dead.
The incubation counts whole steps of residence in the exposed state: the step of the
exposure counts as the first step in the exposed state, so a person exposed in step n becomes infectious at the
end of step n + incubation - 1. The clock that the person kept before counted the step of the exposure only when
the person acted after its infector in that step, so the onset now comes half a step earlier on average.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the agent or group. |
required |
health
|
Annotated[float | Array, NN]
|
The health state. |
SUSCEPTIBLE
|
d
|
Annotated[float, closed_open(0, oo)]
|
The probability of moving at every step. |
0.8
|
beta
|
Annotated[float, closed_open(0, oo)]
|
The probability that an infectious person infects the susceptible persons of its cell. |
0.6
|
gamma
|
Annotated[float, closed_open(0, oo)]
|
The probability of recovering at every step. |
0.01
|
mu
|
Annotated[float, closed_open(0, oo)]
|
The probability of dying at every step of the infection. |
0.0
|
alpha
|
Annotated[float, closed_open(0, oo)]
|
The probability of losing immunity at every step. |
0.0
|
lockdown_start
|
Annotated[float, closed_open(0, oo)]
|
The step at which the lockdown starts. |
0.0
|
lockdown_length
|
Annotated[float, closed_open(0, oo)]
|
The number of steps of the lockdown, 0 for none. |
0.0
|
lockdown_d
|
Annotated[float, closed_open(0, oo)]
|
The probability of moving during the lockdown. |
0.1
|
values
|
Mapping[str, object] | None
|
Further values by name, such as the cells |
None
|
size
|
int | None
|
The number of members, or |
None
|
space
|
BaseSpace | None
|
The grid or network the members live on, or |
None
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import PersonElement
>>> PersonElement('people', size=100).size
100
Source code in src/skcomplex/systems/biology/epidemiology/_agents.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
QuenchedMeanFieldSISSystem(graph=None, *, n=300, m=3, lam=0.2, p=0.05, seed=1, label='system', solver='auto', backend='auto')
Bases: NetworkDynamicalSystem
The SIS epidemic on a fixed network in quenched mean field.
It has one infection probability per node.
The infection persists above the threshold lam_c = 1 / Lambda, the inverse of the largest eigenvalue of the
adjacency matrix, and dies out below it. On scale-free networks the hubs keep it alive at small lam. The system
has the probabilities nodes.p of the group nodes on the nodes of the network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph | None
|
The network, or |
None
|
n
|
int
|
The number of nodes of the default network. |
300
|
m
|
int
|
The number of edges of every new node of the default network. |
3
|
lam
|
float
|
The spreading rate, the ratio of the infection rate per edge and the recovery rate. |
0.2
|
p
|
float
|
The initial probability that every node is infected. |
0.05
|
seed
|
int | None
|
The seed of the default network. |
1
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> import networkx as nx
>>> from skcomplex.systems.biology.epidemiology import QuenchedMeanFieldSISSystem
>>> QuenchedMeanFieldSISSystem(nx.cycle_graph(10)).prepare().simulate(until=0.0).get_values('nodes.p').shape
(1, 10)
Source code in src/skcomplex/systems/biology/epidemiology/_adaptive.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
RandomWalkerEpidemicsSystem(width=64, height=64, *, walkers=1000, lifetime=20.0, infection=1.0, travel=1.0, graph=None, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
Random walkers among whom one sick walker starts a deadly epidemic.
The walkers move on a grid or on a network.
Sick walkers infect the walkers they meet in a cell and die lifetime steps later, so the epidemic spreads as a
front like a forest fire and burns out. Above a critical density of walkers it percolates across the grid. On a
network, such as a small world of cities, walkers travel along edges and long links carry the disease far. The
system has the group walkers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
The number of columns of the grid, whose edges walkers cannot cross. |
64
|
height
|
int
|
The number of rows of the grid. |
64
|
walkers
|
int
|
The number of walkers. |
1000
|
lifetime
|
float
|
The number of steps a walker lives after its infection. |
20.0
|
infection
|
float
|
The probability that a sick walker infects a healthy walker of its cell at every step. |
1.0
|
travel
|
float
|
The probability of moving at every step. |
1.0
|
graph
|
object
|
A NetworkX graph whose nodes the walkers occupy instead of the grid, or |
None
|
random_state
|
int | Generator | None
|
The seed or generator of the initial places and the first sick walker. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import RandomWalkerEpidemicsSystem
>>> float(RandomWalkerEpidemicsSystem(walkers=50).prepare().system_.elements[0].health.sum())
1.0
Source code in src/skcomplex/systems/biology/epidemiology/_agents.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 | |
RecordDynamicsEpidemicSystem(n=10000, *, seed=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
Yearly strains that infect every resident less resistant than their strength.
The infected residents become immune.
Every resident keeps a resistance R drawn uniformly from [0, 1]. Once a year a strain of strength eta, drawn
uniformly from [0, 1), infects the residents with R < eta, whose resistance becomes 1. In a large population an
outbreak happens only in a year whose strain is stronger than every earlier one, a record, so outbreaks thin out as
time goes on: the mean number of outbreaks in t years is close to the harmonic number H_t, about ln t + 0.577,
a Poisson process in the logarithm of time. The system has the resistances residents.R, the infections of the last
year residents.infected, and the strength pathogen.eta of the strain of the coming year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The number of residents. |
10000
|
seed
|
int | None
|
The seed of the resistances. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import RecordDynamicsEpidemicSystem
>>> RecordDynamicsEpidemicSystem(100).prepare().system_.elements[0].size
100
Source code in src/skcomplex/systems/biology/epidemiology/_records.py
218 219 220 221 222 223 224 225 226 227 228 229 | |
RecoveryInteraction(label, *, infected, recovered, gamma=0.1, stochastic=False)
Bases: ReactionInteraction
Recovery, the reaction I -> R at the rate gamma I.
The reaction moves individuals from infected to recovered.
It is a ReactionInteraction between the states x of the two compartments its roles bind, a rate equation, or
in stochastic mode a random event that moves one individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
infected
|
Role
|
The path of the infected compartment. |
required |
recovered
|
Role
|
The path of the recovered compartment. |
required |
gamma
|
Annotated[float, closed_open(0, oo)]
|
The recovery rate. |
0.1
|
stochastic
|
bool
|
Whether recoveries are random events. |
False
|
Examples:
>>> from skcomplex.systems.biology.common.kinetics import CompartmentElement
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.biology.epidemiology import RecoveryInteraction
>>> system = System(
... elements=[CompartmentElement('I', x=10.0), CompartmentElement('R')],
... interactions=[RecoveryInteraction('recovery', infected='I', recovered='R', gamma=0.5)],
... )
>>> trajectory = system.prepare().simulate(until=2.0, dt=0.01)
>>> round(float(trajectory.get_values('I.x')[-1]), 3)
3.679
Source code in src/skcomplex/systems/biology/epidemiology/_factories.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
ResidentElement(label, *, R=0.5, infected=0.0, size=None)
Bases: Element
Resident of a population with a fixed resistance to a disease.
The resident is immune for good once infected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the resident or of the group of residents. |
required |
R
|
Annotated[float | Array, closed(0, 1)]
|
The resistance, between 0 and 1, where 1 is immunity. |
0.5
|
infected
|
Annotated[float | Array, FiniteEnumeratedSet([0, 1])]
|
Whether the resident was infected in the last outbreak. |
0.0
|
size
|
int | None
|
The number of members, or |
None
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import ResidentElement
>>> ResidentElement('resident', R=0.3).R
0.3
Source code in src/skcomplex/systems/biology/epidemiology/_records.py
113 114 115 116 117 118 119 120 121 122 123 | |
ResistanceInfectionInteraction(label, *, residents, pathogen)
Bases: Interaction
Infection of every resident whose resistance is below the strain strength.
The strain is the one of the season, and an infected resident becomes immune.
A resident with R < eta is infected in the season and its resistance becomes 1, so it is never infected again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
residents
|
Role
|
The path of the group of residents. |
required |
pathogen
|
Role
|
The path of the pathogen. |
required |
Examples:
>>> from skcomplex.systems.biology.epidemiology import ResistanceInfectionInteraction
>>> ResistanceInfectionInteraction('infection', residents='people', pathogen='flu').pathogen
'flu'
Source code in src/skcomplex/systems/biology/epidemiology/_records.py
151 152 153 154 155 156 157 158 159 160 | |
SIRSSystem(susceptible=990.0, infected=10.0, recovered=0.0, *, beta=0.0003, gamma=0.1, xi=0.02, stochastic=False, label='system', solver='auto', backend='auto')
Bases: ReactionNetworkSystem
An epidemic whose immunity wanes.
The epidemic returns in damped waves to an endemic equilibrium.
The equilibrium has S = gamma / beta susceptible and I = xi (N - S) / (gamma + xi) infected. The system has the
compartments S, I, and R.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
susceptible
|
float
|
The initial number of susceptible individuals. |
990.0
|
infected
|
float
|
The initial number of infected individuals. |
10.0
|
recovered
|
float
|
The initial number of recovered individuals. |
0.0
|
beta
|
float
|
The infection rate per susceptible-infected pair. |
0.0003
|
gamma
|
float
|
The recovery rate. |
0.1
|
xi
|
float
|
The rate at which immunity wanes. |
0.02
|
stochastic
|
bool
|
Whether infections, recoveries, and losses of immunity are random events of single individuals. |
False
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import SIRSSystem
>>> SIRSSystem(xi=0.1).prepare().system_.interactions[-1].xi
0.1
Source code in src/skcomplex/systems/biology/epidemiology/_factories.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
SIRSystem(susceptible=990.0, infected=10.0, recovered=0.0, *, beta=0.0003, gamma=0.1, stochastic=False, label='system', solver='auto', backend='auto')
Bases: ReactionNetworkSystem
An epidemic that moves individuals from susceptible to infected to recovered.
The system has the compartments S, I, and R.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
susceptible
|
float
|
The initial number of susceptible individuals. |
990.0
|
infected
|
float
|
The initial number of infected individuals. |
10.0
|
recovered
|
float
|
The initial number of recovered individuals. |
0.0
|
beta
|
float
|
The infection rate per susceptible-infected pair. |
0.0003
|
gamma
|
float
|
The recovery rate. |
0.1
|
stochastic
|
bool
|
Whether infections and recoveries are random events of single individuals. |
False
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import SIRSystem
>>> [element.label for element in SIRSystem().prepare().system_.elements]
['S', 'I', 'R']
Source code in src/skcomplex/systems/biology/epidemiology/_factories.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
SIRVaccinationSystem(S=0.99, I=0.01, *, beta=0.5, gamma=0.1, a=1.0, b=1.0, label='system', solver='auto', backend='auto')
Bases: DynamicalSystem
An SIR epidemic with the optimal vaccination rate.
The rate minimises the burden of infections and vaccines, the objective law
ObjectiveLaw(a I + b u^2 / 2, controls=[s.target.u]), with u between 0 and 0.9.
Run with an optimal control solver, vaccination is strongest early, while many are susceptible, and the epidemic
peaks lower than without vaccination. With no weight a on the infections the optimal rate is 0, the epidemic
without control. The system has the fractions population.S, population.I, and population.R, the vaccination
rate population.u, and the observables vaccinated and cost, the running cost.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S
|
float
|
The initial susceptible fraction. |
0.99
|
I
|
float
|
The initial infected fraction. |
0.01
|
beta
|
float
|
The transmission rate. |
0.5
|
gamma
|
float
|
The recovery rate. |
0.1
|
a
|
float
|
The weight of the infected fraction in the cost. |
1.0
|
b
|
float
|
The weight of the squared vaccination rate in the cost. |
1.0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import SIRVaccinationSystem
>>> SIRVaccinationSystem(beta=0.3).prepare().system_.elements[0].get_params()['beta']
0.3
Source code in src/skcomplex/systems/biology/epidemiology/_vaccination.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
SISSystem(susceptible=990.0, infected=10.0, *, beta=0.0003, gamma=0.1, stochastic=False, label='system', solver='auto', backend='auto')
Bases: ReactionNetworkSystem
An infection without immunity, where the recovered become susceptible again.
The disease is endemic.
Above the threshold beta N > gamma, the infected settle at I = N - gamma / beta, and below it they die out. The
system has the compartments S and I.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
susceptible
|
float
|
The initial number of susceptible individuals. |
990.0
|
infected
|
float
|
The initial number of infected individuals. |
10.0
|
beta
|
float
|
The infection rate per susceptible-infected pair. |
0.0003
|
gamma
|
float
|
The recovery rate. |
0.1
|
stochastic
|
bool
|
Whether infections and recoveries are random events of single individuals. |
False
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import SISSystem
>>> [element.label for element in SISSystem().prepare().system_.elements]
['S', 'I']
Source code in src/skcomplex/systems/biology/epidemiology/_factories.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
SpreadingInteraction(label, *, target, state='state', beta=1.0, gamma=0.0, omega=0.0, inactive=0.0, active=1.0, removed=None, form='number', layer=None)
Bases: Interaction
Spreading of the active value of a discrete state to neighbours.
The neighbours are along the edges of a network or the bonds of a lattice.
An inactive member becomes active at the rate beta times the number of its active neighbours, or times their
fraction of its neighbours. An active member recovers at the rate gamma, to the inactive value, or to the removed
value when there is one, and a removed member returns to the inactive value at the rate omega. Every move is a
jump at a rate, so the state changes by random events in continuous time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction, unique among the components of its system. |
required |
target
|
Role
|
The path of the group on the nodes or sites. |
required |
state
|
str
|
The name of the discrete state of the members. |
'state'
|
beta
|
Annotated[float, closed_open(0, oo)]
|
The rate of spreading from one active neighbour, or from all neighbours when they are all active. |
1.0
|
gamma
|
Annotated[float, closed_open(0, oo)]
|
The rate of recovery of an active member. |
0.0
|
omega
|
Annotated[float, closed_open(0, oo)]
|
The rate at which a removed member returns to the inactive value. |
0.0
|
inactive
|
float
|
The value of the state of an inactive member. |
0.0
|
active
|
float
|
The value of the state of an active member. |
1.0
|
removed
|
float | None
|
The value of the state of a recovered member, or |
None
|
form
|
str
|
|
'number'
|
layer
|
str | None
|
The layer of the network whose edges the spreading runs on, or |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
The form is unknown, or the values of the state are not distinct. |
Examples:
>>> from skcomplex.systems.biology.epidemiology import SpreadingInteraction
>>> spreading = SpreadingInteraction('spreading', target='sites', beta=2.0, gamma=1.0, form='fraction')
>>> spreading.form
'fraction'
Source code in src/skcomplex/systems/biology/common/networks/_spreading.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
StrainDrawInteraction(label, *, target)
Bases: Interaction
Draw of the strength of the strain of every season, uniform from zero to one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the pathogen. |
required |
Examples:
>>> from skcomplex.systems.biology.epidemiology import StrainDrawInteraction
>>> StrainDrawInteraction('strain', target='pathogen').target
'pathogen'
Source code in src/skcomplex/systems/biology/epidemiology/_records.py
74 75 76 | |
TravellerElement(label, *, health=SUSCEPTIBLE, tau=0.05, m=0.05, values=None, size=None, space=None)
Bases: Element
Resident of a city at a network node.
The resident infects fellow residents and travels to neighbouring cities.
In its own activation, an infected traveller infects every susceptible traveller of its node with probability
tau, by a rule of the traveller on its node, and another rule makes it recover after a residence of a number
of steps. A MovementInteraction moves it to a random neighbouring node with probability
m. Health is 0 susceptible, 2 infected, or 3 recovered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the agent or group. |
required |
health
|
Annotated[float | Array, NN]
|
The health state. |
SUSCEPTIBLE
|
tau
|
Annotated[float, closed_open(0, oo)]
|
The probability of infecting a susceptible traveller of the same node at every step. |
0.05
|
m
|
Annotated[float, closed_open(0, oo)]
|
The probability of moving to a neighbouring node at every step. |
0.05
|
values
|
Mapping[str, object] | None
|
Further values by name, such as the cells |
None
|
size
|
int | None
|
The number of members, or |
None
|
space
|
BaseSpace | None
|
The grid or network the members live on, or |
None
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import TravellerElement
>>> TravellerElement('travellers', size=10).size
10
Source code in src/skcomplex/systems/biology/epidemiology/_agents.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
WalkerElement(label, *, health=HEALTHY, infection=1.0, travel=1.0, values=None, size=None, space=None)
Bases: Element
Random walker that carries a deadly disease, of Charbonneau's epidemic system.
In its own activation, a living walker moves to a neighbouring cell or node with probability travel by a
MovementInteraction, and a rule of the walker on its cell makes a sick walker infect every healthy walker of
its cell with probability infection. Another rule kills a sick walker after a
residence of a number of steps. Health is 0 healthy, 1 sick, or 2 dead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the agent or group. |
required |
health
|
Annotated[float | Array, NN]
|
The health state. |
HEALTHY
|
infection
|
Annotated[float, closed_open(0, oo)]
|
The probability that a sick walker infects a healthy walker of its cell at every step. |
1.0
|
travel
|
Annotated[float, closed_open(0, oo)]
|
The probability of moving at every step. |
1.0
|
values
|
Mapping[str, object] | None
|
Further values by name, such as the cells |
None
|
size
|
int | None
|
The number of members, or |
None
|
space
|
BaseSpace | None
|
The grid or network the members live on, or |
None
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import WalkerElement
>>> WalkerElement('walkers', size=10).size
10
Source code in src/skcomplex/systems/biology/epidemiology/_agents.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
WattsMayConcurrencySystem(infected=0.01, *, c=2.0, beta=0.2, tau=1.0, T=0.5, nu=0.1, label='system', solver='auto', backend='auto')
Bases: 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
infected
|
float
|
The initial fraction of infectious people. |
0.01
|
c
|
float
|
The rate of acquiring new partners. |
2.0
|
beta
|
float
|
The probability of infection by an infectious partner over a partnership. |
0.2
|
tau
|
float
|
The mean duration of a partnership. |
1.0
|
T
|
float
|
The duration of the exposed period. |
0.5
|
nu
|
float
|
The rate at which the infectious develop the disease. |
0.1
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import WattsMayConcurrencySystem
>>> WattsMayConcurrencySystem(tau=3.0).prepare().system_.interactions[0].tau
3.0
Source code in src/skcomplex/systems/biology/epidemiology/_concurrency.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
ZombieOutbreakSystem(susceptible=500.0, zombies=1.0, removed=0.0, *, birth=0.0, beta=0.0095, alpha=0.005, delta=0.0001, zeta=0.0001, stochastic=False, label='system', solver='auto', backend='auto')
Bases: ReactionNetworkSystem
The outbreak of zombies of Munz et al.
The dead rise again and humans are eventually overrun.
Humans S are born at the rate birth and die naturally at the rate delta. A zombie Z bites a human at the
rate beta S Z, and humans destroy zombies at the rate alpha S Z. The dead and destroyed R rise as zombies at
the rate zeta. Without births the total S + Z + R is conserved, and with resurrection the only stable state is
the doomsday state without humans, whatever the initial numbers, whenever beta > alpha. The system has the
compartments S, Z, and R.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
susceptible
|
float
|
The initial number of humans. |
500.0
|
zombies
|
float
|
The initial number of zombies. |
1.0
|
removed
|
float
|
The initial number of dead and destroyed. |
0.0
|
birth
|
float
|
The birth rate of humans. |
0.0
|
beta
|
float
|
The rate at which zombies turn humans. |
0.0095
|
alpha
|
float
|
The rate at which humans destroy zombies. |
0.005
|
delta
|
float
|
The rate of natural death of humans. |
0.0001
|
zeta
|
float
|
The rate at which the removed rise as zombies. |
0.0001
|
stochastic
|
bool
|
Whether every event moves one individual at random times. |
False
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import ZombieOutbreakSystem
>>> [element.label for element in ZombieOutbreakSystem().prepare().system_.elements]
['S', 'Z', 'R']
Source code in src/skcomplex/systems/biology/epidemiology/_factories.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | |