API Reference

Graphon Types

Graphons.AbstractGraphonType
AbstractGraphon{T,M}

Abstract base type for all graphon models.

Type Parameters

  • T: The edge type (e.g., Bool for simple graphs, Float64 for 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

  • BitMatrix or Matrix{Bool}: Dense representation for simple graphs
  • Matrix{T}: Dense representation for weighted/decorated graphs
  • SparseMatrixCSC{T,Int}: Sparse representation for low-density graphs
  • GBMatrix{T}: GraphBLAS representation (requires SuiteSparseGraphBLAS extension)

All graphon types must:

  1. Be callable: graphon(x, y) returns probability or distribution at positions x, y ∈ [0,1]
  2. Support make_empty_graph(M, n) for creating empty adjacency matrices
  3. Implement sampling through _rand! method

Subtypes

See Also

source
Graphons.SimpleGraphonType
SimpleGraphon{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.

source
Graphons.WeightedGraphonType
WeightedGraphon{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.

source
Graphons.SimpleContinuousGraphonType
SimpleContinuousGraphon{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 function f(x, y) -> Float64 where 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

source
Graphons.SBMType
SBM{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 j
  • size::S: Vector of block sizes (must sum to 1), representing the proportion of nodes in each block
  • cumsize::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

source
Graphons.DecoratedGraphonType
DecoratedGraphon{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 graphs
  • F: The type of the graphon function
  • D: The type of distributions returned by the function

Fields

  • f::F: A callable function f(x, y) -> Distribution where 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

source
Graphons.DecoratedSBMType
DecoratedSBM{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 j
  • size::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 objects
  • sizes: Vector of K positive values that sum to 1
  • M: (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

source

Sampling Functions

Base.randMethod
rand([rng::AbstractRNG], graphon::AbstractGraphon{T,M}, n::Int) -> M

Generate 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

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] == 0 for 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

source
Graphons.sample_graphFunction
sample_graph([rng::AbstractRNG], graphon::AbstractGraphon, n::Int) -> M
sample_graph([rng::AbstractRNG], graphon::AbstractGraphon, ξs::AbstractVector) -> M

Generate a graph from a graphon with deterministic or specified latent positions.

This function provides more control than rand by allowing you to:

  1. Use evenly-spaced latent positions ξ = [0, 1/(n-1), 2/(n-1), ..., 1]
  2. 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 model
  • n: 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 latents

See Also

source

Utility Functions

Graphons.discretized_graphonFunction
discretized_graphon(f::SimpleContinuousGraphon, k::Int) -> SBM

Discretize 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 graphon
  • k: 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

source
discretized_graphon(f::DecoratedGraphon, k::Int) -> DecoratedSBM

Discretize 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 graphon
  • k: 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

source

Index