| Type: | Package |
| Title: | Generates Dense and Sparse Graphs using Graphon Extensions |
| Version: | 0.1.1 |
| Maintainer: | Sevvandi Kandanaarachchi <sevvandik@gmail.com> |
| Description: | Generates dense or sparse graphs using graphon mixtures and graphettes. Graphon mixtures uses two graphons U and W to generate graphs. Sparse graphs are generated in this case using the inverse line graph (root) operation. Graphettes have 3 components, the graphon W, a real-valued sequence and a graph edit function. Both techniques can generate dense or sparse graphs. Kandanaarachchi and Ong (2026) <doi:10.48550/arXiv.2505.13864>, Wijesinghe et al (2026) <doi:10.48550/arXiv.2602.23566>. |
| License: | GPL (≥ 3) |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Imports: | ggplot2, igraph, imager, stats |
| Suggests: | gridExtra, knitr, rmarkdown |
| VignetteBuilder: | knitr |
| URL: | https://sevvandi.github.io/graphonmix/ |
| NeedsCompilation: | no |
| Packaged: | 2026-06-12 06:20:37 UTC; kan092 |
| Author: | Sevvandi Kandanaarachchi
|
| Repository: | CRAN |
| Date/Publication: | 2026-06-12 07:50:02 UTC |
graphonmix: Generates Dense and Sparse Graphs using Graphon Extensions
Description
Generates dense or sparse graphs using graphon mixtures and graphettes. Graphon mixtures uses two graphons U and W to generate graphs. Sparse graphs are generated in this case using the inverse line graph (root) operation. Graphettes have 3 components, the graphon W, a sparsifying sequence and a graph edit function. Both techniques can generate dense or sparse graphs. Kandanaarachchi and Ong (2026) doi:10.48550/arXiv.2505.13864, Wijesinghe et al (2026) doi:10.48550/arXiv.2602.23566.
Author(s)
Maintainer: Sevvandi Kandanaarachchi sevvandik@gmail.com (ORCID)
See Also
Useful links:
Plots the output of extract_sparse function.
Description
Plots the two lines fitted to the unique, sorted log degrees of the graph.
Usage
## S3 method for class 'extract_sparse'
autoplot(object, ...)
Arguments
object |
The output of the function 'extract_sparse' |
... |
Other arguments currently ignored |
Value
A ggplot object.
Examples
library(igraph)
gr <- sample_pa(10000, power = 1.2, directed = FALSE)
sparse <- extract_sparse(gr)
autoplot(sparse)
Plots the output of separate_dense_and_sparse.
Description
Plots the three lines fitted to the unique, sorted log degrees of the graph.
Usage
## S3 method for class 'separate_dense_and_sparse'
autoplot(object, ...)
Arguments
object |
The output of the function 'separate_dense_and_sparse.' |
... |
Other arguments currently ignored |
Value
A ggplot object.
Examples
library(igraph)
W <- matrix(0.1, nrow = 100, ncol = 100)
wts <- c(0.5, 0.3, 0.2)
ns <- 200
nd <- 100
p <- 0.5
gr <- sample_mixed_graph(W, wts, nd, ns, p = 0.1, option = 2)
out <- separate_dense_and_sparse(gr)
separate <- separate_dense_and_sparse(gr)
autoplot(separate)
Creates an exponential graphon
Description
Creates an nxn matrix where the (i,j)th entry is exp(-(i+j)/scalar)
Usage
create_exp_matrix(nrow, scalar)
Arguments
nrow |
The dimension of the matrix |
scalar |
The scalar in exp(-(i+j)/scalar) |
Value
An nxn matrix
Examples
W <- create_exp_matrix(100, 100)
Computes empirical graphon from graph
Description
Computes empirical graphon given a graph
Usage
empirical_graphon(gr, n = NULL)
Arguments
gr |
A graph |
n |
Dimension of the graphon matrix |
Value
The empirical graphon
Examples
library(igraph)
gr <- sample_gnp(1000, p=0.2)
emp <- empirical_graphon(gr, n = 100)
Extracts the sparse part from a (U,W) graphon mixture
Description
This function extracts the sparse component from a (U,W) mixture graph by fitting two lines to the unique sorted log degree values. The first line gives the number of hubs in the sparse part and the remaining line fits the degrees of the dense part.
Usage
extract_sparse(gr)
Arguments
gr |
The input graph |
Value
a list with the following components:
num_hubs |
The number of hubs in the sparse component. |
phat |
The probability vector of the sparse component. This is also known as the mass partition. |
segment_sizes |
The sizes of the two line segments. |
line_equations |
The two equations of the lines. |
cutoff |
The best cut off for the two lines. |
models |
The models of the fitted lines. |
mse |
The mean squared error |
data |
The degree data. |
Examples
library(igraph)
gr <- sample_pa(10000, power = 1.2, directed = FALSE)
sparse <- extract_sparse(gr)
sparse$phat
Generates a sparse graph of star graphs
Description
Generates a union of star graphs given the weights
Usage
generate_star_union(wts, n)
Arguments
wts |
The proportion of the hub degrees |
n |
The number of nodes in the new graph |
Value
A disjoint union of star graphs
Examples
library(igraph)
wts <- c(0.5, 0.3, 0.2)
gr <- generate_star_union(wts, n = 100)
gr
Joins two graphs
Description
Joins two graphs randomly connecting vertices
Usage
graph_join(gr1, gr2, p = 0.5, option = 2)
Arguments
gr1 |
The first graph to join |
gr2 |
The second graph to join |
p |
The proportion of edges in |
option |
Two options. 1 does the disjoint union, 2 does the random edges union. |
Value
The joined graph
Examples
W <- create_exp_matrix(100, 100)
# create the sparse part - a disjoint set of stars
wts <- c(0.5, 0.3, 0.2)
grdense <- sample_graphon(W, 100)
grsparse <- generate_star_union(wts, 200)
gr <- graph_join(grdense, grsparse, opt = 2)
Creates a line graphon from a sequence of probabilities
Description
Creates a line graphon, which is a disjoint clique graphon from a sequence of probability values
Usage
line_graphon(probs)
Arguments
probs |
The list of probabilities starting from the largest. |
Value
The line graphon
Examples
library(ggplot2)
wts <- c(0.5, 0.3, 0.2)
U <- line_graphon(wts)
plot_graphon(U)
Plots graphon
Description
Plots graphon
Usage
plot_graphon(W, cols = c("white", "black"))
Arguments
W |
A graphon given by an nxn matrix |
cols |
Colors, by default white and black |
Value
A ggplot object.
Examples
W <- create_exp_matrix(100, 100)
plot_graphon(W)
Predicts the degree of hubs of an new graph
Description
Predicts the degree of hubs of an unseen graph given a graph generated from the same process.
Usage
predict_hubs(gr, n, k = NULL)
Arguments
gr |
The input graph |
n |
The number of nodes in the new graph |
k |
The number of hubs. Default is |
Value
A vector of hub degrees
Examples
library(igraph)
gr <- sample_pa(10000, power = 1.2, directed = FALSE)
predict_hubs(gr, n = 11000)
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
- ggplot2
Creates a ring graphon
Description
Creates an graphon which can generate ring graphs.
Usage
ring_graphon(n, alpha = 0.1)
Arguments
n |
The dimension of the matrix |
alpha |
A scaling factor used in the graphon. Default set to 0.1 |
Value
An nxn matrix
Examples
# example code
W <- ring_graphon(100)
plot_graphon(W)
Samples a graph from a graphette
Description
Samples a graph from a graphette given by (W, a_n, f), where W is the graphon, a_n is generally a sequence converging to zero and f is a graph edit funcion.
Usage
sample_graphette(
W,
rho_n = NULL,
graph_edit_f = NULL,
n = 100,
t_or_p = 0.5,
ring_sizes = c(5, 6)
)
Arguments
W |
The graphon. This is a symmetric matrix with values in [0,1] |
rho_n |
A function. Default is 1. |
graph_edit_f |
The graph edit function. For star functions it can be
one of |
n |
The number of nodes in the graph to sample |
t_or_p |
The parameter for star function or the ring function. For the ring function it needs to be between 0 and 1. |
ring_sizes |
The size of rings to add if the graph edit function is the ring function. default values set to |
Value
gr A graph sampled from rho_n W.
Examples
library(igraph)
# Example 1
f1 <- function(n) 10/n
W <- matrix(0.2, nrow = 100, ncol = 100)
gr <- sample_graphette(W, rho_n = f1, graph_edit_f = 'add_rings', n = 100, t_or_p = 0.5)
gr
# Example 2
gr <- sample_graphette(W, rho_n = f1, graph_edit_f = 'star_f1', n = 100, t_or_p = 3)
gr
Generates a graph given a graphon
Description
Generates a graph given a dense graphon W.
Usage
sample_graphon(W, n)
Arguments
W |
A graphon given by a matrix |
n |
The number of nodes of the sampled graph |
Value
A graph sampled from the graphon W with n nodes
Examples
library(igraph)
W <- matrix(0.2, nrow = 100, ncol = 100)
gr <- sample_graphon(W, n= 100)
Generate a (U,W) mixture graph
Description
Generate a (U,W) mixture graph from a dense graphon W and a mass partition corresponding to a line graph graphon U.
Usage
sample_mixed_graph(W, wts, nd, ns, p = 0.5, option = 2)
Arguments
W |
The dense graphon. This is a symmetric matrix with values in [0,1] |
wts |
The degree proportions of the hub degrees. Need to add up to 1. This is the mass partition corresponding to the line graph graphon U. |
nd |
The number of nodes in the dense part of the graph |
ns |
The number of nodes in the sparse part of the graph |
p |
The nodes to be added as a proportion of the edges in the dense part |
option |
Graph joining option. If |
Value
A graph sampled from the (U,W) mixture.
Examples
library(igraph)
W <- matrix(0.1, nrow = 100, ncol = 100)
wts <- c(0.5, 0.3, 0.2)
ns <- 200
nd <- 100
p <- 0.5
gr <- sample_mixed_graph(W, wts, nd, ns, p, option = 2)
gr
Samples a graph from a sparsified graphon
Description
Samples a graph from a sparsified graphon given by a_n W, where W is the graphon and a_n is generally a sequence converging to zero.
Usage
sample_sparse_graphon(W, rho_n = NULL, n)
Arguments
W |
The graphon. This is a symmetric matrix with values in [0,1] |
rho_n |
A function. Default is 1. |
n |
The number of nodes in the graph to sample |
Value
gr A graph sampled from rho_n W.
Examples
library(igraph)
f1 <- function(n) 10/n
W <- matrix(0.2, nrow = 100, ncol = 100)
gr <- sample_sparse_graphon(W, f1, n = 100)
gr
Creates a Stochastic Block Model graphon
Description
Creates an graphon representing a Stochastic Block Model (SBM).
Usage
sbm_graphon(mat, n)
Arguments
mat |
The matrix representing the SBM |
n |
The dimension of the matrix |
Value
An nxn matrix
Examples
# example code
mat <- matrix(c(0.9, 0.01, 0.02,
0.01, 0.8, 0.03,
0.02, 0.03, 0.7), nrow = 3, byrow = TRUE)
W <- sbm_graphon(mat, 100)
plot_graphon(W)
Scales a graphon to an nxn matrix
Description
Scales a graphon to an nxn matrix suitable for large adjacency matrices
Usage
scale_graphon(W, n)
Arguments
W |
A graphon given as a symmetric square matrix |
n |
The dimension of the output matrix |
Value
Scaled nxn graphon
Examples
library(igraph)
gr <- sample_gnp(1000, p=0.2)
adj <- as_adjacency_matrix(gr)
W <- scale_graphon(adj, 100)
Separates the dense and sparse part from a (U,W) graphon mixture
Description
This function breaks a (U,W) mixture graph into a dense and sparse component.
Usage
separate_dense_and_sparse(grmix)
Arguments
grmix |
The input graph |
Value
a list with the following components:
gr_dense |
The dense component. |
gr_sparse |
The sparse component. |
data |
The original graph. |
Examples
library(igraph)
W <- matrix(0.1, nrow = 100, ncol = 100)
wts <- c(0.5, 0.3, 0.2)
ns <- 200
nd <- 100
p <- 0.5
gr <- sample_mixed_graph(W, wts, nd, ns, p = 0.1, option = 2)
out <- separate_dense_and_sparse(gr)
out
Adds stars to nodes
Description
Adds stars to nodes
Usage
star_f1(xvals, t)
Arguments
xvals |
Values between 0 and 1 from the graphon |
t |
A parameter indicating the strength of hubs |
Value
a vector of values
Examples
# example code
st <- star_f1(runif(10), 3)
st
Adds stars to nodes
Description
Adds stars to nodes
Usage
star_f2(xvals, t)
Arguments
xvals |
Values between 0 and 1 from the graphon |
t |
A parameter indicating the strength of hubs |
Value
a vector of values
Examples
# example code
st <- star_f2(runif(10), 3)
st
Adds stars to nodes
Description
Adds stars to nodes
Usage
star_f3(xvals, t)
Arguments
xvals |
Values between 0 and 1 from the graphon |
t |
A parameter indicating the strength of hubs |
Value
a vector of values
Examples
# example code
st <- star_f3(runif(10), 3)
st
Adds stars to nodes
Description
Adds stars to nodes
Usage
star_f4(xvals, t)
Arguments
xvals |
Values between 0 and 1 from the graphon |
t |
A parameter indicating the strength of hubs |
Value
a vector of values
Examples
# example code
st <- star_f4(runif(10), 3)
st
Adds stars to nodes
Description
Adds stars to nodes
Usage
star_f5(xvals, t)
Arguments
xvals |
Values between 0 and 1 from the graphon |
t |
A parameter indicating the strength of hubs |
Value
a vector of values
Examples
# example code
st <- star_f5(runif(10), 3)
st