Skip to content

Commit

Permalink
Merge branch 'fix-random-hypergraph' of https://github.com/xgi-org/xgi
Browse files Browse the repository at this point in the history
…into fix-random-hypergraph
  • Loading branch information
nwlandry committed Oct 10, 2024
2 parents edb5ebd + 40e7049 commit 5e8bd4e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions xgi/generators/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def fast_random_hypergraph(n, ps, order=None, seed=None):
Parameters
----------
N : int
n : int
Number of nodes
ps : list of float, or float
List of probabilities (between 0 and 1) to create a
Expand Down Expand Up @@ -153,19 +153,24 @@ def random_hypergraph(n, ps, seed=None):
Example
-------
>>> import xgi
>>> H = xgi.random_hypergraph(50, [0.1, 0.01])
>>> H = xgi.fast_random_hypergraph(50, [0.1, 0.01])
"""
warn("This method is much slower than fast_random_hypergraph")
if seed is not None:
random.seed(seed)
ps = np.array(ps)

if (np.any(np.array(ps) < 0)) or (np.any(np.array(ps) > 1)):
raise ValueError("All elements of ps must be between 0 and 1 included.")
if order is not None:
if len(ps) != 1:
raise ValueError("ps must contain a single element if order is an int")

H = empty_hypergraph()
if (ps < 0).any() or (ps > 1).any():
raise ValueError("All elements of ps must be between 0 and 1 included.")

nodes = range(n)

H = empty_hypergraph()
H.add_nodes_from(nodes)

for i, p in enumerate(ps):
Expand Down

0 comments on commit 5e8bd4e

Please sign in to comment.