Logging is a central aspect of each EA. Besides the final solution(s) especially in research often we need to keep track of different aspects of the evolutionary process, e.g., fitness statistics. The logger of ecr2 keeps track of different user-defined statistics and the population. It may also be used to check stopping conditions (see makeECRTerminator). Most important this logger is used internally by the ecr black-box interface.

initLogger(control, log.stats = list(fitness = list("min", "mean", "max")),
  log.pop = FALSE, init.size = 1000L)

Arguments

control

[ecr_control] Control object.

log.stats

[list] List of lists for statistic computation on attributes of the individuals of the population. Each entry should be named by the attribute it should be based on, e.g., fitness, and should contain a list of R functions as a character string or a a list with elements fun for the function, and pars for additional parameters which shall be passed to the corresponding function. Each function is required to return a scalar numeric value. By default the minimum, mean and maximum of the fitness values is computed. Since fitness statistics are the most important ones these do not have to be stored as attributes, but can be passed as a matrix to the update function.

log.pop

[logical(1)] Shall the entire population be saved in each generation? Default is FALSE.

init.size

[integer(1)] Initial number of rows of the slot of the logger, where the fitness statistics are stored. The size of the statistics log is doubled each time an overflow occurs. Default is 1000.

Value

[ecr_logger] An S3 object of class ecr_logger with the following components:

log.stats

The log.stats list.

log.pop

The log.pop parameter.

init.size

Initial size of the log.

env

The actual log. This is an R environment which ensures, that in-place modification is possible.

See also

Other logging: getPopulations, getStatistics, updateLogger

Examples

control = initECRControl(function(x) sum(x), minimize = TRUE, n.objectives = 1L) control = registerECROperator(control, "mutate", mutBitflip, p = 0.1) control = registerECROperator(control, "selectForMating", selTournament, k = 2) control = registerECROperator(control, "selectForSurvival", selGreedy) log = initLogger(control, log.stats = list( fitness = list("mean", "myRange" = function(x) max(x) - min(x)), age = list("min", "max") ), log.pop = TRUE, init.size = 1000L) # simply pass stuff down to control object constructor population = initPopulation(mu = 10L, genBin, n.dim = 10L) fitness = evaluateFitness(control, population) # append fitness to individuals and init age for (i in seq_along(population)) { attr(population[[i]], "fitness") = fitness[, i] attr(population[[i]], "age") = 1L } for (iter in seq_len(10)) { # generate offspring offspring = generateOffspring(control, population, fitness, lambda = 5) fitness.offspring = evaluateFitness(control, offspring) # update age of population for (i in seq_along(population)) { attr(population[[i]], "age") = attr(population[[i]], "age") + 1L } # set offspring attributes for (i in seq_along(offspring)) { attr(offspring[[i]], "fitness") = fitness.offspring[, i] # update age attr(offspring[[i]], "age") = 1L } sel = replaceMuPlusLambda(control, population, offspring) population = sel$population fitness = sel$fitness # do some logging updateLogger(log, population, n.evals = 5) } head(getStatistics(log))
#> gen fitness.mean fitness.myRange age.min age.max #> 1 1 4.7 2 1 2 #> 2 2 3.9 3 1 3 #> 3 3 3.4 2 1 4 #> 4 4 3.0 2 1 5 #> 5 5 2.0 0 1 4 #> 6 6 2.0 0 2 5