xgi.generators.uniform#
Generate random uniform hypergraphs.
Functions
- uniform_hypergraph_configuration_model(k, m, seed=None)[source]#
A function to generate an m-uniform configuration model
- Parameters:
k (dictionary) – This is a dictionary where the keys are node ids and the values are node degrees.
m (int) – specifies the hyperedge size
seed (integer or None (default)) – The seed for the random number generator
- Returns:
The generated hypergraph
- Return type:
Hypergraph object
- Warns:
warnings.warn – If the sums of the degrees are not divisible by m, the algorithm still runs, but raises a warning and adds an additional connection to random nodes to satisfy this condition.
Notes
This algorithm normally creates multi-edges and loopy hyperedges. We remove the loopy hyperedges.
References
“The effect of heterogeneity on hypergraph contagion models” by Nicholas W. Landry and Juan G. Restrepo https://doi.org/10.1063/5.0020034
Example
>>> import xgi >>> import random >>> n = 1000 >>> m = 3 >>> k = {1: 1, 2: 2, 3: 3, 4: 3} >>> H = xgi.uniform_hypergraph_configuration_model(k, m)
- uniform_erdos_renyi_hypergraph(n, m, p, p_type='prob', multiedges=False, seed=None)[source]#
Generate an m-uniform Erdős–Rényi hypergraph
This creates a hypergraph with n nodes where hyperedges of size m are created at random with probability (or to obtain a mean degree of) p.
This uses a fast method for generating hyperedges so that instead of the algorithm being of complexity \(\mathcal{O}(N^m)\), it can be as fast as \(\mathcal{O}(m(N + |E|))\). See the references for more details.
- Parameters:
n (int > 0) – Number of nodes
m (int > 0) – Hyperedge size
p (float or int >= 0) – Probability of an m-hyperedge if p_type=”prob” and mean expected degree if p_type=”degree”
p_type (str, optional) – Determines the way p is interpreted (see p for detail). Valid options are “prob” or “degree”, by default “prob”
multiedges (bool, optional) – Whether or not to allow multiedges. If True, there can be significant speedups but at the cost of creating (potentially unwanted) artifacts. When multiedges=True, it treats each edge permutation as distinct, which can lead to multiedges, especially for dense hypergraphs. For sparse hypergraphs, however, this is unlikely to be the case. By default, False.
seed (integer or None (default)) – The seed for the random number generator
- Returns:
The Erdos Renyi hypergraph
- Return type:
See also
Notes
When multiedges=True, there is the possibility of generating (potentially unwanted) artifacts, like multiedges and loopy hyperedges which are not present in the original Erdos-Renyi model. Because hypergraphs in XGI only store edges as sets, when an edge such as (0, 0, 0) is generated will be mapped to {0}. However, because this is explicitly a uniform method, we discard these edges. For sparse networks, this is a rare occurrence and allowing these artifacts offers an order of magnitude speedup. Although allowing loopy hyperedges and multiedges is not the default behavior, this (as well as the associated performance boost) is enabled by setting multiedges=True.
References
Nicholas W. Landry and Juan G. Restrepo, “Opinion disparity in hypergraphs with community structure”, Phys. Rev. E 108, 034311 (2024). https://doi.org/10.1103/PhysRevE.108.034311
- uniform_HSBM(n, m, p, sizes, seed=None)[source]#
Create a uniform hypergraph stochastic block model (HSBM).
This uses a fast method for generating hyperedges so that instead of the algorithm being of complexity \(\mathcal{O}(N^m)\), it can be as fast as \(\mathcal{O}(m(N + |E|))\). See the references for more details.
- Parameters:
n (int) – The number of nodes
m (int) – The hyperedge size
p (m-dimensional numpy array) – tensor of probabilities between communities
sizes (list or 1D numpy array) – The sizes of the community blocks in order
seed (integer or None (default)) – The seed for the random number generator
- Returns:
The constructed SBM hypergraph
- Return type:
- Raises:
XGIError –
If the length of sizes and p do not match. - If p is not a tensor with every dimension equal - If p is not m-dimensional - If the entries of p are not in the range [0, 1] - If the sum of the vector of sizes does not equal the number of nodes.
Exception – If there is an integer overflow error
See also
Notes
Because XGI only stores edges as sets, when self-loops occur, they become smaller edges (for example, the edge (0, 0, 0) will be mapped to {0}). However, because this is explicitly a uniform method, we discard these edges so that this is the case. For sparse networks, this is a rare occurrence and this method offers an order of magnitude speedup.
References
Nicholas W. Landry and Juan G. Restrepo, “Opinion disparity in hypergraphs with community structure”, Phys. Rev. E 108, 034311 (2024). https://doi.org/10.1103/PhysRevE.108.034311
- uniform_HPPM(n, m, k, epsilon, rho=0.5, seed=None)[source]#
Construct the m-uniform hypergraph planted partition model (m-HPPM)
This uses a fast method for generating hyperedges so that instead of the algorithm being of complexity \(\mathcal{O}(N^m)\), it can be as fast as \(\mathcal{O}(m(N + |E|))\). See the references for more details.
- Parameters:
n (int > 0) – Number of nodes
m (int > 0) – Hyperedge size
k (float > 0) – Mean degree
epsilon (float > 0) – Imbalance parameter
rho (float between 0 and 1, optional) – The fraction of nodes in community 1, default 0.5
seed (integer or None (default)) – The seed for the random number generator
- Returns:
The constructed m-HPPM hypergraph.
- Return type:
- Raises:
XGIError –
If rho is not between 0 and 1 - If the mean degree is negative. - If epsilon is not between 0 and 1
See also
Notes
Because XGI only stores edges as sets, when self-loops occur, they become smaller edges (for example, the edge (0, 0, 0) will be mapped to {0}). However, because this is explicitly a uniform method, we discard these edges so that this is the case. For sparse networks, this is a rare occurrence and this method offers an order of magnitude speedup.
References
Nicholas W. Landry and Juan G. Restrepo, “Opinion disparity in hypergraphs with community structure”, Phys. Rev. E 108, 034311 (2024). https://doi.org/10.1103/PhysRevE.108.034311