Networks
This document describes the available network classes for building graphs in NextNet.
Static networks
All static networks inherit the follow common methods:
-
nodes() -> int
Number of nodes in the network. -
neighbour(node: int, idx: int) -> int
Get theidx
th neighbor ofnode
, or-1
if none. -
outdegree(node: int) -> int
Number of outgoing edges fromnode
. -
is_undirected() -> bool
True if every edge is bidirectional. -
is_simple() -> bool
True if the network has no self‑loops or parallel edges. -
adjacencylist() -> List[List[int]]
Returns the full adjacency list: for each node, list of neighbor indices. -
(only if weighted)
weighted_adjacencylist() -> List[List[Tuple[int, float]]]
Compute the weighted adjacency list. Returns, for each node, a list of(neighbor_index, weight)
pairs.
Using networks from the NetworkX library
the NextNet python library is made so that it operates with the networkx library which offers a great way to generate and analyse a large collection of random networks.
Constructors:
networkx(adjacency_list: list)
networkx(nx_graph: networkx.Graph)
Wraps a Python NetworkX graph for use in simulations. It works with any networkx graph object, as long as the nodes are labeled as integers.
Example:
import networkx as nx
n=10**5
p = 3/n
gx = nx.fast_gnp_random_graph(n,p)
gx=nx.convert_node_labels_to_integers(gx)
g = nn.networkx(gx)
Networks from a file
empirical_network
empirical_network(path: str,
undirected: bool = True,
simplify: bool = False,
idxbase: int = 1,
sep: char = ' ')
Construct from an edge‐list file.
path
: path to whitespace‐separated edge listundirected
: add edges in both directions (defaultTrue
)simplify
: remove self‑loops and parallel edges (defaultFalse
)idxbase
: node index base in file (e.g.0
or1
, default1
)sep
: field separator (default' '
)
Random Graph Models
watts_strogatz
Generate a Watts–Strogatz small‑world network.
size
: number of nodesk
: each node connects tok
nearest neighborsp
: rewiring probabilityrng
: random number generator
erdos_renyi
Generate an Erdős–Rényi random graph G(n, p) where p = average_degree/(n-1)
.
size
: number of nodesn
average_degree
: desired mean degreerng
: random number generator
barabasi_albert
Generate a Barabási–Albert scale‑free network.
size
: initial number of nodesrng
: random number generatorm
: new edges added per added node (default1
)
configuration_model
Generate a random network with a prescribed degree sequence.
degreelist
: list of desired node degreesrng
: random number generator
Remark: The sum of the degree list needs to be even.
configuration_model_clustered
This allows the generated networks from a prescribed degree sequence and tune the clustering. This is a personal implementation of the algorithm presented in the article by Serrano and Boguñá: Tuning clustering in random networks with arbitrary degree distributions. If you use this function in your research, please cite the original paper.
Three constructors:
- Explicit triangles per class:
- Clustering function c(k):
configuration_model_clustered(
degrees: List[int],
ck: Callable[[int], float],
beta: float,
engine: rng)
- Alpha exponent form:
-
triangles_unsatisfied
(bool
): indicates if requested triangles count could not be met. -
See details in original paper.
Temporal networks
All temporal networks inherit from the base temporal_network
interface and extend the static network
functionality.
activity_driven_network
A mechanistic temporal network model where nodes activate stochastically and form temporary links.
activity_driven_network(
activity_rates: List[float],
eta: float,
m: float,
recovery_rate: float,
rng: rng
)
activity_rates
(List[float]
): Activation rate for each node.eta
(float
): Scaling factor for link‐formation probability.m
(float
): Number of links created per activation event.recovery_rate
(float
): Recovery rate for SIR/SIS dynamics when used as a coupled network.rng
(rng
): Random‐number generator for stochastic activations.
empirical_temporal_network
Constructs a temporal network from empirical contact‐sequence data (edge list with timestamps).
file
(str
): Path to the contact‐list file. Each line should specify a contact event (e.g.,time, node_i, node_j
).finite_duration
(bool
): IfTrue
, treat each listed contact as lasting until its next appearance; ifFalse
, treat contacts as instantaneous at resolutiondt
.dt
(float
): Time resolution for discretizing instantaneous contacts.
brownian_proximity_network
Not available on the Python library yet (v.1.0). It is accessible on the R library.
temporal_sirx_network
Not available on the Python library yet (v.1.0). It is accessible on the R library.