View source: R/logger.default.R
initLogger | R Documentation |
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 ecr 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.extras = NULL,
log.pop = FALSE,
init.size = 1000L
)
control |
[ |
log.stats |
[ |
log.extras |
[ |
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.
Statistics are logged in a data.frame
.
Other logging:
getPopulationFitness()
,
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.