API Reference
Graphon Types
Graphons.AbstractGraphon — TypeAbstractGraphon{T,M}Abstract base type for all graphon models.
Type Parameters
T: The edge type (e.g.,Boolfor simple graphs,Float64for weighted graphs,SizedVector{2,Bool}for multiplex networks)M: The matrix type for sampled graphs (e.g.,BitMatrix,Matrix{T},SparseMatrixCSC{T,Int},GBMatrix{T})
Edge Types
Bool: Simple (unweighted) graphs<:Real: Weighted graphs with numeric edge weights<:AbstractVector{Bool}: Multiplex networks with multiple edge types
Matrix Types
BitMatrixorMatrix{Bool}: Dense representation for simple graphsMatrix{T}: Dense representation for weighted/decorated graphsSparseMatrixCSC{T,Int}: Sparse representation for low-density graphsGBMatrix{T}: GraphBLAS representation (requires SuiteSparseGraphBLAS extension)
All graphon types must:
- Be callable:
graphon(x, y)returns probability or distribution at positionsx, y ∈ [0,1] - Support
make_empty_graph(M, n)for creating empty adjacency matrices - Implement sampling through
_rand!method
Subtypes
SimpleContinuousGraphon: Continuous function-based graphonsSBM: Stochastic block modelsDecoratedGraphon: Graphons with distribution-valued edgesDecoratedSBM: Block models with distribution-valued edgesSSM: Stochastic shape models
See Also
rand,sample_graph: Sampling functions
Graphons.SimpleGraphon — TypeSimpleGraphon{M}Type alias for graphons representing simple (unweighted) graphs with Boolean edges.
Equivalent to AbstractGraphon{Bool,M} where M is a matrix type storing Boolean values.
Graphons.WeightedGraphon — TypeWeightedGraphon{M}Type alias for graphons representing weighted graphs with Float64 edges.
Equivalent to AbstractGraphon{Float64,M} where M is a matrix type storing Float64 values.
Graphons.SimpleContinuousGraphon — TypeSimpleContinuousGraphon{M,F} <: SimpleGraphon{M}A continuous graphon represented by a function f(x, y) that returns the probability of an edge between nodes at latent positions x and y in [0,1].
Type Parameters
M: The matrix type used to represent sampled graphs (e.g.,BitMatrix,SparseMatrixCSC{Bool,Int})F: The type of the graphon function
Fields
f::F: A callable functionf(x, y) -> Float64where x, y ∈ [0,1] and the return value is in [0,1]
Constructors
SimpleContinuousGraphon(f, M=BitMatrix)Create a continuous graphon from function f with matrix type M.
Examples
# Constant probability graphon
g = SimpleContinuousGraphon((x, y) -> 0.5)
# Distance-based graphon
g = SimpleContinuousGraphon((x, y) -> exp(-abs(x - y)))
# Sparse matrix representation
g = SimpleContinuousGraphon((x, y) -> 0.1, SparseMatrixCSC{Bool,Int})See Also
SBM: Discrete stochastic block modeldiscretized_graphon: Discretize a continuous graphon
Graphons.SBM — TypeSBM{P,S,S2} <: AbstractGraphon{Bool,BitMatrix}A Stochastic Block Model (SBM) is a discrete graphon with K blocks where edge probabilities depend only on the block membership of nodes.
Fields
θ::P: K×K matrix of edge probabilities between blocks, where θ[i,j] is the probability of an edge between block i and jsize::S: Vector of block sizes (must sum to 1), representing the proportion of nodes in each blockcumsize::S2: Cumulative sum of block sizes for efficient block assignment
Constructor
SBM(θ, sizes)Create a stochastic block model with edge probability matrix θ and block sizes sizes.
Arguments
θ: K×K matrix where each entry is in [0,1]sizes: Vector of K positive values that sum to 1
Examples
# Two-block assortative model
θ = [0.8 0.1; 0.1 0.8]
sizes = [0.5, 0.5]
sbm = SBM(θ, sizes)
# Three-block model with unequal sizes
θ = [0.9 0.1 0.2; 0.1 0.8 0.1; 0.2 0.1 0.7]
sizes = [0.3, 0.5, 0.2]
sbm = SBM(θ, sizes)See Also
SimpleContinuousGraphon: Continuous graphon representationdiscretized_graphon: Convert continuous graphon to SBM
Graphons.DecoratedGraphon — TypeDecoratedGraphon{T,M,F,D} <: AbstractGraphon{T,M}A decorated graphon where edges have rich attributes drawn from distributions. Instead of returning edge probabilities, the graphon function returns a distribution from which edge values are sampled.
Type Parameters
T: The type of edge values (inferred from the distribution)M: The matrix type for sampled graphsF: The type of the graphon functionD: The type of distributions returned by the function
Fields
f::F: A callable functionf(x, y) -> Distributionwhere x, y ∈ [0,1]
Constructors
DecoratedGraphon(f)
DecoratedGraphon(f, M)Create a decorated graphon from function f. The edge type is automatically inferred by evaluating f(0.1, 0.2).
Examples
using Distributions
# Edges are normal random variables
g = DecoratedGraphon((x, y) -> Normal(x + y, 0.1))
# Edges are Poisson counts
g = DecoratedGraphon((x, y) -> Poisson(10 * x * y))
# With custom matrix type
g = DecoratedGraphon((x, y) -> Normal(0, 1), Matrix{Float64})See Also
DecoratedSBM: Block model with distributionsSimpleContinuousGraphon: Simple graphon with probabilities
Graphons.DecoratedSBM — TypeDecoratedSBM{D,M,P,S,S2} <: AbstractGraphon{eltype(M),M}A Stochastic Block Model where edges have rich attributes drawn from distributions. Each block pair (i,j) has an associated distribution from which edge values are sampled.
Fields
θ::P: K×K matrix of distributions, where θ[i,j] is the distribution for edges between block i and jsize::S: Vector of block sizes (must sum to 1)cumsize::S2: Cumulative sum of block sizes
Constructor
DecoratedSBM(θ, sizes, M=Matrix{...})Create a decorated SBM with distribution matrix θ and block sizes sizes.
Arguments
θ: K×K matrix of Distribution objectssizes: Vector of K positive values that sum to 1M: (Optional) Matrix type for sampled graphs
Examples
using Distributions
# Two-block model with Normal edges
θ = [Normal(1.0, 0.1) Normal(0.0, 0.1);
Normal(0.0, 0.1) Normal(1.0, 0.1)]
sizes = [0.5, 0.5]
dsbm = DecoratedSBM(θ, sizes)
# Poisson-weighted edges
θ = [Poisson(10) Poisson(2); Poisson(2) Poisson(10)]
dsbm = DecoratedSBM(θ, sizes)See Also
DecoratedGraphon: Continuous decorated graphonSBM: Simple block model with probabilities
Graphons.SSM — TypeSSM{T,M,V,B,S,S2} <: AbstractGraphon{T,M}A Stochastic Shape Model (SSM) is an extension of the Stochastic Block Model (SBM). See (Verdeyme and Olhede, 2024) for details.
Sampling Functions
Base.rand — Methodrand([rng::AbstractRNG], graphon::AbstractGraphon{T,M}, n::Int) -> MGenerate a random graph from a graphon with n nodes.
Latent positions for each node are drawn uniformly at random from [0,1], and edges are sampled according to the graphon. For simple graphons, edges are present with probability f(ξᵢ, ξⱼ). For decorated graphons, edge weights are sampled from the distribution f(ξᵢ, ξⱼ).
Arguments
rng: Random number generator (optional, defaults toRandom.default_rng())graphon: A graphon model (e.g.,SimpleContinuousGraphon,SBM,DecoratedGraphon)n: Number of nodes in the graph
Returns
An adjacency matrix of type M (determined by the graphon) with:
- Symmetric structure:
A[i,j] == A[j,i] - No self-loops:
A[i,i] == 0for all i - Edge type
T(Bool for simple graphs, Float64 for weighted, etc.)
Examples
# Simple random graph
g = SimpleContinuousGraphon((x, y) -> 0.3)
A = rand(g, 100) # 100-node graph with 30% edge probability
# Reproducible sampling
using Random
rng = MersenneTwister(42)
A = rand(rng, g, 100)
# Stochastic block model
sbm = SBM([0.8 0.1; 0.1 0.8], [0.5, 0.5])
A = rand(sbm, 200)
# Decorated graphon with weighted edges
using Distributions
dg = DecoratedGraphon((x, y) -> Normal(x + y, 0.1))
W = rand(dg, 50) # Returns Matrix{Float64}See Also
sample_graph: Sample with fixed latent positionsSimpleContinuousGraphon,SBM,DecoratedGraphon
Graphons.sample_graph — Functionsample_graph([rng::AbstractRNG], graphon::AbstractGraphon, n::Int) -> M
sample_graph([rng::AbstractRNG], graphon::AbstractGraphon, ξs::AbstractVector) -> MGenerate a graph from a graphon with deterministic or specified latent positions.
This function provides more control than rand by allowing you to:
- Use evenly-spaced latent positions
ξ = [0, 1/(n-1), 2/(n-1), ..., 1] - Specify custom latent positions for each node
Graphs sampled with the same latent positions will have the same expected structure, making this useful for reproducibility and controlled experiments.
Arguments
rng: Random number generator (optional)graphon: A graphon modeln: Number of nodes (latents will be evenly spaced on [0,1])ξs: Vector of latent positions in [0,1], one per node
Returns
An adjacency matrix of type M with symmetric structure and no self-loops.
Examples
# Evenly-spaced latents
g = SimpleContinuousGraphon((x, y) -> x * y)
A = sample_graph(g, 10) # Uses ξ = [0, 0.111..., 0.222..., ..., 1]
# Custom latent positions
ξs = [0.1, 0.2, 0.5, 0.9]
A = sample_graph(g, ξs)
# Reproducible with same latents
using Random
rng = MersenneTwister(42)
A1 = sample_graph(rng, g, ξs)
rng = MersenneTwister(42)
A2 = sample_graph(rng, g, ξs)
# A1 and A2 will be identical
# Compare random vs deterministic latents
A_random = rand(g, 100) # Random latents
A_fixed = sample_graph(g, 100) # Evenly-spaced latentsSee Also
rand: Sample with random latent positionsSimpleContinuousGraphon,SBM,DecoratedGraphon
Utility Functions
Graphons.discretized_graphon — Functiondiscretized_graphon(f::SimpleContinuousGraphon, k::Int) -> SBMDiscretize a continuous graphon into a Stochastic Block Model with k blocks by evaluating the graphon at a uniform grid of points.
Arguments
f: A continuous graphonk: Number of blocks for discretization
Returns
An SBM with k blocks approximating the continuous graphon.
Examples
# Create continuous graphon
f = SimpleContinuousGraphon((x, y) -> min(x, y))
# Discretize into 10-block SBM
sbm = discretized_graphon(f, 10)See Also
SimpleContinuousGraphon: Continuous graphon typeSBM: Stochastic block model type
discretized_graphon(f::DecoratedGraphon, k::Int) -> DecoratedSBMDiscretize a continuous decorated graphon into a block model with k blocks by evaluating the graphon at a uniform grid of points.
Arguments
f: A decorated graphonk: Number of blocks for discretization
Returns
A DecoratedSBM with k blocks approximating the continuous graphon.
Examples
using Distributions
# Create continuous decorated graphon
f = DecoratedGraphon((x, y) -> Normal(x * y, 0.1))
# Discretize into 10-block model
dsbm = discretized_graphon(f, 10)See Also
DecoratedGraphon: Continuous decorated graphonDecoratedSBM: Block model with distributions