From d2994fb6ee528ddd25f72814a59e702072a477ec Mon Sep 17 00:00:00 2001 From: Nicholas Landry Date: Thu, 10 Oct 2024 14:41:26 -0400 Subject: [PATCH] updates --- xgi/generators/uniform.py | 41 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/xgi/generators/uniform.py b/xgi/generators/uniform.py index 0bd65864..a5216fd1 100644 --- a/xgi/generators/uniform.py +++ b/xgi/generators/uniform.py @@ -347,13 +347,17 @@ def uniform_erdos_renyi_hypergraph(n, m, p, p_type="prob", multiedges=False, see Notes ----- - Because XGI only stores edges as sets, if self-loops are allowed, - for example, the edge (0, 0, 0) 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 this method offers an order of magnitude speedup, - so while it is not the default behavior, this option is exposed to - the users by setting `multiedges=True`. + 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 ---------- @@ -408,6 +412,9 @@ def uniform_erdos_renyi_hypergraph(n, m, p, p_type="prob", multiedges=False, see # will not longer be uniform, so we discard them. if len(e) == m: H.add_edge(e) + # We no longer subtract 1 because if we did, the minimum + # value of the right-hand side would be zero, meaning that + # we sample the same index multiple times. index += np.random.geometric(q) return H @@ -416,6 +423,8 @@ def _index_to_edge_prod(index, n, m): """Generate a hyperedge from an index given the number of nodes and size of hyperedges. + In this method, it treats each edge permutation as distinct, which can + lead to multiedges and loopy edges, especially for dense hypergraphs. Imagine that there is a hypergraph with 4 nodes and an edge size of 3. We write out each edge (allowing duplicate entries) incrementing the last entry first, followed by the second-to-last entry and so on, with each edge corresponding to an index @@ -424,15 +433,11 @@ def _index_to_edge_prod(index, n, m): This function will, for instance, return (0, 0, 3) for index 3, network size 4, and edge size 3. - Because XGI only stores edges as sets, 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, so while - it is not the default behavior. - - This method treats each edge permutation as distinct, which can - lead to multiedges, especially for dense hypergraphs. - + Because hypergraphs in XGI only store edges as sets, the edge (0, 0, 0), + for example, generated by this function 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 this method offers + an order of magnitude speedup. Parameters ---------- @@ -471,8 +476,8 @@ def _index_to_edge_comb(index, n, m): return (0, 2, 3) for index 2, network size 4, and edge size 3. - In this function, we prohibit multiedges, so each index corresponds to a - unique edge. + In this function, we prohibit multiedges, so each edge corresponds to a + unique index. Parameters ----------