Generate seeds to be passed to runSimulation's seed input. Values
are sampled from 1 to 2147483647, or are generated using L'Ecuyer-CMRG's (2002)
method (returning either a list if arrayID is omitted, or the specific
row value from this list if arrayID is included).
genSeeds(design = 1L, iseed = NULL, arrayID = NULL, old.seeds = NULL)
gen_seeds(...)design matrix that requires a unique seed per condition, or a number indicating the number of seeds to generate. Default generates one number
the initial set.seed number used to generate a sequence
of independent seeds according to the L'Ecuyer-CMRG (2002) method. This
is recommended whenever quality random number generation is required
across similar (if not identical) simulation jobs
(e.g., see runArraySimulation). If arrayID is not
specified then this will return a list of the associated seed for the
full design
(optional) single integer input corresponding to the specific
row in the design object when using the iseed input.
This is used in functions such as runArraySimulation
to pull out the specific seed rather than manage a complete list, and
is therefore more memory efficient
(optional) vector or matrix of last seeds used in
previous simulations to avoid repeating the same seed on a subsequent run.
Note that this approach should be used sparingly as seeds set more frequently
are more likely to correlate, and therefore provide less optimal random
number behaviour (e.g., if performing a simulation on two runs to achieve
5000 * 2 = 10,000 replications this is likely reasonable,
but for simulations with 100 * 2 = 200 replications this is more
likely to be sub-optimal).
Length must be equal to the number of rows in design
does nothing
# generate 1 seed (default)
genSeeds()
#> [1] 595688410
# generate 5 unique seeds
genSeeds(5)
#> [1] 1809449992 1887503261 1000739687 1129367556 717434384
# generate from nrow(design)
design <- createDesign(factorA=c(1,2,3),
factorB=letters[1:3])
seeds <- genSeeds(design)
seeds
#> [1] 1123050453 474408704 1310164663 1607262655 390300427 731677967 298354824
#> [8] 27984649 225437218
# construct new seeds that are independent from original (use this sparingly)
newseeds <- genSeeds(design, old.seeds=seeds)
newseeds
#> [1] 746949893 1602927401 937942413 992053320 1416086442 823141978 1246508874
#> [8] 1619914930 1610796999
# can be done in batches too
newseeds2 <- genSeeds(design, old.seeds=cbind(seeds, newseeds))
cbind(seeds, newseeds, newseeds2) # all unique
#> seeds newseeds newseeds2
#> [1,] 1123050453 746949893 187037883
#> [2,] 474408704 1602927401 1156242821
#> [3,] 1310164663 937942413 2079951069
#> [4,] 1607262655 992053320 65720644
#> [5,] 390300427 1416086442 63806296
#> [6,] 731677967 823141978 2117530059
#> [7,] 298354824 1246508874 530569453
#> [8,] 27984649 1619914930 983369505
#> [9,] 225437218 1610796999 1621803732
############
# generate seeds for runArraySimulation()
(iseed <- genSeeds()) # initial seed
#> [1] 1772491070
seed_list <- genSeeds(design, iseed=iseed)
seed_list
#> [[1]]
#> [1] 10407 -580029603 1390287482 -1112709709 397903704 -684795527
#> [7] -1962390810
#>
#> [[2]]
#> [1] 10407 423224079 1060168791 -1324501878 338685348 -333661873
#> [7] 1426535804
#>
#> [[3]]
#> [1] 10407 1556206344 250047046 -671091177 1369431366 -1111867701
#> [7] -764689384
#>
#> [[4]]
#> [1] 10407 -1804731154 -2068368773 107251773 408911970 -162727637
#> [7] -2093305321
#>
#> [[5]]
#> [1] 10407 728486110 167295809 -280103446 1575208030 317861460 1753697019
#>
#> [[6]]
#> [1] 10407 -771896447 1202492878 2028085115 2083879772 1898270809 973647758
#>
#> [[7]]
#> [1] 10407 -1599816698 2079468253 -264522773 836233761 950798835
#> [7] 362821733
#>
#> [[8]]
#> [1] 10407 -197528885 761966381 585609708 1086456883 886957423 949409231
#>
#> [[9]]
#> [1] 10407 -2046658214 1757613708 -1833796285 558899161 -471621828
#> [7] -1012199754
#>
#> attr(,"iseed")
#> [1] 1772491070
# expand number of unique seeds given iseed (e.g., in case more replications
# are required at a later date)
seed_list_tmp <- genSeeds(nrow(design)*2, iseed=iseed)
str(seed_list_tmp) # first 9 seeds identical to seed_list
#> List of 18
#> $ : int [1:7] 10407 -580029603 1390287482 -1112709709 397903704 -684795527 -1962390810
#> $ : int [1:7] 10407 423224079 1060168791 -1324501878 338685348 -333661873 1426535804
#> $ : int [1:7] 10407 1556206344 250047046 -671091177 1369431366 -1111867701 -764689384
#> $ : int [1:7] 10407 -1804731154 -2068368773 107251773 408911970 -162727637 -2093305321
#> $ : int [1:7] 10407 728486110 167295809 -280103446 1575208030 317861460 1753697019
#> $ : int [1:7] 10407 -771896447 1202492878 2028085115 2083879772 1898270809 973647758
#> $ : int [1:7] 10407 -1599816698 2079468253 -264522773 836233761 950798835 362821733
#> $ : int [1:7] 10407 -197528885 761966381 585609708 1086456883 886957423 949409231
#> $ : int [1:7] 10407 -2046658214 1757613708 -1833796285 558899161 -471621828 -1012199754
#> $ : int [1:7] 10407 -892100723 1207090254 768831129 1189817772 1518025971 1373914233
#> $ : int [1:7] 10407 1479195856 244939414 394870487 -371255709 1814167031 -1382791282
#> $ : int [1:7] 10407 -387912108 -1893140266 193720225 2127211886 -1688118839 1117183337
#> $ : int [1:7] 10407 -1553696551 90230369 309561123 1798044693 786698682 939024774
#> $ : int [1:7] 10407 559525644 -244814480 -229511897 1204499670 823224812 -940625420
#> $ : int [1:7] 10407 1800935859 486943487 663011968 -1326933647 2021538014 -977998928
#> $ : int [1:7] 10407 1568681969 -520501636 -595531759 1489746325 1061905805 -464685662
#> $ : int [1:7] 10407 283799279 -135043436 -469163823 347157787 1236230248 960318884
#> $ : int [1:7] 10407 1551887724 -1031693495 1568587414 -89566573 1638824253 -925190692
#> - attr(*, "iseed")= int 1772491070
# more usefully for HPC, extract only the seed associated with an arrayID
arraySeed.15 <- genSeeds(nrow(design)*2, iseed=iseed, arrayID=15)
arraySeed.15
#> [[1]]
#> [1] 10407 1800935859 486943487 663011968 -1326933647 2021538014
#> [7] -977998928
#>
#> attr(,"arrayID")
#> [1] 15
#> attr(,"iseed")
#> [1] 1772491070