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

Impute KNN sets seed #380

Closed
const-ae opened this issue Nov 15, 2018 · 1 comment
Closed

Impute KNN sets seed #380

const-ae opened this issue Nov 15, 2018 · 1 comment

Comments

@const-ae
Copy link
Contributor

Hi Laurent,

first thanks for the great package, it makes dealing with MS data much simpler.

I was just exploring the different methods for imputing missing values, when I discovered that to my surprise impute(msnset, "knn") fixes the seed value.

suppressPackageStartupMessages(library(MSnbase))
data(msnset)
# Other methods show the expected behavior
for(i in 1:10){
  tmp <- MSnbase::impute(msnset, "zero")
  print(rnorm(1))
}
#> [1] 2.077938
#> [1] -0.3538495
#> [1] 1.269365
#> [1] 0.1198152
#> [1] -0.07994367
#> [1] -1.107776
#> [1] 0.5004011
#> [1] -0.7553048
#> [1] -1.225024
#> [1] 0.2958373

# Fixes the seed, so no more randomness afterwards
for(i in 1:10){
  tmp <- MSnbase::impute(msnset, "knn")
  print(rnorm(1))
}
#> [1] -0.668527
#> [1] -0.668527
#> [1] -0.668527
#> [1] -0.668527
#> [1] -0.668527
#> [1] -0.668527
#> [1] -0.668527
#> [1] -0.668527
#> [1] -0.668527
#> [1] -0.668527

Created on 2018-11-15 by the reprex package (v0.2.1)

I saw that internally it is actually not your package that calls set.seed(), but the impute::impute.knn() method, but the method returns the state of the random number generator. So I was wondering if you could reset the rng state after the method call? If you are currently busy I could also try to make a small PR.

Best, Constantin

@lgatto
Copy link
Owner

lgatto commented Nov 15, 2018

Thank you for this, could catch. I wouldn't mind a PR.

const-ae added a commit to const-ae/MSnbase that referenced this issue Nov 15, 2018
- Reset .Random.seed after impute::impute.knn is called
sgibb added a commit that referenced this issue Nov 16, 2018
@lgatto lgatto closed this as completed Nov 20, 2018
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