Generalised multi-valued logical networks
A generalised logical network of Thomas.
- Class:
GeneralizedLogicalNetworkSystem - Import:
from skcomplex.systems.biology.systems_biology import GeneralizedLogicalNetworkSystem - Field:
biology/systems_biology - Topics:
logical network,multi-valued,asynchronous,thomas,jumps - References:
- Thomas 1991
- Raman 2021
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.biology.systems_biology import GeneralizedLogicalNetworkSystem
trajectory = GeneralizedLogicalNetworkSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
regulations |
None |
levels |
None |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | continuous |
| Space | none |
| Laws | jump |
| Randomness | stochastic |
| Domains | integer |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class GeneralizedLogicalNetworkSystem(BaseSystem):
"""A generalised logical network of Thomas.
Its variables step asynchronously towards focal levels.
Every variable takes discrete levels, and each of its regulators acts once its level reaches a threshold. The
logical parameters give the focal level of the variable for every combination of acting regulators, and the variable
rises or falls one level at a time towards it, each step a random event, so the dynamics explores the asynchronous
state transition graph. The default is the negative circuit of a three-level `x` that activates `y` at its second
threshold and a Boolean `y` that represses `x`, whose state graph is a cycle, a sustained oscillation. A positive
circuit, two mutual repressors, has two stable states instead. The system has the levels `<variable>.level`.
Args:
regulations:
For every variable, its regulators, their thresholds, and the logical parameters of its focal level, or
`None` for the negative circuit.
levels:
The initial level of every variable, or `None` for 0.
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.systems_biology import GeneralizedLogicalNetworkSystem
>>> [element.label for element in GeneralizedLogicalNetworkSystem().prepare().system_.elements]
['x', 'y']
"""
field = 'biology/systems_biology'
topics = ('logical network', 'multi-valued', 'asynchronous', 'thomas', 'jumps')
references = ('Thomas 1991', 'Raman 2021')
until = 50.0
dt = 0.25
def __init__(
self,
regulations: Regulations | None = None,
levels: Mapping[str, int] | None = None,
*,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.regulations = regulations
self.levels = levels
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of a generalised logical network of Thomas.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
network = NEGATIVE_CIRCUIT if self.regulations is None else self.regulations
start = self.levels or {}
self.system_ = System(
self.label,
elements=[LogicalVariableElement(name, level=float(start.get(name, 0))) for name in network],
interactions=[
LogicalRegulationInteraction(
f'{name}_regulation',
target=name,
regulators=tuple(regulators),
thresholds=tuple(thresholds),
parameters=dict(parameters),
)
for name, (regulators, thresholds, parameters) in network.items()
],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
LogicalVariableElement, fromElement
Interactions:
LogicalRegulationInteraction, fromInteraction
class LogicalVariableElement(Element):
"""Variable of a generalised logical network.
It is a discrete level from zero to its largest level.
The levels stand for qualitative concentrations, such as absent, basal, medium, or high, cut at the thresholds at
which the variable acts on its targets.
Args:
label:
The label of the variable.
level:
The initial level.
Examples:
>>> from skcomplex.systems.biology.systems_biology import LogicalVariableElement
>>> LogicalVariableElement('x', level=2.0).level
2.0
"""
def __init__(
self,
label: str,
*,
level: Annotated[float, NN] = 0.0,
) -> None:
super().__init__(label)
self.level = level
class LogicalRegulationInteraction(Interaction):
"""Regulation of a logical variable.
It steps one level at a time towards the focal level its regulators set.
In the formalism of Thomas, every regulator acts when its level reaches its threshold. The logical parameters map
every combination of acting regulators, a tuple of truth values in the order of the regulators, to the focal level
of the target. The target rises or falls by one level towards its focal level at the unit rate, so the transitions
of all variables are asynchronous random events.
Args:
label:
The label of the interaction.
target:
The path of the regulated variable.
regulators:
The paths of the regulating variables.
thresholds:
The level at which every regulator acts, in the order of the regulators.
parameters:
The focal level of the target for every combination of acting regulators.
Examples:
>>> from skcomplex.systems.biology.systems_biology import LogicalRegulationInteraction
>>> regulation = LogicalRegulationInteraction(
... 'x_regulation', target='x', regulators=['y'], thresholds=(1,), parameters={(False,): 2, (True,): 0}
... )
>>> regulation.parameters[(True,)]
0
"""
law_classes = (JumpLaw,)
def __init__(
self,
label: str,
*,
target: Role,
regulators: tuple[Role, ...] = (),
thresholds: Sequence[int] = (),
parameters: Mapping[tuple[bool, ...], int] | None = None,
) -> None:
super().__init__(label)
self.target = target
self.regulators = regulators
self.thresholds = thresholds
self.parameters = parameters
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the steps of the target up and down towards its focal level.
Args:
context:
The namespace of the bound elements, the time `t`, and the parameters.
"""
super()._prepare(context)
s = context
level = s.target.level
focal = self._get_focal(s.regulators)
self.laws_ = [
JumpLaw(where(focal > level, 1, 0), {level: 1}),
JumpLaw(where(focal < level, 1, 0), {level: -1}),
]
def _get_focal(self, regulators: Sequence[SimpleNamespace]) -> Expression:
"""Return the focal level of the target.
It is the logical parameter of the regulators that act.
"""
parameters = self.parameters or {}
focal: Expression = SR(0)
for acting in product((False, True), repeat=len(regulators)):
indicator: Expression = SR(1)
for regulator, threshold, active in zip(regulators, self.thresholds, acting, strict=True):
indicator *= (
where(regulator.level >= threshold, 1, 0) if active else where(regulator.level < threshold, 1, 0)
)
focal += parameters.get(acting, 0) * indicator
return focal