mosmafs (version 0.1.2)

slickEcr: Modified Interface to ECR

Description

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

slickEcr does mostly what ecr::ecr does, with different default values at places. Note that fitness.fun 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.

Usage

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

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

continueEcr( ecr.object, generations, 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, unbiased.fidelity = NULL )

Value

[MosmafsResult] the terminated optimization state.

Arguments

fitness.fun

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

lambda

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

population

[list] list of individuals to start off from.

mutator

[ecr_mutator] mutation operator.

recombinator

[ecr_recombinator] recombination operator.

generations

[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.

parent.selector

[ecr_selector] parent selection operator.

survival.selector

[ecr_selector] survival selection operator.

p.recomb

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

p.mut

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

survival.strategy

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

n.elite

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

fidelity

[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.

unbiased.fidelity

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

log.stats

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

log.stats.newinds

[list] information to log for each newly evaluated individuals

ecr.object

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

Examples

Run this code
# \donttest{
library("mlr")
library("magrittr")
library("mlrCPO")

# Define tasks
task.whole <- create.hypersphere.data(3, 2000) %>%
create.classif.task(id = "sphere") %>%
task.add.permuted.cols(10)
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
fitness.fun <- makeObjective(lrn, task, ps, cv5,
 holdout.data = task.hout)
 
#  Receive parameter set from fitness function
ps.objective <- getParamSet(fitness.fun)

# 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(fitness.fun = fitness.fun, 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(
 fitness.fun = fitness.fun, lambda = 5, population = initials,
 mutator = mutator,
 recombinator = crossover,
 generations = 5)
 
print(run.simple)
# } 

Run the code above in your browser using DataLab