Skip to content

Generators

The NetworkGenerator protocol and its concrete implementations. Each generator is a frozen dataclass that produces a csr_matrix adjacency from a NumPy Generator.

generator

Network generator protocol and concrete implementations.

Defines a structural typing contract for network generation and provides frozen dataclass implementations for each generation algorithm. All generators are stateless and picklable for multiprocessing.

NetworkGenerator

Bases: Protocol

Structural interface for network generation.

Implementations must be picklable (frozen dataclasses recommended) to support parallel execution via multiprocessing.

generate

generate(rng: Generator) -> csr_matrix

Generate a single network.

Parameters:

Name Type Description Default
rng Generator

Random number generator for this realisation.

required

Returns:

Type Description
csr_matrix

Symmetric adjacency matrix in CSR format.

ErdosRenyiGenerator dataclass

ErdosRenyiGenerator(n: int, p: float)

Erdos-Renyi random graph G(n, p).

ConfigurationModelGenerator dataclass

ConfigurationModelGenerator(
    degrees: NDArray[int_], phi: float = 0.0
)

Configuration model from a fixed degree sequence.

When phi > 0, uses the Clustered Configuration Model to embed triangles and K4 cliques for the target clustering coefficient.

PoissonNetworkGenerator dataclass

PoissonNetworkGenerator(
    n: int,
    mean_degree: float,
    max_degree: int,
    phi: float = 0.0,
)

Configuration model with Poisson-sampled degrees.

Stores only numeric parameters (no callables) so the generator is trivially picklable for multiprocessing.

BigVRewiringGenerator dataclass

BigVRewiringGenerator(
    base: NetworkGenerator, target_clustering: float
)

Compose a base generator with Big-V degree-preserving rewiring.

Generates a network using base, then rewires edges to reach the target clustering coefficient while preserving the degree sequence.

MotifDecompositionGenerator dataclass

MotifDecompositionGenerator(
    num_nodes: int,
    clique_size: int,
    target_clustering: float,
)

Generate networks via motif decomposition (tearing algorithm).

Starts with disconnected cliques and rewires to reduce clustering from 1.0 to the target level.

Parameters:

Name Type Description Default
num_nodes int

Total nodes (must be divisible by clique_size).

required
clique_size int

Size of initial cliques.

required
target_clustering float

Desired global clustering coefficient.

required