Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nwlandry committed Oct 10, 2024
1 parent e8e89b5 commit d2994fb
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions xgi/generators/uniform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
----------
Expand Down Expand Up @@ -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
----------
Expand Down

0 comments on commit d2994fb

Please sign in to comment.