Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added seed to shuffle-hypedges #645

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion xgi/generators/randomizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
]


def shuffle_hyperedges(S, order, p):
def shuffle_hyperedges(S, order, p, seed=None):
"""Shuffle existing hyperdeges of order `order` with probablity `p`.

Parameters
Expand All @@ -26,6 +26,8 @@ def shuffle_hyperedges(S, order, p):
Order of hyperedges to shuffle
p : float
Probability of shuffling each hyperedge
seed : integer or None (default)
Seed for the random number generator.

Returns
-------
Expand All @@ -52,6 +54,9 @@ def shuffle_hyperedges(S, order, p):

"""

if seed is not None:
random.seed(seed)

if (order + 1) not in xgi.unique_edge_sizes(S):
raise ValueError(f"There is no hyperedge of order {order} is this hypergraph.")
if (p < 0) or (p > 1):
Expand Down
Loading