Two-layer adaptive oscillator model of sepsis
The two-layer model of tumour disease and sepsis.
- Class:
TwoLayerSepsisSystem - Import:
from skcomplex.systems.biology.physiology import TwoLayerSepsisSystem - Field:
biology/physiology - Topics:
sepsis,adaptive network,multiplex,phase oscillators,ode - References:
- Sawicki et al. 2022
- Berner et al. 2023
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.biology.physiology import TwoLayerSepsisSystem
trajectory = TwoLayerSepsisSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
n_cells |
20 |
beta |
1.5707963267948966 |
sigma |
1.0 |
pathological |
0.0 |
omega_healthy |
0.0 |
omega_pathological |
1.0 |
omega_immune |
0.0 |
alpha_p |
0.9424777960769379 |
alpha_s |
1.0995574287564276 |
epsilon_p |
0.03 |
epsilon_s |
0.3 |
connectivity |
0.5 |
seed |
0 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | continuous |
| Space | network |
| Laws | rate |
| Randomness | unknown |
| Domains | real |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class TwoLayerSepsisSystem(BaseSystem):
"""The two-layer model of tumour disease and sepsis.
Its parenchymal and immune cells are adaptive oscillators.
The parenchymal layer of `n_cells` phase oscillators couples through fixed links `a_ij`, drawn as 1 with the
probability `connectivity`, and adaptive cytokine links `kappa_ij`. The immune layer couples through adaptive links
alone, which adapt ten times faster, and every cell couples to its partner in the other layer with strength `sigma`.
Following Eqs. (40) and (41) of Berner et al. (2023), `dphi_i/dt = omega_i - sum_j (a_ij + kappa_ij) sin(phi_i -
phi_j + alpha) / N - sigma sin(phi_i - phi_i')` and `dkappa_ij/dt = -epsilon (kappa_ij + sin(phi_i - phi_j -
beta))`. The healthy state is the frequency-synchronized one, and the age parameter `beta` and a fraction
`pathological` of cells with another natural frequency push the layers into desynchronized, pathological states. The
system has the phases `cells.phi`, the parenchymal cells first and the immune cells after, and the couplings
`parenchymal_links.kappa` and `immune_links.kappa`.
Args:
n_cells:
The number of cells of each layer.
beta:
The age parameter of the adaptation.
sigma:
The coupling between the layers.
pathological:
The fraction of pathological parenchymal cells.
omega_healthy:
The natural frequency of healthy parenchymal cells.
omega_pathological:
The natural frequency of pathological parenchymal cells.
omega_immune:
The natural frequency of the immune cells.
alpha_p:
The phase lag of the parenchymal layer.
alpha_s:
The phase lag of the immune layer.
epsilon_p:
The adaptation rate of the parenchymal links.
epsilon_s:
The adaptation rate of the immune links.
connectivity:
The probability of a fixed parenchymal link.
seed:
The seed of the fixed links, the pathological cells, and the initial phases and couplings.
label:
The label of the system, which names it when it is nested in another one.
solver:
The solver of the problem, or `'auto'` for the one the system chooses.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Examples:
>>> from skcomplex.systems.biology.physiology import TwoLayerSepsisSystem
>>> TwoLayerSepsisSystem(5).prepare().system_.elements[0].phi.size
10
"""
field = 'biology/physiology'
topics = ('sepsis', 'adaptive network', 'multiplex', 'phase oscillators', 'ode')
references = ('Sawicki et al. 2022', 'Berner et al. 2023')
until = 200.0
dt = 1.0
def __init__(
self,
n_cells: int = 20,
*,
beta: float = 0.5 * math.pi,
sigma: float = 1.0,
pathological: float = 0.0,
omega_healthy: float = 0.0,
omega_pathological: float = 1.0,
omega_immune: float = 0.0,
alpha_p: float = 0.3 * math.pi,
alpha_s: float = 0.35 * math.pi,
epsilon_p: float = 0.03,
epsilon_s: float = 0.3,
connectivity: float = 0.5,
seed: int | None = 0,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.n_cells = n_cells
self.beta = beta
self.sigma = sigma
self.pathological = pathological
self.omega_healthy = omega_healthy
self.omega_pathological = omega_pathological
self.omega_immune = omega_immune
self.alpha_p = alpha_p
self.alpha_s = alpha_s
self.epsilon_p = epsilon_p
self.epsilon_s = epsilon_s
self.connectivity = connectivity
self.seed = seed
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of the two-layer model of tumour disease and sepsis.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
rng = np.random.default_rng(self.seed)
n = self.n_cells
parenchyma = nx.complete_graph(range(n), create_using=nx.DiGraph)
parenchyma.add_nodes_from(range(n, 2 * n))
immune = nx.DiGraph()
immune.add_nodes_from(range(2 * n))
immune.add_edges_from((i, j) for i in range(n, 2 * n) for j in range(n, 2 * n) if i != j)
partners = nx.DiGraph()
partners.add_nodes_from(range(2 * n))
partners.add_edges_from([(i, i + n) for i in range(n)] + [(i + n, i) for i in range(n)])
space = NetworkSpace(parenchyma, layers=[LayerSpec('immune', immune), LayerSpec('partners', partners)])
frequencies = np.full(2 * n, self.omega_immune)
sick = rng.random(n) < self.pathological
frequencies[:n] = np.where(sick, self.omega_pathological, self.omega_healthy)
cells = CellOscillatorElement('cells', phi=rng.uniform(0, 2 * math.pi, 2 * n), omega=frequencies, space=space)
edges = n * (n - 1)
parenchymal_links = CytokineLinkElement(
'parenchymal_links',
kappa=rng.uniform(-1, 1, edges),
a=(rng.random(edges) < self.connectivity).astype(float),
space=space,
on='edges',
)
immune_links = CytokineLinkElement('immune_links', kappa=rng.uniform(-1, 1, edges), space=space, on='immune')
self.system_ = System(
self.label,
elements=[cells, parenchymal_links, immune_links],
interactions=[
CellRotationInteraction('rotation', target='cells'),
AdaptivePhaseCouplingInteraction(
'parenchymal_coupling',
among='cells',
N=n,
alpha=self.alpha_p,
beta=self.beta,
epsilon=self.epsilon_p,
),
AdaptivePhaseCouplingInteraction(
'immune_coupling',
among='cells',
along='immune',
N=n,
alpha=self.alpha_s,
beta=self.beta,
epsilon=self.epsilon_s,
),
LayerCouplingInteraction('interlayer', among='cells', along='partners', sigma=self.sigma),
],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
Interactions:
CellRotationInteraction, fromInteractionAdaptivePhaseCouplingInteraction, fromInteractionLayerCouplingInteraction, fromInteraction
class CellOscillatorElement(Element):
"""Cell oscillators, functional units of a tissue layer reduced to a phase `phi` and a natural frequency `omega`.
Args:
label:
The label of the cell or of the group of cells.
phi:
The initial phase.
omega:
The natural frequency.
space:
The network whose nodes hold one cell each, or `None` for one cell.
Examples:
>>> from skcomplex.systems.biology.physiology import CellOscillatorElement
>>> CellOscillatorElement('cell', omega=0.2).omega
0.2
"""
def __init__(
self,
label: str,
*,
phi: Annotated[float | Array, Period(2 * math.pi)] = 0.0,
omega: float | Array = 0.0,
space: BaseSpace | None = None,
) -> None:
super().__init__(label, space=space)
self.phi = phi
self.omega = omega
class CytokineLinkElement(Element):
"""Link between two cells of a layer.
It has a fixed connectivity `a` and an adaptive cytokine coupling `kappa`.
Args:
label:
The label of the link or of the group on the edges.
kappa:
The initial adaptive coupling, between -1 and 1.
a:
The fixed connectivity, between 0 and 1.
space:
The network whose edges hold one link each, or `None` for one link.
on:
The edges of the network that hold the links, `'edges'` for those of its graph or the name of a layer.
Examples:
>>> from skcomplex.systems.biology.physiology import CytokineLinkElement
>>> CytokineLinkElement('link', a=1.0).a
1.0
"""
def __init__(
self,
label: str,
*,
kappa: Annotated[float | Array, RealSet.closed(-1, 1)] = 0.0,
a: Annotated[float | Array, RealSet.closed(0, 1)] = 0.0,
space: BaseSpace | None = None,
on: str | None = None,
) -> None:
super().__init__(label, space=space, on=on)
self.kappa = kappa
self.a = a
class CellRotationInteraction(Interaction):
"""Rotation of the phase of cell oscillators at their natural frequency, `phi' = omega`.
Healthy and pathological cells differ by their metabolism, which the natural frequency `omega` stands for.
Couplings to other cells add to the rate of the phase.
Args:
label:
The label of the interaction.
target:
The path of the cells, whose values are `phi` and `omega`.
Examples:
>>> from skcomplex.systems.biology.physiology import CellRotationInteraction
>>> CellRotationInteraction('rotation', target='cells').target
'cells'
"""
law_classes = (RateLaw,)
def __init__(self, label: str, *, target: Role) -> None:
super().__init__(label)
self.target = target
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the rotation of the phase.
Args:
context:
The namespace of the target, the time `t`, and the parameters.
"""
super()._prepare(context)
s = context.target
self.laws_ = [RateLaw(s.phi, s.omega)]
class AdaptivePhaseCouplingInteraction(Interaction):
"""Phase coupling of the cells of a layer through adaptive links.
The links adapt to the phase differences they carry.
Along the link from cell `j` to cell `i`, `dphi_i/dt += -(a_ij + kappa_ij) sin(phi_i - phi_j + alpha) / N` and
`dkappa_ij/dt = -epsilon (kappa_ij + sin(phi_i - phi_j - beta))`. The phase lag `alpha` sets the preferred phase
difference of the coupling, and the age parameter `beta` the rule of the adaptation. The links are the element on
the edges the coupling runs along.
Args:
label:
The label of the interaction.
among:
The path of the group of cells on the nodes.
along:
The edges of the layer, `True` for those of the graph of the network or the name of a layer.
N:
The number of cells of the layer, which normalizes the coupling.
alpha:
The phase lag of the coupling.
beta:
The age parameter of the adaptation.
epsilon:
The adaptation rate.
Examples:
>>> from skcomplex.systems.biology.physiology import AdaptivePhaseCouplingInteraction
>>> AdaptivePhaseCouplingInteraction('coupling', among='cells', along='immune', epsilon=0.3).epsilon
0.3
"""
def __init__(
self,
label: str,
*,
among: Role,
along: bool | str = True,
N: Annotated[float, RealSet.open(0, oo)] = 1.0,
alpha: float = 0.0,
beta: float = 0.0,
epsilon: Annotated[float, RealSet.closed_open(0, oo)] = 0.01,
) -> None:
super().__init__(label, among=among, along=along)
self.N = N
self.alpha = alpha
self.beta = beta
self.epsilon = epsilon
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the coupling of the receiving cell and the adaptation of the link.
Args:
context:
The namespace of the two cells of an edge, its link, and the parameters.
"""
super()._prepare(context)
s = context
difference = s.target.phi - s.source.phi
kappa = s.edge.kappa
self.laws_ = [
RateLaw(s.target.phi, -(s.edge.a + kappa) * sin(difference + s.alpha) / s.N),
RateLaw(kappa, -s.epsilon * (kappa + sin(difference - s.beta))),
]
class LayerCouplingInteraction(Interaction):
"""Coupling of every cell to its partner in another layer.
It adds `dphi_i/dt += -sigma sin(phi_i - phi_j)`.
It runs on the edges of the layer of the network that joins the partners, both ways.
Args:
label:
The label of the interaction.
among:
The path of the group of cells on the nodes.
along:
The layer of the network whose edges join the partners.
sigma:
The strength of the coupling between the layers.
Examples:
>>> from skcomplex.systems.biology.physiology import LayerCouplingInteraction
>>> LayerCouplingInteraction('interlayer', among='cells', along='partners', sigma=0.5).along
'partners'
"""
def __init__(
self,
label: str,
*,
among: Role,
along: bool | str = True,
sigma: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
) -> None:
super().__init__(label, among=among, along=along)
self.sigma = sigma
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the pull of the receiving cell towards its partner.
Args:
context:
The namespace of the two cells of an edge and the parameters.
"""
super()._prepare(context)
s = context
self.laws_ = [RateLaw(s.target.phi, -s.sigma * sin(s.target.phi - s.source.phi))]