Network superposition model of Erdős-Rényi subgraphs
The network superposition model.
- Class:
NetworkSuperpositionSystem - Import:
from skcomplex.systems.mathematics.networks import NetworkSuperpositionSystem - Field:
mathematics/networks - Topics:
network,superposition,random graph,superstatistics,degree distribution - References:
- Abe and Thurner 2005
- Thurner et al. 2018
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.mathematics.networks import NetworkSuperpositionSystem
trajectory = NetworkSuperpositionSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
n_nodes |
100 |
n_subgraphs |
20 |
exponent |
2.0 |
low |
0.005 |
high |
0.1 |
random_state |
0 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | any |
| Space | network |
| Laws | any |
| Randomness | deterministic |
| Domains | any |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class NetworkSuperpositionSystem(BaseSystem):
"""The network superposition model.
It is a union of Erdős-Rényi graphs whose linking probabilities are drawn.
Every one of `n_subgraphs` subgraphs of `n_nodes` nodes draws one linking probability `p` from `Q(p) ~ p^-exponent`
on `[low, high]` and links each pair of its nodes with probability `p`, and the network is their union (Thurner et
al. 2018, section 4.5.2). Its degrees mix the Poisson laws of the subgraphs, `P(k) = ∫ dp P(k | N p) Q(p)`, Eq.
4.34, so a power law of the probabilities gives a power law of the degrees up to the largest mean degree `N high`.
The book draws `p` for every attempted link, which gives one Erdős-Rényi graph of the mean probability, so the
probability is drawn once per subgraph, the reading of Eq. 4.34, like the cells of superstatistics. The system has
the group `nodes` and their states `degree` and `clustering`.
Args:
n_nodes:
The number of nodes of every subgraph.
n_subgraphs:
The number of subgraphs.
exponent:
The exponent of the distribution `Q(p)` of the linking probabilities.
low:
The smallest linking probability.
high:
The largest linking probability.
random_state:
The seed or generator of the linking probabilities and the links.
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.
Raises:
ValidationError:
The bounds of the linking probabilities are not `0 < low <= high <= 1`.
Examples:
>>> from skcomplex.systems.mathematics.networks import NetworkSuperpositionSystem
>>> system = NetworkSuperpositionSystem(10, n_subgraphs=3).prepare().system_
>>> system.elements[0].degree.size
30
"""
field = 'mathematics/networks'
topics = ('network', 'superposition', 'random graph', 'superstatistics', 'degree distribution')
references = ('Abe and Thurner 2005', 'Thurner et al. 2018')
until = 1
dt = 1
def __init__(
self,
n_nodes: int = 100,
*,
n_subgraphs: int = 20,
exponent: float = 2.0,
low: float = 0.005,
high: float = 0.1,
random_state: int | np.random.Generator | None = 0,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.n_nodes = n_nodes
self.n_subgraphs = n_subgraphs
self.exponent = exponent
self.low = low
self.high = high
self.random_state = random_state
@staticmethod
def _get_linking_probabilities(
size: int,
exponent: float,
bounds: tuple[float, float],
rng: np.random.Generator,
) -> Array:
"""Return linking probabilities drawn from `Q(p) ~ p^-exponent` between two bounds.
The draw is by inverse transform.
"""
low, high = bounds
uniform = rng.uniform(size=size)
if exponent == 1:
return low * (high / low) ** uniform
power = 1 - exponent
return (low**power + uniform * (high**power - low**power)) ** (1 / power)
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of the nodes of the union of the subgraphs.
Args:
context:
The observables to compile with the problem, or `None` for none.
Raises:
ValidationError:
The bounds of the linking probabilities are not `0 < low <= high <= 1`.
"""
super()._prepare(context)
if not 0 < self.low <= self.high <= 1:
error_msg = (
f'The linking probabilities lie in [{self.low}, {self.high}]. Give bounds with 0 < low <= high <= 1.'
)
raise ValidationError(error_msg)
rng = np.random.default_rng(self.random_state)
graph = nx.Graph()
for index, chance in enumerate(
self._get_linking_probabilities(self.n_subgraphs, self.exponent, (self.low, self.high), rng),
):
subgraph = nx.fast_gnp_random_graph(self.n_nodes, float(chance), seed=rng)
graph.update(nx.relabel_nodes(subgraph, {node: index * self.n_nodes + node for node in subgraph}))
clustering = nx.clustering(graph)
nodes = SuperposedNodeElement(
'nodes',
degree=np.asarray([graph.degree(node) for node in graph], dtype=float),
clustering=np.asarray([clustering[node] for node in graph], dtype=float),
space=NetworkSpace(graph),
)
self.system_ = System(self.label, elements=[nodes])
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
SuperposedNodeElement, fromElement
class SuperposedNodeElement(Element):
"""Nodes of a superposed network, each with its degree and its clustering.
Args:
label:
The label of the nodes.
degree:
The number of edges of every node, one per node or shared.
clustering:
The share of the pairs of neighbours of every node that are joined, one per node or shared.
space:
The network with one node per site, or `None` for one node.
Examples:
>>> from skcomplex.systems.mathematics.networks import SuperposedNodeElement
>>> SuperposedNodeElement('nodes').clustering
0.0
"""
visual = DEGREE_VISUAL
def __init__(
self,
label: str,
*,
degree: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
clustering: Annotated[object, RealSet.closed(0, 1)] = 0.0,
space: BaseSpace | None = None,
) -> None:
super().__init__(label, space=space)
self.degree = degree
self.clustering = clustering