slickEcr: Modified Interface to ECR

View source: R/customnsga2.R

slickEcrR Documentation

Modified Interface to ECR


Mostly ecr::ecr, with some simplifications and extensions.

slickEcr does mostly what ecr::ecr does, with different default values at places. Note that must be a "smoof" function.

initEcr only evaluates fitness for the initial population and does not perform any mutation or selection.

continueEcr continues a run for another number of generations. Only ecr.object (a result from a previous initEcr, slickEcr, or continueEcr call) and generations must be given, the other arguments are optional. If they were set in a previous slickEcr or continueEcr call, the values from the previous run are used. Otherwise it is possible to supply any combination of these values to set them to new values.

Note, for fidelity, that the generation continues counting from previous runs, so if initEcr was ran for 5 generations and continueEcr is called with a fidelity with first column values c(1, 8), then the fidelity given in the first row is applied for 2 generations, after which the fidelity given in the second row applies.


  generations = 100,
  parent.selector = selSimple,
  survival.selector = selNondom,
  p.recomb = 0.7,
  p.mut = 0.3,
  survival.strategy = "plus",
  n.elite = 0,
  fidelity = NULL, = TRUE,
  log.stats = NULL,
  log.stats.newinds = c(list(runtime = list("mean", "sum")), if (!is.null(fidelity))
    list(fidelity = list("sum")))

  fidelity = NULL,
  log.stats = NULL,
  log.stats.newinds = c(list(runtime = list("mean", "sum")), if (!is.null(fidelity))
    list(fidelity = list("sum"))), = TRUE

  lambda = NULL,
  mutator = NULL,
  recombinator = NULL,
  parent.selector = NULL,
  survival.selector = NULL,
  p.recomb = NULL,
  p.mut = NULL,
  survival.strategy = NULL,
  n.elite = NULL,
  fidelity = NULL, = NULL


[smoof_multi_objective_function] fitness function, must be a "smoof" function.


[integer(1)] number of individuals to add in each generation.


[list] list of individuals to start off from.


[ecr_mutator] mutation operator.


[ecr_recombinator] recombination operator.


[integer(1) | list of function] number of iterations to evaluate if it is an integer, or terminator function. If this is an integer, it counts the new generations to evaluate; otherwise the terminator functions are applied to the whole combined trace of evaluation.


[ecr_selector] parent selection operator.


[ecr_selector] survival selection operator.


[numeric(1)] probability to apply a recombination operator.


[numeric(1)] probability to apply mutation operator.


[character(1)|function] one of "plus" or "comma" or a function. If function, arguments must be the same as for ecr::replaceMuPlusLambda.


[integer(1)] Number of elites to keep, only used if survival.strategy is "comma"


[data.frame | NULL] If this is given, it controls the fidelity of the function being evaluated, via its fidelity argument. It must then be a data.frame with two or three columns. The first column gives the generation at which the fidelity first applies; the second column controls the fidelity at that generation or later; the third column, if given, controls the additional fidelity whenever the result of the first evaluation is not dominated by any result of the previous generation. The entries in the first column must be strictly ascending. The first element of the first column must always be 1. Whenever fidelity changes, the whole population is re-evaluated, so it is recommended to use only few different fidelity jumps throughout all generations.

[logical(1)] Whether generations do not have to be re-evaluated when fidelity jumps downward.


[list] information to log for each generation. Defaults to min, mean, and max of each objective as well as dominated hypervolume.


[list] information to log for each newly evaluated individuals


[MosmafsResult] an object retrieved from previous runs of initEcr, slickEcr, or continueEcr


[MosmafsResult] the terminated optimization state.



# Define tasks
task.whole <-, 2000) %>%
create.classif.task(id = "sphere") %>%
rows.whole <- sample(2000)
task <- subsetTask(task.whole, rows.whole[1:500])
task.hout <- subsetTask(task.whole, rows.whole[501:2000])

# Create learner
lrn <- makeLearner("classif.rpart", maxsurrogate = 0)

# Create parameter set to optimize over
ps <- pSS(
 maxdepth: integer[1, 30],
 minsplit: integer[2, 30],
 cp: numeric[0.001, 0.999])

# Create fitness function <- makeObjective(lrn, task, ps, cv5, = task.hout)
#  Receive parameter set from fitness function
ps.objective <- getParamSet(

# Define mutators and recombinators
mutator <- combine.operators(ps.objective,
 numeric = ecr::setup(mutGauss, sdev = 0.1),
 integer = ecr::setup(mutGaussInt, sdev = 3),
 selector.selection = mutBitflipCHW)
crossover <- combine.operators(ps.objective,
 numeric = recPCrossover,
 integer = recPCrossover,
 selector.selection = recPCrossover)

# Initialize population and evaluate it
initials <- sampleValues(ps.objective, 32, discrete.names = TRUE)
run.init <- initEcr( =, population = initials)

# Run NSGA-II for 5 generations with run.init as input
run.gen <- continueEcr(run.init, generations = 5, lambda = 5, mutator = mutator, 
 recombinator = crossover, parent.selector = selSimple, 
 survival.selector = selNondom, 
 p.recomb = 0.7, p.mut = 0.3, survival.strategy = "plus")
# Or instead of initEcr and continueEcr use the shortcut function slickEcr
run.simple <- slickEcr( =, lambda = 5, population = initials,
 mutator = mutator,
 recombinator = crossover,
 generations = 5)

mosmafs documentation built on Nov. 3, 2022, 1:05 a.m.