GithubHelp home page GithubHelp logo

[JOSS review] Seeding about slurmr HOT 2 CLOSED

uscbiostats avatar uscbiostats commented on September 22, 2024
[JOSS review] Seeding

from slurmr.

Comments (2)

gvegayon avatar gvegayon commented on September 22, 2024

I really liked this post https://rpubs.com/Jouni_Helske/225931 (mentioned in the issue you pointed out). Following one of the (rather simple) tests, which as you suggested the simple 1:njobs does not pass, I wrote this simple (sort of arbitrary) function:

# A naive seeding function
new_seeds <- function(nseeds) {
  
  sum_of_seed <- sum(.Random.seed)
  sum_of_seed <- sum_of_seed - (sum_of_seed %/% 100L)*100L
  seeds <- (1L:nseeds) * 10L
  (seeds + sum_of_seed ^ (1L:nseeds %% 2L))[order(stats::runif(nseeds))]
  
  
}

# "Test" from https://rpubs.com/Jouni_Helske/225931
last_rand_seq <- list()
random <- function(kind) {
  set.seed(123)
  RNGkind(kind = kind)
  x <- numeric(1e5)
  seeds <- new_seeds(1e5)
  for(i in seq_along(x)){
    set.seed(seeds[i])
    x[i] <- runif(1)
  }
  
  last_rand_seq <<- c(last_rand_seq, list(x))
  
  acf(x, main = kind)
}
kinds <- c("Mersenne-Twister", "Marsaglia-Multicarry", "L'Ecuyer-CMRG")

invisible(sapply(kinds, random)) # Looks nice, no autocorrelation

This function is reproducible, i.e., seeds can be reproduced. Will including this function to generate the random seeds instead of using 1:njobs be enough for JOSS? From what I read in the discussion this is still a problem without a clear solution.

from slurmr.

mllg avatar mllg commented on September 22, 2024

I'm not sure I understand how the function new_seeds() helps to solve the problem

Your seeds are determined by the current RNG state on which you apply some transformations. Wouldn't you get the same quality of randomness with as.integer(runif(nseeds, 1, .Machine$integer.max))?

Either way, I think that the proposed solution (or just calling runif()) would be sufficient for me -- the arguably better solution is the one proposed by @HenrikBengtsson in the linked issue.

Note that there are two special cases which you might also need to address to get the seeding right:

  1. .Random.seed is NULL until the RNG is initiated (usually by drawing the first random number).
  2. sum(.Random.seed) might overflow.

from slurmr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.