99infillOptFocus = function (infill.crit , models , control , par.set , opt.path , design , iter , ... ) {
1010 global.y = Inf
1111
12+ discreteVectorPars = filterParams(par.set , type = c(" discretevector" , " logicalvector" ))
13+
1214 allRequirements = extractSubList(par.set $ pars , " requires" , simplify = FALSE )
13- allUsedVars = unique(do.call( base :: c , sapply (allRequirements , all.vars )))
14- forbiddenVars = getParamIds(filterParams( par.set , type = c( " discretevector " , " logicalvector " )) )
15- if (any(allUsedVars %in% forbiddenVars )) {
15+ allRequirementVars = unique(unlist(lapply (allRequirements , all.vars )))
16+ forbiddenRequirementVars = getParamIds(discreteVectorPars )
17+ if (any(allRequirementVars %in% forbiddenRequirementVars )) {
1618 stop(" Cannot do focus search when some variables have requirements that depend on discrete or logical vector parameters." )
1719 }
1820
@@ -22,19 +24,23 @@ infillOptFocus = function(infill.crit, models, control, par.set, opt.path, desig
2224 # copy parset so we can shrink it
2325 ps.local = par.set
2426
25- # handle discrete vectors:
26- # The problem is that for discrete vectors, we can't adjust the values dimension-wise.
27- # Therefore, for discrete vectors, we always drop the last level and instead have a
28- # mapping that maps, for each discrete vector param and for each dimension, from
29- # the sampled value (levels 1 to n - #(dropped levels)) to levels with random dropouts.
30- discreteVectorMapping = lapply(filterParams(par.set , type = c(" discretevector" , " logicalvector" ))$ pars ,
27+ # Handle discrete vectors (and logical vectors):
28+ # The problem is that for discrete vectors, we can't adjust the range dimension-wise.
29+ # 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
31+ # the optimum) is dropped from each vector on this list. The $values of the parameters in the parameterset also
32+ # 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
34+ # with originally n values, from the sampled value (levels 1 to n - #(dropped levels)) to the acutal levels with
35+ # random dropouts.
36+ #
37+ # Since the requirements of the param set are queried while generating the design, this breaks if
38+ # there are requirements depending on discrete vector parameters.
39+ discreteVectorMapping = lapply(discreteVectorPars $ pars ,
3140 function (param ) rep(list (setNames(names(param $ values ), names(param $ values ))), param $ len ))
32- discreteVectorMapping = do.call(base :: c , discreteVectorMapping )
33- # the resulting object is NULL if there are no discrete / logical vector params
34-
35- if (! is.null(discreteVectorMapping )) {
36- mappedPars = filterParams(par.set , type = c(" discretevector" , " logicalvector" ))
37- names(discreteVectorMapping ) = getParamIds(mappedPars , with.nr = TRUE , repeated = TRUE )
41+ discreteVectorMapping = unlist(discreteVectorMapping , recursive = FALSE )
42+ if (! isEmpty(discreteVectorPars )) {
43+ names(discreteVectorMapping ) = getParamIds(discreteVectorPars , with.nr = TRUE , repeated = TRUE )
3844 }
3945
4046
0 commit comments