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

Changing seed number - be careful #1005

Closed
AdimDrewnik opened this issue Jun 21, 2024 · 10 comments
Closed

Changing seed number - be careful #1005

AdimDrewnik opened this issue Jun 21, 2024 · 10 comments
Assignees

Comments

@AdimDrewnik
Copy link

AdimDrewnik commented Jun 21, 2024

When running Robyn with different seeds be careful when changing the seed value. For example if you run seed = 123 with 10 trials and later run seed 124 with 10 trials then 9 out of 10 trials will have the same seed in the both runs. Seed number must be changed by more than the number of trials if someone wants completely new RNG in the whole run.

@laresbernardo
Copy link
Collaborator

You're right. Not that it is an issue but you've got a point. Adding a PR to improve this logic, using this approach:

seed <- 124
set.seed(seed)
for (i in 1:5) {
  print(seed + runif(1))
}

@AdimDrewnik
Copy link
Author

I think this implementation will cause even worse problems. As seed needs to be an integer using runif will cause all seeds to be the same exact number in many cases.

@laresbernardo
Copy link
Collaborator

Hi @AdimDrewnik Seeds can be any number, no need for integer values.

@AdimDrewnik
Copy link
Author

I have just checked. Using seed e.g. 1.1 and 1.11 gives exactly same random numbers.

@laresbernardo
Copy link
Collaborator

I think that's not right. Please, check:

> seed <- 1
> set.seed(seed)
> for (i in 1:5) {
+   print(seed + runif(1))
+ }
[1] 1.265509
[1] 1.372124
[1] 1.572853
[1] 1.908208
[1] 1.201682
> seed <- 1.1
> set.seed(seed)
> for (i in 1:5) {
+   print(seed + runif(1))
+ }
[1] 1.365509
[1] 1.472124
[1] 1.672853
[1] 2.008208
[1] 1.301682
> seed <- 1.11
> set.seed(seed)
> for (i in 1:5) {
+   print(seed + runif(1))
+ }
[1] 1.375509
[1] 1.482124
[1] 1.682853
[1] 2.018208
[1] 1.311682

@AdimDrewnik
Copy link
Author

I am talking about this case

set.seed(1.1)
rnorm(5)
[1] -0.6264538 0.1836433 -0.8356286 1.5952808 0.3295078

set.seed(1.11)
rnorm(5)
[1] -0.6264538 0.1836433 -0.8356286 1.5952808 0.3295078

@laresbernardo
Copy link
Collaborator

Alright, but that's not the implementation I've proposed in the code.

@AdimDrewnik
Copy link
Author

AdimDrewnik commented Oct 18, 2024

But you are generating seeds that will be used for random number generation. If you generate non integer seeds that are same integer when rounded your RNG for two trials will be the same.

@laresbernardo
Copy link
Collaborator

I've increased the order of magnitude to have large numeric values. Does this look good to you? Feel free to test and confirm before we merge to main branch.

@AdimDrewnik
Copy link
Author

Please revert this change and only add a warning to the documentation. It will only cause more problems and more issues. Before I only needed to increase the seed number above the number of trials. Now I am getting a chance to run same RNG multiple times.

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

2 participants