-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_design.R
64 lines (62 loc) · 2.28 KB
/
random_design.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
random_design <- R6::R6Class("random_design",
public = list(
X = NULL,
D = NULL,
L = NULL,
b = NULL,
seed = NULL,
use_lhs = NULL,
initialize = function(D, L, use_lhs=TRUE, seed=numeric(0)) {
self$D <- D
self$L <- L
self$X <- matrix(NA, nrow=0, ncol=self$D)
self$use_lhs <- use_lhs
# self$b <- NA
self$seed <- seed
},
get.batch = function(L=self$L) {
if (length(self$seed) > 0) {
set.seed(self$seed)
self$seed <- self$seed + 1
}
if (self$use_lhs) {
newX <- lhs::maximinLHS(n=L, k=self$D)
} else {
newX <- matrix(runif(self$D*L), ncol=self$D, nrow=L)
}
self$X <- rbind(self$X, newX)
newX
}
)
)
#' Sobol sequence
#'
#' I don't like the randtoolbox because you can't have two
#' separate concurrent Sobol sequences.
sobol_design <- R6::R6Class("sobol_design",
public = list(
X = NULL,
D = NULL,
L = NULL,
b = NULL,
seed = NULL,
use_lhs = NULL,
initialize = function(D, L, seed=numeric(0)) {
self$D <- D
self$L <- L
self$seed <- seed
# D=1 sobol gives vector, as.matrix makes it matrix with 1 col
self$X <- as.matrix(randtoolbox::sobol(n=L,dim=D, init=T, seed=seed, scrambling=1))
},
get.batch = function(L=self$L) {
# if (length(self$seed) > 0) {
# set.seed(self$seed)
# self$seed <- self$seed + 1
# }
# D=1 sobol gives vector, as.matrix makes it matrix with 1 col
newX <- as.matrix(randtoolbox::sobol(n=L, dim=self$D, init=F, scrambling=1))
self$X <- rbind(self$X, newX)
newX
}
)
)