@@ -38,6 +38,8 @@ exampleRun = function(fun, design = NULL, learner = NULL, control,
3838 par.types = getParamTypes(par.set )
3939 n.params = sum(getParamLengths(par.set ))
4040 noisy = isNoisy(fun )
41+ control $ noisy = noisy
42+ control $ minimize = shouldBeMinimized(fun )
4143 learner = checkLearner(learner , par.set , control )
4244 assertClass(control , " MBOControl" )
4345 points.per.dim = asCount(points.per.dim , positive = TRUE )
@@ -51,8 +53,6 @@ exampleRun = function(fun, design = NULL, learner = NULL, control,
5153 global.opt = smoof :: getGlobalOptimum(fun )$ value
5254 else
5355 global.opt = NA_real_
54- control $ noisy = noisy
55- control $ minimize = shouldBeMinimized(fun )
5656
5757 if (control $ n.objectives != 1L )
5858 stopf(" exampleRun can only be applied for single objective functions, but you have %i objectives! Use 'exampleRunMultiCrit'!" ,
@@ -80,9 +80,9 @@ exampleRun = function(fun, design = NULL, learner = NULL, control,
8080 if (is.null(fun.mean )) {
8181 evals = evaluate(fun , par.set , n.params , par.types , noisy , noisy.evals , points.per.dim , names.x , name.y , seq_along(control $ multifid.lvls ))
8282 } else {
83- evals = evaluate(fun.mean , par.set , n.params , par.types , noisy = FALSE , noisy.evals = 1 , points.per.dim , names.x , name.y , seq_along(control $ multifid.lvls ))
83+ evals = evaluate(fun.mean , par.set , n.params , par.types , noisy = FALSE , noisy.evals = 1 , points.per.dim , names.x , name.y , multifid.lvls = seq_along(control $ multifid.lvls ))
8484 }
85-
85+
8686 if (is.na(global.opt ))
8787 global.opt.estim = ifelse(shouldBeMinimized(fun ), min(evals [, name.y ]), max(evals [, name.y ]))
8888 else
@@ -93,7 +93,7 @@ exampleRun = function(fun, design = NULL, learner = NULL, control,
9393 messagef(" Performing MBO on function." )
9494 if (is.null(design ))
9595 messagef(" Initial design: %i. Sequential iterations: %i." , control $ init.design.points , control $ iters )
96- messagef(" Learner: %s. Settings:\n %s" , learner $ id , mlr ::: getHyperParsString(learner ))
96+ messagef(" Learner: %s. Settings:\n %s" , learner $ id , mlr ::: getHyperParsString(learner , show.missing.values = FALSE ))
9797 }
9898
9999 # run optimizer now
@@ -104,7 +104,14 @@ exampleRun = function(fun, design = NULL, learner = NULL, control,
104104 if (! is.null(fun.mean )) {
105105 y.true = vnapply(convertRowsToList(getOptPathX(res $ opt.path ), name.list = TRUE , name.vector = TRUE ), fun.mean )
106106 }
107-
107+
108+ if (control $ multifid ) {
109+ n.params = n.params - 1
110+ par.set = dropParams(par.set , " .multifid.lvl" )
111+ par.types = getParamTypes(par.set )
112+ names.x = getParamIds(par.set , repeated = TRUE , with.nr = TRUE )
113+ }
114+
108115 makeS3Obj(" MBOExampleRun" ,
109116 fun.mean = fun.mean ,
110117 par.set = par.set ,
@@ -135,7 +142,7 @@ print.MBOExampleRun = function(x, ...) {
135142 catf(" True points per dim. : %s" , collapse(x $ points.per.dim ))
136143 print(x $ control )
137144 catf(" Learner : %s" , x $ learner $ id )
138- catf(" Learner settings:\n %s" , mlr ::: getHyperParsString(x $ learner ))
145+ catf(" Learner settings:\n %s" , mlr ::: getHyperParsString(x $ learner , show.missing.values = FALSE ))
139146 mr = x $ mbo.res
140147 op = mr $ opt.path
141148 catf(" Recommended parameters:" )
@@ -158,29 +165,13 @@ getEvals = function(fun, par.set, noisy, noisy.evals, points.per.dim, names.x, n
158165 return (evals )
159166}
160167
161- getEvalsForMultifid = function (fun , par.set , noisy , noisy.evals , points.per.dim , names.x , name.y , multifid.lvls ) {
162- eval.list = lapply(multifid.lvls , function (l ){
163- force(l )
164- force(fun )
165- this.fun = function (x ) {
166- x $ .multifid.lvl = l
167- fun(x )
168- }
169- evals = getEvals(this.fun , par.set , noisy , noisy.evals , points.per.dim , names.x , name.y )
170- cbind.data.frame(.multifid.lvl = l , evals )
171- })
172- do.call(" rbind" , eval.list )
173- }
174-
175168evaluate = function (fun , par.set , n.params , par.types , noisy , noisy.evals , points.per.dim , names.x , name.y , multifid.lvls = numeric (0 )) {
176169 if (! noisy && n.params == 1L && par.types == " discrete" )
177170 stopf(" ExampleRun does not make sense with a single deterministic discrete parameter." )
171+ if (length(multifid.lvls ) && n.params %in% c(2L ,3L ) && all(par.types %in% c(" numeric" , " numericvector" , " discrete" , " integer" )))
172+ return (getEvals(fun , par.set , noisy , noisy.evals , points.per.dim * length(multifid.lvls ), names.x , name.y ))
178173 if (n.params %in% c(1L , 2L ) && all(par.types %in% c(" numeric" , " numericvector" , " discrete" ))) {
179- if (length(multifid.lvls )) {
180- return (getEvalsForMultifid(fun , par.set , noisy , noisy.evals , points.per.dim , names.x , name.y , multifid.lvls ))
181- } else {
182- return (getEvals(fun , par.set , noisy , noisy.evals , points.per.dim , names.x , name.y ))
183- }
174+ return (getEvals(fun , par.set , noisy , noisy.evals , points.per.dim , names.x , name.y ))
184175 }
185176}
186177
0 commit comments