diff --git a/R/exampleRun.R b/R/exampleRun.R index e0a783353..44919d3ec 100644 --- a/R/exampleRun.R +++ b/R/exampleRun.R @@ -93,7 +93,7 @@ exampleRun = function(fun, design = NULL, learner = NULL, control, messagef("Performing MBO on function.") if (is.null(design)) messagef("Initial design: %i. Sequential iterations: %i.", control$init.design.points, control$iters) - messagef("Learner: %s. Settings:\n%s", learner$id, mlr:::getHyperParsString(learner, show.missing.values = FALSE)) + messagef("Learner: %s. Settings:\n%s", learner$id, getHyperParsString2(learner, show.missing.values = FALSE)) } # run optimizer now @@ -142,7 +142,7 @@ print.MBOExampleRun = function(x, ...) { catf("True points per dim. : %s", collapse(x$points.per.dim)) print(x$control) catf("Learner : %s", x$learner$id) - catf("Learner settings:\n%s", mlr:::getHyperParsString(x$learner, show.missing.values = FALSE)) + catf("Learner settings:\n%s", getHyperParsString2(x$learner, show.missing.values = FALSE)) mr = x$mbo.res op = mr$opt.path catf("Recommended parameters:") diff --git a/R/exampleRunMultiObj.R b/R/exampleRunMultiObj.R index da9466391..2ceb48e47 100644 --- a/R/exampleRunMultiObj.R +++ b/R/exampleRunMultiObj.R @@ -91,7 +91,7 @@ exampleRunMultiObj= function(fun, design = NULL, learner, control, points.per.di showInfo(show.info, "Performing MBO on function.") showInfo(show.info, "Initial design: %i. Sequential iterations: %i.", control$init.design.points, control$iters) - showInfo(show.info, "Learner: %s. Settings:\n%s", learner$id, mlr:::getHyperParsString(learner, show.missing.values = FALSE)) + showInfo(show.info, "Learner: %s. Settings:\n%s", learner$id, getHyperParsString2(learner, show.missing.values = FALSE)) # run optimizer now res = mbo(fun, design, learner = learner, control = control, show.info = show.info) @@ -151,7 +151,7 @@ print.MBOExampleRunMultiObj = function(x, ...) { catf("Parameter types : %s", collapse(x$par.types)) print(x$control) catf("Learner : %s", x$learner$id) - catf("Learner settings:\n%s", mlr:::getHyperParsString(x$learner, show.missing.values = FALSE)) + catf("Learner settings:\n%s", getHyperParsString2(x$learner, show.missing.values = FALSE)) catf("Hypervolume : %.4e", x$mbo.hypervolume) catf("NSGA2 Hypervolume (6000 FEs) : %.4e", x$nsga2.hypervolume) } diff --git a/R/utils.R b/R/utils.R index c55124037..1fcb463b3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -46,4 +46,12 @@ measureTime = function(expr, ee = parent.frame()) { # FIXME: remove as soon as this is in ParamHelper isSimpleNumeric = function(par) { isNumeric(par, include.int = TRUE) && !hasRequires(par) -} \ No newline at end of file +} + +getHyperParsString2 = function(learner, show.missing.values = TRUE) { + hps = getHyperPars(learner) + ns = names(hps) + pars = getParamSet(learner)$pars[ns] + s = mapply(paramValueToString, pars, hps, MoreArgs = list(show.missing.values = show.missing.values)) + paste(ns, s, sep = "=", collapse = ",") +} diff --git a/inst/examples/ex_1d_noisy_numeric.R b/inst/examples/ex_1d_noisy_numeric.R index 8c18098ac..a4bf27619 100644 --- a/inst/examples/ex_1d_noisy_numeric.R +++ b/inst/examples/ex_1d_noisy_numeric.R @@ -26,8 +26,8 @@ ctrl = makeMBOControl( ) ctrl = setMBOControlTermination(ctrl, iters = 5L) -ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), opt = "focussearch", - opt.focussearch.points = 500L) +ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), + opt = "focussearch", opt.focussearch.points = 500L) lrn = makeMBOLearner(ctrl, obj.fun) diff --git a/inst/examples/ex_1d_numeric.R b/inst/examples/ex_1d_numeric.R index 6978ff399..08fb5fa5b 100644 --- a/inst/examples/ex_1d_numeric.R +++ b/inst/examples/ex_1d_numeric.R @@ -18,8 +18,8 @@ obj.fun = makeSingleObjectiveFunction( ctrl = makeMBOControl(propose.points = 1) ctrl = setMBOControlTermination(ctrl, iters = 10L) -ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), opt = "focussearch", - opt.focussearch.points = 500L) +ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), + opt = "focussearch", opt.focussearch.points = 500L) lrn = makeMBOLearner(ctrl, obj.fun) diff --git a/inst/examples/ex_2d_numeric.R b/inst/examples/ex_2d_numeric.R index 9a7b9485c..ac012e0d3 100644 --- a/inst/examples/ex_2d_numeric.R +++ b/inst/examples/ex_2d_numeric.R @@ -13,8 +13,8 @@ obj.fun = makeBraninFunction() ctrl = makeMBOControl(propose.points = 1L) ctrl = setMBOControlTermination(ctrl, iters = 10L) -ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), opt = "focussearch", - opt.focussearch.points = 2000L) +ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), + opt = "focussearch", opt.focussearch.points = 2000L) lrn = makeMBOLearner(ctrl, obj.fun) design = generateDesign(10L, getParamSet(obj.fun), fun = lhs::maximinLHS) diff --git a/inst/examples/ex_mixed.R b/inst/examples/ex_mixed.R index 384aaf02b..94bcf9c80 100644 --- a/inst/examples/ex_mixed.R +++ b/inst/examples/ex_mixed.R @@ -27,8 +27,8 @@ obj.fun = makeSingleObjectiveFunction( ctrl = makeMBOControl(propose.points = 1L) ctrl = setMBOControlTermination(ctrl, iters = 10L) -ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), opt = "focussearch", - opt.focussearch.points = 500L) +ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), + opt = "focussearch", opt.focussearch.points = 500L) lrn = makeMBOLearner(ctrl, obj.fun) diff --git a/man/mlrMBO_examples.Rd b/man/mlrMBO_examples.Rd index d1df13eb6..12ea147c6 100644 --- a/man/mlrMBO_examples.Rd +++ b/man/mlrMBO_examples.Rd @@ -27,8 +27,8 @@ obj.fun = makeSingleObjectiveFunction( ctrl = makeMBOControl(propose.points = 1) ctrl = setMBOControlTermination(ctrl, iters = 10L) -ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), opt = "focussearch", - opt.focussearch.points = 500L) +ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), + opt = "focussearch", opt.focussearch.points = 500L) lrn = makeMBOLearner(ctrl, obj.fun) @@ -54,8 +54,8 @@ obj.fun = makeBraninFunction() ctrl = makeMBOControl(propose.points = 1L) ctrl = setMBOControlTermination(ctrl, iters = 10L) -ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), opt = "focussearch", - opt.focussearch.points = 2000L) +ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), + opt = "focussearch", opt.focussearch.points = 2000L) lrn = makeMBOLearner(ctrl, obj.fun) design = generateDesign(10L, getParamSet(obj.fun), fun = lhs::maximinLHS) @@ -168,8 +168,8 @@ ctrl = makeMBOControl( ) ctrl = setMBOControlTermination(ctrl, iters = 5L) -ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), opt = "focussearch", - opt.focussearch.points = 500L) +ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), + opt = "focussearch", opt.focussearch.points = 500L) lrn = makeMBOLearner(ctrl, obj.fun) @@ -260,8 +260,8 @@ obj.fun = makeSingleObjectiveFunction( ctrl = makeMBOControl(propose.points = 1L) ctrl = setMBOControlTermination(ctrl, iters = 10L) -ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), opt = "focussearch", - opt.focussearch.points = 500L) +ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI(), + opt = "focussearch", opt.focussearch.points = 500L) lrn = makeMBOLearner(ctrl, obj.fun) diff --git a/tests/run-examples.R b/tests/run-examples.R deleted file mode 100644 index 2f81d0da2..000000000 --- a/tests/run-examples.R +++ /dev/null @@ -1,15 +0,0 @@ -library(mlrMBO) - -# check all demo examples here - -# if (any(c("R_EXPENSIVE_TEST_OK") %in% names(Sys.getenv()))) { -if (any(c("TRAVIS", "R_EXPENSIVE_TEST_OK") %in% names(Sys.getenv()))) { - library(BBmisc) - - dir = file.path(path.package("mlrMBO"), file.path("examples")) - files = list.files(dir, pattern = ".R", full.names = TRUE) - for (f in files) { - messagef("Checking example '%s'", f) - source(f) - } -} diff --git a/vignettes/parallelization.Rmd b/vignettes/parallelization.Rmd index 63139315f..1cc38c417 100644 --- a/vignettes/parallelization.Rmd +++ b/vignettes/parallelization.Rmd @@ -137,7 +137,7 @@ ctrl = setMBOControlInfill(ctrl, crit = crit.cb) ctrl = setMBOControlMultiPoint(ctrl, method = "cb") ctrl = setMBOControlTermination(ctrl, iters = 5) design = generateDesign(n = 5*8, par.set = getParamSet(obj.fun)) -# library(parallelMap) +library(parallelMap) # parallelStartMulticore(cpus = 2, show.info = FALSE) res = mbo(obj.fun, control = ctrl, design = design, show.info = FALSE) # parallelStop() @@ -178,7 +178,7 @@ autoplot(obj.fun.single, render.levels = TRUE) + general.scale Now let's create an objective function that uses parallelization internally by using the function `parallelMap()` of the equally named package. ```{r custom_noisy_parallel} -# parallelRegisterLevels(levels = "objective") +parallelRegisterLevels(levels = "objective") obj.fun.parallel = makeSingleObjectiveFunction( name = "noisy_example", fn = function(x) { @@ -204,7 +204,7 @@ library(mlr) ctrl = makeMBOControl(final.method = "best.predicted") ctrl = setMBOControlTermination(ctrl, iters = 5L) ctrl = setMBOControlInfill(ctrl, crit = crit.aei) -# parallelStartMulticore(cpus = 4L, show.info = TRUE, level = "custom.objective") +# parallelStartMulticore(cpus = 2L, show.info = TRUE, level = "custom.objective") res.parallel = mbo(obj.fun.parallel, control = ctrl, show.info = FALSE) # parallelStop() res.parallel