Epidemiology
Epidemiology: compartmental, network, metapopulation, and agent-based systems of infection and recovery.
ActiveHostElement(label, visual=None, *, i=0.0, a=0.1, lam=0.3, mu=0.1)
Bases: Element
Node of an activity-driven network, susceptible at i = 0 or infected at i = 1, in discrete time.
A TransitionInteraction 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
TopologyInteraction 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 |
visual
|
VisualSpec | None
|
How the element is drawn, or |
None
|
i
|
Annotated[float, StateSpec(domain=closed_open(0, oo))]
|
Whether the node is infected. |
0.0
|
a
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The activity, the probability of firing at a step. |
0.1
|
lam
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The probability of infection along one edge. |
0.3
|
mu
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The probability of recovery at a step. |
0.1
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import ActiveHostElement
>>> ActiveHostElement('node').mu
0.1
Source code in src/skcomplex/systems/biology/epidemiology/_adaptive.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
CarrierElement(label, visual=None, *, p=0.05, lam=0.2)
Bases: Element
Node of a network whose state is the probability that it is infected, in quenched mean field.
The node recovers at rate 1 and every infected neighbour infects it at rate lam, with the probabilities of the
neighbours taken as independent, so dp_i / dt = -p_i + lam (1 - p_i) sum_j A_ij p_j over the neighbours j.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the node or of the group of nodes. |
required |
visual
|
VisualSpec | None
|
How the element is drawn, or |
None
|
p
|
Annotated[float, StateSpec(domain=closed_open(0, oo))]
|
The initial probability of being infected. |
0.05
|
lam
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The spreading rate, the ratio of the infection rate per edge and the recovery rate. |
0.2
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import CarrierElement
>>> CarrierElement('node').lam
0.2
Source code in src/skcomplex/systems/biology/epidemiology/_adaptive.py
101 102 103 104 105 106 107 108 109 110 111 | |
ColocationInteraction(label, *, people, p=0.05, gamma=0.1, closed=False)
Bases: Interaction
Daily movement of people between their homes and workplaces, and infection between people at one location.
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
|
Annotated[str, RoleSpec()]
|
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
114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
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
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
CommuterElement(label, visual=VisualSpec('agents', {'color_by': 'health', 'color_range': (0.0, 2.0)}), *, home=0.0, work=0.0, health=0.0)
Bases: Element
Person of a synthetic city who sleeps at home and spends the day at a workplace, with an SIR health state.
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 |
visual
|
VisualSpec | None
|
How the element is drawn, or |
VisualSpec('agents', {'color_by': 'health', 'color_range': (0.0, 2.0)})
|
home
|
Annotated[float, StateSpec(domain=NN)]
|
The location of the home. |
0.0
|
work
|
Annotated[float, StateSpec(domain=NN)]
|
The location of the workplace or school. |
0.0
|
health
|
Annotated[float, StateSpec(domain=NN)]
|
The health state. |
0.0
|
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
64 65 66 67 68 69 70 71 72 73 74 75 76 | |
DegreeClassElement(label, visual=None, *, rho=0.01, lam=0.2, k=1.0, P=1.0)
Bases: Element
Infected density of the nodes of one degree of a network, 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 heterogeneous_mean_field_sis adds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the class or the group of classes. |
required |
visual
|
VisualSpec | None
|
How the element is drawn, or |
None
|
rho
|
Annotated[float, StateSpec(domain=closed_open(0, oo))]
|
The initial infected density. |
0.01
|
lam
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The spreading rate, the ratio of the infection and recovery rates. |
0.2
|
k
|
Annotated[float, ParameterSpec(domain=open(0, oo))]
|
The degree of the class. |
1.0
|
P
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The probability |
1.0
|
Examples:
>>> from skcomplex.core.components.elements import GroupElement
>>> from skcomplex.systems.biology.epidemiology import DegreeClassElement
>>> GroupElement(
... 'network', element=DegreeClassElement, size=2, values={'k': [1.0, 2.0], 'P': [0.5, 0.5]}
... ).prepare().size_
2
Source code in src/skcomplex/systems/biology/epidemiology/_networks.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
EpidemicCenterElement(label, visual=None, *, x=0.0, a=2.2, recovery=6, e=0.005)
Bases: Element
City in a discrete-time SIRS epidemic, where 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 |
visual
|
VisualSpec | None
|
How the element is drawn, or |
None
|
x
|
Annotated[float, StateSpec(domain=closed_open(0, oo), lags=MAX_RECOVERY, initial=(0.0,) * MAX_RECOVERY)]
|
The initial fraction of infected individuals. |
0.0
|
a
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The rate of transmission per contact. |
2.2
|
recovery
|
Annotated[int, ParameterSpec(domain=NN)]
|
The number of steps a recovered individual stays immune, at most 12. |
6
|
e
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The fraction of the infected of the center who visit another center. |
0.005
|
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
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
HostElement(label, visual=None, *, i=0.0, w=1.0)
Bases: Element
Node of a network that is susceptible at i = 0 or infected at i = 1, in continuous time.
A SpreadingInteraction infects and recovers it, and a TopologyInteraction 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 |
visual
|
VisualSpec | None
|
How the element is drawn, or |
None
|
i
|
Annotated[float, StateSpec(domain=closed_open(0, oo))]
|
Whether the node is infected. |
0.0
|
w
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The rate at which the node, while susceptible, rewires an edge to an infected neighbour. |
1.0
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import HostElement
>>> HostElement('node').w
1.0
Source code in src/skcomplex/systems/biology/common/networks/_host.py
39 40 41 42 43 44 45 46 47 48 49 | |
ImmunityLossInteraction(label, *, recovered, susceptible, xi=0.05, stochastic=False)
Bases: ReactionInteraction
Loss of immunity, the reaction R -> S at the rate xi R from recovered back to susceptible.
It is a ReactionInteraction between the states n 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
|
Annotated[str, RoleSpec()]
|
The path of the recovered compartment. |
required |
susceptible
|
Annotated[str, RoleSpec()]
|
The path of the susceptible compartment. |
required |
xi
|
Annotated[float, ParameterSpec(domain=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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
ImmunizingDegreeClassElement(label, visual=None, *, s=0.999, i=0.001, r=0.0, beta=0.1, mu=1.0, k=1.0, P=1.0)
Bases: Element
Susceptible, infected, and recovered densities of the nodes of one degree, 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
heterogeneous_mean_field_sir adds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the class or the group of classes. |
required |
visual
|
VisualSpec | None
|
How the element is drawn, or |
None
|
s
|
Annotated[float, StateSpec(domain=closed_open(0, oo))]
|
The initial susceptible density. |
0.999
|
i
|
Annotated[float, StateSpec(domain=closed_open(0, oo))]
|
The initial infected density. |
0.001
|
r
|
Annotated[float, StateSpec(domain=closed_open(0, oo))]
|
The initial recovered density. |
0.0
|
beta
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The rate of transmission along one contact. |
0.1
|
mu
|
Annotated[float, ParameterSpec(domain=open(0, oo))]
|
The recovery rate. |
1.0
|
k
|
Annotated[float, ParameterSpec(domain=open(0, oo))]
|
The degree of the class. |
1.0
|
P
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The probability |
1.0
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import ImmunizingDegreeClassElement
>>> GroupElement(
... 'network',
... element=ImmunizingDegreeClassElement,
... size=3,
... values={'k': [1.0, 2.0, 3.0], 'P': [0.5, 0.3, 0.2]},
... ).size
3
Source code in src/skcomplex/systems/biology/epidemiology/_outbreaks.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
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 from susceptible to infected.
It is a ReactionInteraction between the states n 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
|
Annotated[str, RoleSpec()]
|
The path of the susceptible compartment. |
required |
infected
|
Annotated[str, RoleSpec()]
|
The path of the infected compartment. |
required |
beta
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The transmission rate. |
0.001
|
stochastic
|
bool
|
Whether infections are random events. |
False
|
Examples:
>>> from skcomplex.core.components.elements import CompartmentElement
>>> from skcomplex.core.components.system import System
>>> from skcomplex.core.engine.runtime import Simulation
>>> from skcomplex.systems.biology.epidemiology import InfectionInteraction
>>> system = System(
... elements=[CompartmentElement('S', n=99.0), CompartmentElement('I', n=1.0)],
... interactions=[InfectionInteraction('infection', susceptible='S', infected='I', beta=0.01)],
... )
>>> trajectory = Simulation(system, dt=0.1).prepare().run(until=5.0).trajectory_
>>> round(float(trajectory.values('S.n')[-1] + trajectory.values('I.n')[-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 | |
PartnershipEpidemicElement(label, visual=None, *, S=0.99, E=0.0, I=0.01, R=0.0, J=0.0, c=2.0, beta=0.2, tau=1.0, T=0.5, nu=0.1)
Bases: Element
Population of Watts and May whose infections pass along partnerships that last, 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. The infection starts at time
zero, so the infectious and the memory are zero before it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the population. |
required |
visual
|
VisualSpec | None
|
How the element is drawn, or |
None
|
S
|
Annotated[float, StateSpec(domain=FRACTION)]
|
The initial fraction of susceptible people. |
0.99
|
E
|
Annotated[float, StateSpec(domain=FRACTION)]
|
The initial fraction of exposed people. |
0.0
|
I
|
Annotated[float, StateSpec(domain=FRACTION, history=0.0)]
|
The initial fraction of infectious people. |
0.01
|
R
|
Annotated[float, StateSpec(domain=FRACTION)]
|
The initial fraction of people who developed the disease. |
0.0
|
J
|
Annotated[float, StateSpec(domain=closed_open(0, oo), history=0.0)]
|
The initial infection memory of current partnerships. |
0.0
|
c
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The rate of acquiring new partners. |
2.0
|
beta
|
Annotated[float, ParameterSpec(domain=FRACTION)]
|
The probability of infection by an infectious partner over a partnership. |
0.2
|
tau
|
Annotated[float, ParameterSpec(domain=open(0, oo))]
|
The mean duration of a partnership. |
1.0
|
T
|
Annotated[float, ParameterSpec(domain=open(0, oo))]
|
The duration of the exposed period. |
0.5
|
nu
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The rate at which the infectious develop the disease. |
0.1
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import PartnershipEpidemicElement
>>> PartnershipEpidemicElement('population').tau
1.0
Source code in src/skcomplex/systems/biology/epidemiology/_concurrency.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
PathogenElement(label, visual=None, *, eta=0.0)
Bases: Element
Pathogen whose strength in every season is drawn anew, uniformly from zero to one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the pathogen. |
required |
visual
|
VisualSpec | None
|
How the element is drawn, or |
None
|
eta
|
Annotated[float, StateSpec(domain=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
42 43 44 45 46 47 48 49 50 | |
PersonElement(label, visual=VisualSpec('agents', {'color_by': 'health', 'color_range': (0.0, 4.0)}), *, 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)
Bases: Element
Person of the agent-based SIR system, with 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. Transitions of the agent form, which
agent_based_sir 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 follows the convention of the residence time after of TransitionInteraction: 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 |
visual
|
VisualSpec | None
|
How the element is drawn, or |
VisualSpec('agents', {'color_by': 'health', 'color_range': (0.0, 4.0)})
|
health
|
Annotated[float, StateSpec(domain=NN)]
|
The health state. |
SUSCEPTIBLE
|
d
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The probability of moving at every step. |
0.8
|
beta
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The probability that an infectious person infects the susceptible persons of its cell. |
0.6
|
gamma
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The probability of recovering at every step. |
0.01
|
mu
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The probability of dying at every step of the infection. |
0.0
|
alpha
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The probability of losing immunity at every step. |
0.0
|
lockdown_start
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The step at which the lockdown starts. |
0.0
|
lockdown_length
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The number of steps of the lockdown, 0 for none. |
0.0
|
lockdown_d
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The probability of moving during the lockdown. |
0.1
|
Examples:
>>> from skcomplex.core.components.elements import GroupElement
>>> from skcomplex.systems.biology.epidemiology import PersonElement
>>> GroupElement('people', element=PersonElement, size=100).size
100
Source code in src/skcomplex/systems/biology/epidemiology/_agents.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
RecoveryInteraction(label, *, infected, recovered, gamma=0.1, stochastic=False)
Bases: ReactionInteraction
Recovery, the reaction I -> R at the rate gamma I from infected to recovered.
It is a ReactionInteraction between the states n 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
|
Annotated[str, RoleSpec()]
|
The path of the infected compartment. |
required |
recovered
|
Annotated[str, RoleSpec()]
|
The path of the recovered compartment. |
required |
gamma
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The recovery rate. |
0.1
|
stochastic
|
bool
|
Whether recoveries are random events. |
False
|
Examples:
>>> from skcomplex.core.components.elements import CompartmentElement
>>> from skcomplex.core.components.system import System
>>> from skcomplex.core.engine.runtime import Simulation
>>> from skcomplex.systems.biology.epidemiology import RecoveryInteraction
>>> system = System(
... elements=[CompartmentElement('I', n=10.0), CompartmentElement('R')],
... interactions=[RecoveryInteraction('recovery', infected='I', recovered='R', gamma=0.5)],
... )
>>> trajectory = Simulation(system, dt=0.01).prepare().run(until=2.0).trajectory_
>>> round(float(trajectory.values('I.n')[-1]), 3)
3.679
Source code in src/skcomplex/systems/biology/epidemiology/_factories.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
ResidentElement(label, visual=None, *, R=0.5, infected=0.0)
Bases: Element
Resident of a population with a fixed resistance to a disease, immune for good once infected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the resident or of the group of residents. |
required |
visual
|
VisualSpec | None
|
How the element is drawn, or |
None
|
R
|
Annotated[float, StateSpec(domain=closed(0, 1))]
|
The resistance, between 0 and 1, where 1 is immunity. |
0.5
|
infected
|
Annotated[float, StateSpec(domain=FiniteEnumeratedSet([0, 1]))]
|
Whether the resident was infected in the last outbreak. |
0.0
|
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
88 89 90 91 92 93 94 95 96 97 98 | |
ResistanceInfectionInteraction(label, *, residents, pathogen)
Bases: Interaction
Infection of every resident whose resistance is below the strength of the season's strain, who 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
|
Annotated[str, RoleSpec()]
|
The path of the group of residents. |
required |
pathogen
|
Annotated[str, RoleSpec()]
|
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
122 123 124 125 126 127 128 129 130 131 | |
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: TransitionInteraction
Spreading of the active value of a discrete state 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
transition 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 parts of its system. |
required |
target
|
Annotated[str, RoleSpec()]
|
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, ParameterSpec(domain=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, ParameterSpec(domain=closed_open(0, oo))]
|
The rate of recovery of an active member. |
0.0
|
omega
|
Annotated[float, ParameterSpec(domain=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
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
SubpopulationElement(label, visual=None, *, S=1000.0, I=0.0, R=0.0, beta=0.3, gamma=0.1, D=0.01)
Bases: Element
Well-mixed SIR population at a node of a network, whose individuals hop along each edge at the rate D.
Inside the node, beta S I / N individuals are infected and gamma I recover per unit time, with
N = S + I + R. Hopping along every edge adds D times the graph Laplacian to every compartment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the subpopulation or the field. |
required |
visual
|
VisualSpec | None
|
How the element is drawn, or |
None
|
S
|
Annotated[float, StateSpec(domain=closed_open(0, oo))]
|
The initial number of susceptible individuals. |
1000.0
|
I
|
Annotated[float, StateSpec(domain=closed_open(0, oo))]
|
The initial number of infected individuals. |
0.0
|
R
|
Annotated[float, StateSpec(domain=closed_open(0, oo))]
|
The initial number of recovered individuals. |
0.0
|
beta
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The infection rate. |
0.3
|
gamma
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The recovery rate. |
0.1
|
D
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The rate at which an individual hops along one edge. |
0.01
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import SubpopulationElement
>>> SubpopulationElement('city', S=1000.0).beta
0.3
Source code in src/skcomplex/systems/biology/epidemiology/_networks.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
TravellerElement(label, visual=VisualSpec('agents', {'color_by': 'health', 'color_range': (0.0, 3.0)}), *, health=SUSCEPTIBLE, tau=0.05, m=0.05)
Bases: Element
Resident of a city at a network node, who 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 TransitionInteraction whose members act on their cell, and another transition 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 |
visual
|
VisualSpec | None
|
How the element is drawn, or |
VisualSpec('agents', {'color_by': 'health', 'color_range': (0.0, 3.0)})
|
health
|
Annotated[float, StateSpec(domain=NN)]
|
The health state. |
SUSCEPTIBLE
|
tau
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The probability of infecting a susceptible traveller of the same node at every step. |
0.05
|
m
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The probability of moving to a neighbouring node at every step. |
0.05
|
Examples:
>>> from skcomplex.core.components.elements import GroupElement
>>> from skcomplex.systems.biology.epidemiology import TravellerElement
>>> GroupElement('travellers', element=TravellerElement, size=10).size
10
Source code in src/skcomplex/systems/biology/epidemiology/_agents.py
175 176 177 178 179 180 181 182 183 184 185 186 187 | |
VaccinatedPopulationElement(label, visual=None, *, S=0.99, I=0.01, R=0.0, u=0.0, beta=0.5, gamma=0.1, a=1.0, b=1.0)
Bases: Element
Susceptible, infected, and recovered fractions of a population vaccinated at a bounded rate.
The fractions follow S' = -beta S I - u S, I' = beta S I - gamma I, and R' = gamma I + u S, where the
vaccination rate u is a control input between 0 and its largest value. The planner minimises the burden of the
infections and the cost of the vaccines, ∫ (a I + b u^2 / 2) dt, after Lenhart and Workman.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the population. |
required |
visual
|
VisualSpec | None
|
How the element is drawn, or |
None
|
S
|
Annotated[float, StateSpec(domain=closed_open(0, oo))]
|
The initial susceptible fraction. |
0.99
|
I
|
Annotated[float, StateSpec(domain=closed_open(0, oo))]
|
The initial infected fraction. |
0.01
|
R
|
Annotated[float, StateSpec(domain=closed_open(0, oo))]
|
The initial recovered fraction. |
0.0
|
u
|
Annotated[float, ParameterSpec(adaptive=True, bounds=(0.0, MAX_RATE))]
|
The vaccination rate, the control input. |
0.0
|
beta
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The transmission rate. |
0.5
|
gamma
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The recovery rate. |
0.1
|
a
|
Annotated[float, ParameterSpec(domain=closed_open(0, oo))]
|
The weight of the infected fraction in the cost. |
1.0
|
b
|
Annotated[float, ParameterSpec(domain=open(0, oo))]
|
The weight of the squared vaccination rate in the cost. |
1.0
|
Examples:
>>> from skcomplex.systems.biology.epidemiology import VaccinatedPopulationElement
>>> VaccinatedPopulationElement('population', I=0.01).I
0.01
Source code in src/skcomplex/systems/biology/epidemiology/_vaccination.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
WalkerElement(label, visual=VisualSpec('agents', {'color_by': 'health', 'color_range': (0.0, 2.0)}), *, health=HEALTHY, infection=1.0, travel=1.0)
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 TransitionInteraction whose members act on their cell makes a sick walker infect
every healthy walker of its cell with probability infection. Another transition 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 |
visual
|
VisualSpec | None
|
How the element is drawn, or |
VisualSpec('agents', {'color_by': 'health', 'color_range': (0.0, 2.0)})
|
health
|
Annotated[float, StateSpec(domain=NN)]
|
The health state. |
HEALTHY
|
infection
|
Annotated[float, ParameterSpec(domain=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, ParameterSpec(domain=closed_open(0, oo))]
|
The probability of moving at every step. |
1.0
|
Examples:
>>> from skcomplex.core.components.elements import GroupElement
>>> from skcomplex.systems.biology.epidemiology import WalkerElement
>>> GroupElement('walkers', element=WalkerElement, size=10).size
10
Source code in src/skcomplex/systems/biology/epidemiology/_agents.py
237 238 239 240 241 242 243 244 245 246 247 248 249 | |
activity_driven_epidemics(n=500, *, m=2, exponent=2.2, least=0.01, lam=0.9, mu=0.1, infected=0.05, seed=1)
Return 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.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the states |
Examples:
>>> from skcomplex.systems.biology.epidemiology import activity_driven_epidemics
>>> float(activity_driven_epidemics(n=10, seed=0).elements[0].values['a'].min()) >= 0.01
True
Source code in src/skcomplex/systems/biology/epidemiology/_adaptive.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 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 359 360 361 362 363 364 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 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
adaptive_sis(n=200, k=6.0, *, beta=0.4, gamma=1.0, w=1.0, infected=0.2, seed=1)
Return the SIS epidemic on a network whose 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.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the states |
Examples:
>>> from skcomplex.systems.biology.epidemiology import adaptive_sis
>>> [component.label for component in adaptive_sis(n=20).elements]
['hosts', 'contacts']
Source code in src/skcomplex/systems/biology/epidemiology/_adaptive.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
agent_based_sir(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)
Return people who walk on a grid and infect those in their cell, with optional extensions of the SIR system.
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.
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, as the residence time of |
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the group |
Examples:
>>> from skcomplex.systems.biology.epidemiology import agent_based_sir
>>> int(agent_based_sir(people=100, infected=3, random_state=0).elements[0].values['health'].sum())
6
Source code in src/skcomplex/systems/biology/epidemiology/_agents.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
delayed_sirs(first=0.01, second=0.0, *, a=2.0, recovery=6, e=0.005)
Return two cities with recurrent outbreaks of a disease of 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.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the centers |
Examples:
>>> from skcomplex.systems.biology.epidemiology import delayed_sirs
>>> delayed_sirs().elements[0].x
0.01
Source code in src/skcomplex/systems/biology/epidemiology/_recurrent.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 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 144 145 146 147 148 149 | |
episims_city(people=1000, *, household=3.0, workplace=20.0, p=0.05, gamma=0.1, infected=5, closed=False, seed=0)
Return a synthetic city in the spirit of EpiSims, where 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.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the homes, workplaces, and health states of the agent group |
Examples:
>>> from skcomplex.systems.biology.epidemiology import episims_city
>>> episims_city(100).elements[0].size
100
Source code in src/skcomplex/systems/biology/epidemiology/_cities.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
heterogeneous_mean_field_sir(exponent=2.5, k_min=3, k_max=100, *, beta=0.1, mu=1.0, infected=0.0001)
Return the SIR epidemic on an uncorrelated network of power-law degrees, 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.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the densities |
Examples:
>>> from skcomplex.systems.biology.epidemiology import heterogeneous_mean_field_sir
>>> heterogeneous_mean_field_sir(k_min=2, k_max=5).elements[0].prepare().size_
4
Source code in src/skcomplex/systems/biology/epidemiology/_outbreaks.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
heterogeneous_mean_field_sis(exponent=2.5, k_min=3, k_max=30, *, lam=0.2, rho=0.01)
Return the SIS epidemic on a network with a power-law degree distribution, 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.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the densities |
Examples:
>>> from skcomplex.systems.biology.epidemiology import heterogeneous_mean_field_sis
>>> heterogeneous_mean_field_sis(k_min=2, k_max=5).elements[0].prepare().size_
4
Source code in src/skcomplex/systems/biology/epidemiology/_networks.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
metapopulation(graph=None, *, population=1000.0, infected=10.0, beta=0.3, gamma=0.1, D=0.01)
Return SIR epidemics in subpopulations at the nodes of a network, linked by individuals who travel.
The infection starts in the first node and spreads to the others with the travellers. The total number of individuals stays constant.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the compartments |
Examples:
>>> import networkx as nx
>>> from skcomplex.systems.biology.epidemiology import metapopulation
>>> metapopulation(nx.path_graph(4)).elements[0].prepare().size_
4
Source code in src/skcomplex/systems/biology/epidemiology/_networks.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
network_sir(graph=None, *, residents=20, tau=0.05, days=14.0, m=0.05, random_state=0)
Return SIR epidemics in cities at the nodes of a network, carried between cities by travellers.
Every node starts with the same number of susceptible residents, and one resident of a random node is infected.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the group |
Examples:
>>> import networkx as nx
>>> from skcomplex.systems.biology.epidemiology import network_sir
>>> network_sir(nx.cycle_graph(5), residents=3).elements[0].prepare().size_
15
Source code in src/skcomplex/systems/biology/epidemiology/_agents.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | |
pair_formation_sis(n=400, k=2, *, beta=None, gamma=0.5, sigma=None, pressure=1.5, turnover=2.0, infected=0.05, seed=1)
Return the SIS epidemic on partnerships that dissolve and are replaced at once, with k partners each.
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.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the states |
Examples:
>>> from skcomplex.systems.biology.epidemiology import pair_formation_sis
>>> pair_formation_sis(n=20, k=4).interactions[0].beta
0.375
Source code in src/skcomplex/systems/biology/epidemiology/_concurrency.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
quenched_mean_field_sis(graph=None, *, n=300, m=3, lam=0.2, p=0.05, seed=1)
Return the SIS epidemic on a fixed network in quenched mean field, 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.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the probabilities |
Examples:
>>> import networkx as nx
>>> from skcomplex.systems.biology.epidemiology import quenched_mean_field_sis
>>> quenched_mean_field_sis(nx.cycle_graph(10)).elements[0].prepare().size_
10
Source code in src/skcomplex/systems/biology/epidemiology/_adaptive.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
random_walker_epidemics(width=64, height=64, *, walkers=1000, lifetime=20.0, infection=1.0, travel=1.0, graph=None, random_state=0)
Return random walkers among whom one sick walker starts a deadly epidemic, 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.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the group |
Examples:
>>> from skcomplex.systems.biology.epidemiology import random_walker_epidemics
>>> float(random_walker_epidemics(walkers=50).elements[0].values['health'].sum())
1.0
Source code in src/skcomplex/systems/biology/epidemiology/_agents.py
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 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 621 622 623 624 625 626 627 628 629 630 | |
record_dynamics_epidemic(n=10000, *, seed=0)
Return yearly strains that infect every resident less resistant than their strength, who 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The number of residents. |
10000
|
seed
|
int | None
|
The seed of the resistances. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the resistances |
Examples:
>>> from skcomplex.systems.biology.epidemiology import record_dynamics_epidemic
>>> record_dynamics_epidemic(100).elements[0].prepare().size_
100
Source code in src/skcomplex/systems/biology/epidemiology/_records.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
sir(susceptible=990.0, infected=10.0, recovered=0.0, *, beta=0.0003, gamma=0.1, stochastic=False)
Return an epidemic that moves individuals from susceptible to infected to recovered.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the compartments |
Examples:
>>> from skcomplex.systems.biology.epidemiology import sir
>>> [element.label for element in sir().elements]
['S', 'I', 'R']
Source code in src/skcomplex/systems/biology/epidemiology/_factories.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
sir_vaccination(S=0.99, I=0.01, *, beta=0.5, gamma=0.1, a=1.0, b=1.0)
Return an SIR epidemic with the vaccination rate that minimises the burden of infections and vaccines.
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.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the fractions |
Examples:
>>> from skcomplex.systems.biology.epidemiology import sir_vaccination
>>> sir_vaccination(beta=0.3).elements[0].beta
0.3
Source code in src/skcomplex/systems/biology/epidemiology/_vaccination.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
sirs(susceptible=990.0, infected=10.0, recovered=0.0, *, beta=0.0003, gamma=0.1, xi=0.02, stochastic=False)
Return an epidemic whose immunity wanes, which returns in damped waves to an endemic equilibrium.
The equilibrium has S = gamma / beta susceptible and I = xi (N - S) / (gamma + xi) infected.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the compartments |
Examples:
>>> from skcomplex.systems.biology.epidemiology import sirs
>>> sirs(xi=0.1).interactions[-1].xi
0.1
Source code in src/skcomplex/systems/biology/epidemiology/_factories.py
355 356 357 358 359 360 361 362 363 364 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 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
sis(susceptible=990.0, infected=10.0, *, beta=0.0003, gamma=0.1, stochastic=False)
Return an infection without immunity, where the recovered become susceptible again and the disease is endemic.
Above the threshold beta N > gamma, the infected settle at I = N - gamma / beta, and below it they die out.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the compartments |
Examples:
>>> from skcomplex.systems.biology.epidemiology import sis
>>> [element.label for element in sis().elements]
['S', 'I']
Source code in src/skcomplex/systems/biology/epidemiology/_factories.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
watts_may_concurrency(infected=0.01, *, c=2.0, beta=0.2, tau=1.0, T=0.5, nu=0.1)
Return the SEIR epidemic of Watts and May, where 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.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the fractions |
Examples:
>>> from skcomplex.systems.biology.epidemiology import watts_may_concurrency
>>> watts_may_concurrency(tau=3.0).elements[0].tau
3.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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
zombie_outbreak(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)
Return the outbreak of zombies of Munz et al., where 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.
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
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The system, with the compartments |
Examples:
>>> from skcomplex.systems.biology.epidemiology import zombie_outbreak
>>> [element.label for element in zombie_outbreak().elements]
['S', 'Z', 'R']
Source code in src/skcomplex/systems/biology/epidemiology/_factories.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |