Skip to content

Networks

Network realizations shared by the biology packages.

They cover weighted edges, infected hosts, and Boolean nodes.

BooleanFunctionInteraction(label, *, target, inputs, table=(0,))

Bases: Interaction

Synchronous update of a node by a truth table of any number of input nodes.

A table of 2^k entries reads the k inputs as the bits of a binary number, from the most significant, and gives the next value of the target. The update is the sum, over the patterns whose entry is 1, of the product that is 1 exactly on that pattern.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the updated node.

required
inputs tuple[Role, ...]

The paths of the input nodes, in the order of the bits of the table.

required
table tuple[int, ...]

The next value of the target for each of the 2^k input patterns.

(0,)

Raises:

Type Description
ValidationError

The table does not have one entry per pattern of the inputs.

Examples:

>>> from skcomplex.systems.biology.systems_biology import BooleanFunctionInteraction
>>> BooleanFunctionInteraction('and', target='c', inputs=['a', 'b'], table=(0, 0, 0, 1)).table
(0, 0, 0, 1)
Source code in src/skcomplex/systems/biology/common/networks/_boolean_function.py
50
51
52
53
54
55
56
57
58
59
60
61
def __init__(
    self,
    label: str,
    *,
    target: Role,
    inputs: tuple[Role, ...],
    table: tuple[int, ...] = (0,),
) -> None:
    super().__init__(label)
    self.target = target
    self.inputs = inputs
    self.table = table

BooleanNodeElement(label, *, x=0)

Bases: Element

Node of a Boolean network, a gene or protein that is on or off.

Parameters:

Name Type Description Default
label str

The label of the node.

required
x Annotated[float, FiniteEnumeratedSet([0, 1])]

The initial value, 0 or 1.

0

Examples:

>>> from skcomplex.systems.biology.systems_biology import BooleanNodeElement
>>> BooleanNodeElement('Sic1', x=1).x
1
Source code in src/skcomplex/systems/biology/common/networks/_boolean_node.py
29
30
31
32
33
34
35
36
def __init__(
    self,
    label: str,
    *,
    x: Annotated[float, FiniteEnumeratedSet([0, 1])] = 0,
) -> None:
    super().__init__(label)
    self.x = x

EdgeDrawInteraction(label, *, among, noise=0.0, low=-1.0, high=1.0, state='w', along=True)

Bases: Interaction

First draw of the weight of every new edge of a network.

The weights of the other edges drift at random.

Every step of discrete time an edge marked fresh draws its weight uniformly from [low, high] and loses its mark, and every other edge adds noise times a standard normal draw to its weight, or keeps it without noise.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
among Role

The path of the group on the nodes of the network. The weight and the mark are values of the group on its edges.

required
noise Annotated[float, closed_open(0, oo)]

The standard deviation of the drift of a weight in a step, 0 for none.

0.0
low float

The least weight of a new edge.

-1.0
high float

The largest weight of a new edge.

1.0
state str

The name of the state of the edges that holds the weight.

'w'
along bool | str

The edges the laws run on, True for the edges of the network the group lives on, or the name of a layer.

True

Examples:

>>> from skcomplex.systems.biology.common.networks import EdgeDrawInteraction
>>> EdgeDrawInteraction('draw', among='species', noise=0.1).noise
0.1
Source code in src/skcomplex/systems/biology/common/networks/_edge_draw.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def __init__(
    self,
    label: str,
    *,
    among: Role,
    noise: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
    low: float = -1.0,
    high: float = 1.0,
    state: str = 'w',
    along: bool | str = True,
) -> None:
    super().__init__(label, among=among, along=along)
    self.noise = noise
    self.low = low
    self.high = high
    self.state = state

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 for one node.

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
def __init__(
    self,
    label: str,
    *,
    i: Annotated[float | Array, RealSet.closed_open(0, oo)] = 0.0,
    w: Annotated[float | Array, RealSet.closed_open(0, oo)] = 1.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.i = i
    self.w = w

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 for members that recover to the inactive value.

None
form str

'number' for a rate proportional to the number of active neighbours, or 'fraction' for one proportional to their fraction of the neighbours.

'number'
layer str | None

The layer of the network whose edges the spreading runs on, or None for the graph of the network or the neighbourhood of the lattice.

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
def __init__(
    self,
    label: str,
    *,
    target: Role,
    state: str = 'state',
    beta: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    gamma: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
    omega: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
    inactive: float = 0.0,
    active: float = 1.0,
    removed: float | None = None,
    form: str = 'number',
    layer: str | None = None,
) -> None:
    super().__init__(label)
    self.target = target
    self.state = state
    self.beta = beta
    self.gamma = gamma
    self.omega = omega
    self.inactive = inactive
    self.active = active
    self.removed = removed
    self.form = form
    self.layer = layer

WeightedEdgeElement(label, *, w=0.0, fresh=1.0, space=None, on=None)

Bases: Element

Edge of a network with a weight w.

The weight is such as the strength of an influence or a coupling between two species.

A new edge is marked fresh until an EdgeDrawInteraction draws its weight.

Parameters:

Name Type Description Default
label str

The label of the edge or of the group of edges.

required
w float | Array

The weight.

0.0
fresh Annotated[float | Array, FiniteEnumeratedSet([0, 1])]

Whether the edge has not drawn its weight yet, 1 or 0.

1.0
space BaseSpace | None

The network whose edges hold one member each, or None for one edge.

None
on str | None

'edges' for one member per edge of the network, or None for one per node.

None

Examples:

>>> from skcomplex.systems.biology.common.networks import WeightedEdgeElement
>>> WeightedEdgeElement('edge').fresh
1.0
Source code in src/skcomplex/systems/biology/common/networks/_weighted_edge.py
47
48
49
50
51
52
53
54
55
56
57
58
def __init__(
    self,
    label: str,
    *,
    w: float | Array = 0.0,
    fresh: Annotated[float | Array, FiniteEnumeratedSet([0, 1])] = 1.0,
    space: BaseSpace | None = None,
    on: str | None = None,
) -> None:
    super().__init__(label, space=space, on=on)
    self.w = w
    self.fresh = fresh