Type: | Package |
Title: | Generates Mixture Graphs from Dense and Sparse Graphons |
Version: | 0.0.1.0 |
Maintainer: | Sevvandi Kandanaarachchi <sevvandik@gmail.com> |
Description: | Generates (U,W) mixture graphs where U is a line graph graphon and W is a dense graphon. Graphons are graph limits and graphon U can be written as sequence of positive numbers adding to 1. Graphs are sampled from U and W and joined randomly to obtain the mixture graph. Given a mixture graph, U can be inferred. Kandanaarachchi and Ong (2025) <doi:10.48550/arXiv.2505.13864>. |
License: | GPL (≥ 3) |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
Imports: | ggplot2, igraph, imager, stats |
Suggests: | gridExtra, knitr, rmarkdown |
VignetteBuilder: | knitr |
URL: | https://sevvandi.github.io/graphonmix/ |
NeedsCompilation: | no |
Packaged: | 2025-10-05 22:38:34 UTC; kan092 |
Author: | Sevvandi Kandanaarachchi
|
Repository: | CRAN |
Date/Publication: | 2025-10-09 07:40:02 UTC |
graphonmix: Generates Mixture Graphs from Dense and Sparse Graphons
Description
Generates (U,W) mixture graphs where U is a line graph graphon and W is a dense graphon. Graphons are graph limits and graphon U can be written as sequence of positive numbers adding to 1. Graphs are sampled from U and W and joined randomly to obtain the mixture graph. Given a mixture graph, U can be inferred. Kandanaarachchi and Ong (2025) doi:10.48550/arXiv.2505.13864.
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)
Creates an nxn exponential matrix
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
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
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)