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(...)

Arguments

design

design matrix that requires a unique seed per condition, or a number indicating the number of seeds to generate. Default generates one number

iseed

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

arrayID

(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

old.seeds

(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

Author

Phil Chalmers rphilip.chalmers@gmail.com

Examples


# generate 1 seed (default)
genSeeds()
#> [1] 413067025

# generate 5 unique seeds
genSeeds(5)
#> [1]  595688410 1809449992 1887503261 1000739687 1129367556

# generate from nrow(design)
design <- createDesign(factorA=c(1,2,3),
                       factorB=letters[1:3])
seeds <- genSeeds(design)
seeds
#> [1]  717434384 1123050453  474408704 1310164663 1607262655  390300427  731677967
#> [8]  298354824   27984649

# construct new seeds that are independent from original (use this sparingly)
newseeds <- genSeeds(design, old.seeds=seeds)
newseeds
#> [1]  225437218  746949893 1602927401  937942413  992053320 1416086442  823141978
#> [8] 1246508874 1619914930

# can be done in batches too
newseeds2 <- genSeeds(design, old.seeds=cbind(seeds, newseeds))
cbind(seeds, newseeds, newseeds2) # all unique
#>            seeds   newseeds  newseeds2
#>  [1,]  717434384  225437218 1610796999
#>  [2,] 1123050453  746949893  187037883
#>  [3,]  474408704 1602927401 1156242821
#>  [4,] 1310164663  937942413 2079951069
#>  [5,] 1607262655  992053320   65720644
#>  [6,]  390300427 1416086442   63806296
#>  [7,]  731677967  823141978 2117530059
#>  [8,]  298354824 1246508874  530569453
#>  [9,]   27984649 1619914930  983369505

############
# generate seeds for runArraySimulation()
(iseed <- genSeeds())  # initial seed
#> [1] 1621803732
seed_list <- genSeeds(design, iseed=iseed)
seed_list
#> [[1]]
#> [1]       10407  -393088597 -1748028176  1267569713  1159145534 -1462476889
#> [7]  1519588284
#> 
#> [[2]]
#> [1]       10407  2073295769 -1213792688   115928303   -82479839  -707141313
#> [7] -1704073572
#> 
#> [[3]]
#> [1]       10407  -870242787   789196619  1776108125   252083774   429837893
#> [7] -1551619282
#> 
#> [[4]]
#> [1]       10407  -154385593 -1451335364  2072700444   602812746  -945279022
#> [7] -1896060987
#> 
#> [[5]]
#> [1]      10407 2142874795 1974175838  400706708 -621277328 1223183922 1877168725
#> 
#> [[6]]
#> [1]      10407 1167495963  151780166  140739656 -777520365 1910696700  673198308
#> 
#> [[7]]
#> [1]       10407   790963760  1674262040   422428202  -654732746 -1633316309
#> [7]  -337032649
#> 
#> [[8]]
#> [1]       10407  -580487630  1572901224   246126514  -513772774  1205009976
#> [7] -1489209156
#> 
#> [[9]]
#> [1]       10407   729665589  1498004745  -251215129 -1587945835 -2139861609
#> [7]   121097077
#> 
#> attr(,"iseed")
#> [1] 1621803732

# 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 -393088597 -1748028176 1267569713 1159145534 -1462476889 1519588284
#>  $ : int [1:7] 10407 2073295769 -1213792688 115928303 -82479839 -707141313 -1704073572
#>  $ : int [1:7] 10407 -870242787 789196619 1776108125 252083774 429837893 -1551619282
#>  $ : int [1:7] 10407 -154385593 -1451335364 2072700444 602812746 -945279022 -1896060987
#>  $ : int [1:7] 10407 2142874795 1974175838 400706708 -621277328 1223183922 1877168725
#>  $ : int [1:7] 10407 1167495963 151780166 140739656 -777520365 1910696700 673198308
#>  $ : int [1:7] 10407 790963760 1674262040 422428202 -654732746 -1633316309 -337032649
#>  $ : int [1:7] 10407 -580487630 1572901224 246126514 -513772774 1205009976 -1489209156
#>  $ : int [1:7] 10407 729665589 1498004745 -251215129 -1587945835 -2139861609 121097077
#>  $ : int [1:7] 10407 -500765584 -1884258102 -467641450 -1457474979 2081533045 142219828
#>  $ : int [1:7] 10407 475358860 2067292367 -2032602631 -1535946034 -1556895047 -1457501172
#>  $ : int [1:7] 10407 469601039 -358140378 441340672 1265872825 -354511135 -455939222
#>  $ : int [1:7] 10407 -1821768114 -752134477 -981915175 -1797154631 1138497185 -234232535
#>  $ : int [1:7] 10407 1434029461 806223608 632913975 1538473977 -1633173233 1041652166
#>  $ : int [1:7] 10407 1253882201 -2136258491 1447152181 271033773 1375414422 -1084608369
#>  $ : int [1:7] 10407 -830582776 -1607115150 1467556768 -226635721 -1776085954 1275937975
#>  $ : int [1:7] 10407 -1341095906 1459509467 -283439126 -2000069736 638679578 -1331946233
#>  $ : int [1:7] 10407 -872589327 -1816091312 1073275342 -1537001271 1479780440 443954894
#>  - attr(*, "iseed")= int 1621803732

# 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  1253882201 -2136258491  1447152181   271033773  1375414422
#> [7] -1084608369
#> 
#> attr(,"arrayID")
#> [1] 15
#> attr(,"iseed")
#> [1] 1621803732