Samples a hypergraph from one of four random models, chosen with type.
Usage
random_hypergraph(
type = c("uniform", "regular", "gnp", "sbm"),
...,
seed = NULL
)Arguments
- type
The model:
"uniform"(default),"regular","gnp"or"sbm".- ...
The arguments of the model, by name:
nNumber of nodes (all types; for
"sbm",NULLusessum(block_sizes)).mNumber of hyperedges (
"uniform","regular","gnp"; for"gnp",NULLdraws it from a Poisson distribution).kHyperedge size (
"uniform") or node degree ("regular").probSampling weights, length
nfor"uniform"and lengthmfor"regular";NULLis equal weights.pIncidence probability in
[0, 1]("gnp").lambdaPoisson mean of
m("gnp").PSymmetric block-to-block pair probability matrix (
"sbm").block_sizesPositive integer block sizes (
"sbm").dHyperedge size, recycled across sampled pairs; with
variable_size = TRUE, the Poisson mean of the size minus two ("sbm").impurityNumber of added members replaced by nodes outside the blocks of the pair (
"sbm", default 0).variable_sizeDraw sizes as
2 + Poisson(d)("sbm", defaultFALSE).absolute_purityReplacements come only from outside the blocks of the pair (
"sbm", defaultTRUE).
- seed
Optional seed; the random number state of the caller is restored on exit.
Value
A net_hg with binary incidence and the model parameters in
$params; for "sbm", $blocks records the planted block of each
node.
Details
"gnp" is the Erdos–Renyi-style model: n nodes and m hyperedges, with
every incidence drawn independently as Bernoulli(p). If m is omitted
it is Poisson with mean lambda, or n * p when lambda is also omitted.
Empty and singleton hyperedges are retained, since they are outcomes of the
model.
"uniform" makes every hyperedge contain exactly k distinct nodes, and
"regular" makes every node belong to exactly k distinct hyperedges.
Sampling weights prob can be unequal.
"sbm" samples a graph stochastic block model and extends every sampled
pair of nodes to a hyperedge with further members from the blocks of the
pair; impurity of the added members can then be replaced by nodes outside
those blocks.
Each type takes its own arguments, given by name; an argument that the chosen type does not take is an error.
Conditions
hypergraphs_bad_input for an argument the chosen type does not take, an
argument given without a name, or a count (n, m, k, impurity,
seed) that is not one whole number in range – fractions, NA, Inf
and values beyond the integer range are refused, never truncated.
Examples
uniform <- random_hypergraph("uniform", n = 20, m = 8, k = 3, seed = 1)
hg_measures(uniform, what = "distribution", measure = "size")
#> value n proportion ccdf
#> 1 3 8 1 1
regular <- random_hypergraph("regular", n = 20, m = 8, k = 2, seed = 1)
hg_measures(regular, what = "distribution", measure = "hyperdegree")
#> value n proportion ccdf
#> 1 2 20 1 1
bernoulli <- random_hypergraph("gnp", n = 20, m = 8, p = 0.2, seed = 1)
bernoulli
#> Hypergraph: 20 nodes, 8 hyperedges (sizes 1: 1, 2: 1, 3: 4, 4: 1, 5: 1)
#> Source: random gnp model
#> hyperedge size members
#> h1 2 V6, V16
#> h2 1 V3
#> h3 3 V5, V13, V18
#> h4 3 V1, V7, V10
#> h5 5 V3, V4, V8, V10, V14
#> h6 4 V1, V9, V12, V19
#> h7 3 V1, V14, V17
#> h8 3 V9, V10, V13
blocks <- matrix(c(0.5, 0.05, 0.05, 0.5), 2, 2)
planted <- random_hypergraph("sbm", P = blocks, block_sizes = c(10, 10),
d = 3, seed = 1)
hg_get(planted, what = "nodes")
#> node degree block
#> 1 V1 9 1
#> 2 V2 9 1
#> 3 V3 12 1
#> 4 V4 5 1
#> 5 V5 5 1
#> 6 V6 5 1
#> 7 V7 8 1
#> 8 V8 6 1
#> 9 V9 8 1
#> 10 V10 5 1
#> 11 V11 5 2
#> 12 V12 5 2
#> 13 V13 6 2
#> 14 V14 10 2
#> 15 V15 11 2
#> 16 V16 11 2
#> 17 V17 9 2
#> 18 V18 7 2
#> 19 V19 10 2
#> 20 V20 10 2