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

Enforcing determinism when using PRNGs? #8

Open
sdmccabe opened this issue Jul 19, 2022 · 0 comments
Open

Enforcing determinism when using PRNGs? #8

sdmccabe opened this issue Jul 19, 2022 · 0 comments

Comments

@sdmccabe
Copy link
Collaborator

It's not a big deal for now but ultimately we'll want to be able to set seeds for the rewiring algorithms. I see a few possibilities for this:

  1. Use the standard library's random, and set the seed using random.seed($SEED). I don't like this because it mutates global state.
  2. Use numpy's Generator object. This is probably preferable but a bit heavy (and tricky for users).
  3. Add a parameter for passing a random seed at initialization, store a random.Random as an attribute, and call that to generate random numbers.
  4. Do the same, with a np.random.Generator.

I think #3 could look like the following:

class BaseRewirer:
	<...>
	def __init__(seed: Optional[int] = None):
		self.rand = random.Random(seed)
		
	<...>
	def rewire(self, G, **kwargs):
		# selecting a random edge
		rand_edge = rand.choice(list(G.edges))
	<...>

The challenge with using np.random.Generator is that numpy randomness wants to return arrays, which we don't always want (e.g., when sampling edges).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant