9
9
infillOptFocus = function (infill.crit , models , control , par.set , opt.path , design , iter , ... ) {
10
10
global.y = Inf
11
11
12
- discreteVectorPars = filterParams(par.set , type = c(" discretevector" , " logicalvector" ))
12
+ discrete.vector.pars = filterParams(par.set , type = c(" discretevector" , " logicalvector" ))
13
13
14
- allRequirements = extractSubList(par.set $ pars , " requires" , simplify = FALSE )
15
- allRequirementVars = unique(unlist(lapply(allRequirements , all.vars )))
16
- forbiddenRequirementVars = getParamIds(discreteVectorPars )
17
- if (any(allRequirementVars %in% forbiddenRequirementVars )) {
14
+ all.requirements = extractSubList(par.set $ pars , " requires" , simplify = FALSE )
15
+ all.requirement.vars = unique(unlist(lapply(all.requirements , all.vars )))
16
+ if (any(all.requirement.vars %in% getParamIds(discrete.vector.pars ))) {
18
17
stop(" Cannot do focus search when some variables have requirements that depend on discrete or logical vector parameters." )
19
18
}
20
19
@@ -27,20 +26,20 @@ infillOptFocus = function(infill.crit, models, control, par.set, opt.path, desig
27
26
# Handle discrete vectors (and logical vectors):
28
27
# The problem is that for discrete vectors, we can't adjust the range dimension-wise.
29
28
# Instead we store the range of each discrete vectorparameter dimension in the list of named characters
30
- # `discreteVectorMapping `. In each iteration a random value (that does not contain
29
+ # `discrete.vector.mapping `. In each iteration a random value (that does not contain
31
30
# the optimum) is dropped from each vector on this list. The $values of the parameters in the parameterset also
32
31
# need to be modified to reflect the reduced range: from them, always the last value is dropped.
33
- # Then `discreteVectorMapping ` is a mapping that maps, for each discrete vector param dimension
32
+ # Then `discrete.vector.mapping ` is a mapping that maps, for each discrete vector param dimension
34
33
# with originally n values, from the sampled value (levels 1 to n - #(dropped levels)) to the acutal levels with
35
34
# random dropouts.
36
35
#
37
36
# Since the requirements of the param set are queried while generating the design, this breaks if
38
37
# there are requirements depending on discrete vector parameters.
39
- discreteVectorMapping = lapply(discreteVectorPars $ pars ,
38
+ discrete.vector.mapping = lapply(discrete.vector.pars $ pars ,
40
39
function (param ) rep(list (setNames(names(param $ values ), names(param $ values ))), param $ len ))
41
- discreteVectorMapping = unlist(discreteVectorMapping , recursive = FALSE )
42
- if (! isEmpty(discreteVectorPars )) {
43
- names(discreteVectorMapping ) = getParamIds(discreteVectorPars , with.nr = TRUE , repeated = TRUE )
40
+ discrete.vector.mapping = unlist(discrete.vector.mapping , recursive = FALSE )
41
+ if (! isEmpty(discrete.vector.pars )) {
42
+ names(discrete.vector.mapping ) = getParamIds(discrete.vector.pars , with.nr = TRUE , repeated = TRUE )
44
43
}
45
44
46
45
@@ -53,8 +52,8 @@ infillOptFocus = function(infill.crit, models, control, par.set, opt.path, desig
53
52
newdesign = convertDataFrameCols(newdesign , ints.as.num = TRUE , logicals.as.factor = TRUE )
54
53
55
54
# handle discrete vectors
56
- for (dfindex in names(discreteVectorMapping )) {
57
- mapping = discreteVectorMapping [[dfindex ]]
55
+ for (dfindex in names(discrete.vector.mapping )) {
56
+ mapping = discrete.vector.mapping [[dfindex ]]
58
57
levels(newdesign [[dfindex ]]) = mapping [levels(newdesign [[dfindex ]])]
59
58
}
60
59
@@ -102,20 +101,20 @@ infillOptFocus = function(infill.crit, models, control, par.set, opt.path, desig
102
101
par $ values [[to.del ]] = NULL
103
102
} else {
104
103
# we remove the last element of par$values and a random element for
105
- # each dimension in discreteVectorMapping .
104
+ # each dimension in discrete.vector.mapping .
106
105
par $ values = par $ values [- length(par $ values )]
107
106
if (par $ type != " logicalvector" ) {
108
107
# for discretevectorparam val would be a list; convert to character vector
109
108
val = names(val )
110
109
}
111
110
for (dimnum in seq_len(par $ len )) {
112
111
dfindex = paste0(par $ id , dimnum )
113
- newmap = val.names = discreteVectorMapping [[dfindex ]]
112
+ newmap = val.names = discrete.vector.mapping [[dfindex ]]
114
113
val.names = val.names [val.names != val [dimnum ]]
115
114
to.del = sample(val.names , 1 )
116
115
newmap = newmap [newmap != to.del ]
117
116
names(newmap ) = names(par $ values )
118
- discreteVectorMapping [[dfindex ]] <<- newmap
117
+ discrete.vector.mapping [[dfindex ]] <<- newmap
119
118
}
120
119
}
121
120
}
0 commit comments