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)
control | [ |
---|---|
log.stats | [ |
log.pop | [ |
init.size | [ |
[ecr_logger
]
An S3 object of class ecr_logger
with the following components:
The log.stats
list.
The log.pop
parameter.
Initial size of the log.
The actual log. This is an R environment which ensures, that in-place modification is possible.
Other logging: getPopulations
,
getStatistics
, updateLogger
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