Package ‘ecr’
September 10, 2016
Type Package
Title Evolutionary Computing in R
Description Provides a powerful framework for evolutionary
computing in R. The user can easily construct powerful evolutionary algorithms for tackling both single- and multi-objective problems by plugging in different predefined evolutionary building blocks, e. g., operators for mutation,
recombination and selection with just a few lines of code. Your problem cannot be easily solved with a standard EA which works on real-valued vectors, permutations or binary strings? No problem, 'ecr' has been developed with that in mind. Extending the framework with own operators is also possible. Additionally there are various comfort functions, like monitoring, logging and more.
Version 1.0.1 Encoding UTF-8 Date 2016-09-10
Maintainer Jakob Bossek<[email protected]>
License BSD_2_clause + file LICENSE URL https://github.com/jakobbossek/ecr
BugReports https://github.com/jakobbossek/ecr/issues Depends ParamHelpers (>= 1.8), BBmisc (>= 1.6), smoof (>= 1.4),
ggplot2 (>= 1.0.0)
Imports checkmate (>= 1.1), parallelMap (>= 1.1), reshape2 (>= 1.4.1), gridExtra (>= 0.9.1)
Suggests testthat (>= 0.9.1) ByteCompile yes
LazyData yes RoxygenNote 5.0.1 NeedsCompilation yes
Author Jakob Bossek [aut, cre], Dirk Surmann [ctb]
Repository CRAN
Date/Publication 2016-09-10 18:06:34
1
2 R topics documented:
R topics documented:
approximateNadirPoint . . . 4
asemoa . . . 4
autoplot.ecr_single_objective_result . . . 6
buildInitialPopulation . . . 7
computeAverageHausdorffDistance . . . 8
computeCrowdingDistance . . . 8
computeDistanceFromPointToSetOfPoints . . . 9
computeDominatedHypervolume . . . 10
computeEpsilonIndicator . . . 10
computeGenerationalDistance . . . 12
computeInvertedGenerationalDistance . . . 12
dominated . . . 13
dominates . . . 14
doNondominatedSorting . . . 14
doTheEvolution . . . 15
ecr . . . 17
ecrpackage . . . 20
ecr_parallelization . . . 21
ecr_result . . . 22
evaluateFitness . . . 23
generateOffspring . . . 23
getAvailableEventNames . . . 24
getEvaluations . . . 24
getGenerations . . . 25
getNextGeneration . . . 25
getOperatorName . . . 26
getOperatorParameters . . . 26
getSupportedRepresentations . . . 27
is.supported . . . 27
isEcrOperator . . . 28
makeGenerator . . . 28
makeMonitor . . . 29
makeMutator . . . 30
makeOperator . . . 31
makeOptimizationTask . . . 32
makePopulation . . . 33
makeRecombinator . . . 33
makeSelector . . . 34
makeTerminator . . . 35
mergePopulations . . . 36
nsga2 . . . 36
onePlusOneGA . . . 37
OptState . . . 38
OptStateGetter . . . 39
print.ecr_control . . . 40
registerAction . . . 40
R topics documented: 3
rescalePoints . . . 41
selectForMating . . . 41
selectForSurvival . . . 42
setupBinaryGenerator . . . 43
setupBitFlipMutator . . . 43
setupCloseToOptimumTerminator . . . 44
setupConsoleMonitor . . . 44
setupCrossoverRecombinator . . . 45
setupDominatedHypervolumeSelector . . . 45
setupECRControl . . . 46
setupEvolutionaryOperators . . . 47
setupGaussMutator . . . 48
setupGreedySelector . . . 49
setupInsertionMutator . . . 50
setupIntermediateRecombinator . . . 50
setupInversionMutator . . . 51
setupMaximumEvaluationsTerminator . . . 51
setupMaximumIterationsTerminator . . . 52
setupMaximumTimeTerminator . . . 52
setupNondomSelector . . . 53
setupNullRecombinator . . . 53
setupOptPathLoggingMonitor . . . 54
setupOptState . . . 54
setupOXRecombinator . . . 55
setupParentSelector . . . 56
setupPermutationGenerator . . . 56
setupPMXRecombinator . . . 57
setupPolynomialMutator . . . 57
setupRouletteWheelSelector . . . 58
setupSBXRecombinator . . . 59
setupScrambleMutator . . . 60
setupSimpleSelector . . . 60
setupSwapMutator . . . 61
setupTerminators . . . 61
setupTournamentSelector . . . 62
setupUniformGenerator . . . 62
setupUniformMutator . . . 63
simpleEA . . . 63
smsemoa . . . 65
summary.ecr_multi_objective_result . . . 66
updateOptState . . . 67
which.dominated . . . 67
wrapChildren . . . 68
Index 69
4 asemoa
approximateNadirPoint Reference point approximations.
Description
Helper functions to compute nadir or ideal point from sets of points, e.g., multiple approximation sets.
Usage
approximateNadirPoint(..., sets = NULL) approximateIdealPoint(..., sets = NULL)
Arguments
... [any]
Arbirary number of matrizes.
sets [list]
List of sets. This is an alternative way of passing the sets. Can be used exclu- sively or combined with....
Value
numeric Reference point.
asemoa Implementation of the NSGA-II EMOA algorithm by Deb.
Description
The AS-EMOA, short for aspiration set evolutionary multi-objective algorithm aims to incorporate expert knowledge into multi-objective optimization [1]. The algorithm expects an aspiration set, i.e., a set of reference points. It then creates an approximation of the pareto front close to the aspiration set utilizing the average Hausdorff distance.
Usage
asemoa(task, n.population = 10L, aspiration.set = NULL,
normalize.fun = NULL, dist.fun = ecr:::computeEuclideanDistance, p = 1, parent.selector = setupSimpleSelector(),
mutator = setupPolynomialMutator(eta = 25, p = 0.2),
recombinator = setupSBXRecombinator(eta = 15, p = 0.7), max.iter = 100L, max.evals = NULL, max.time = NULL, ...)
asemoa 5 Arguments
task [ecr_optimization_task]
Optimization task. If asmoof_function is passed it is automatically converted into a task.
n.population [integer(1)]
Population size. Default is10.
aspiration.set [matrix]
The aspiration set. Each column contains one point of the set.
normalize.fun [function]
Function used to normalize fitness values of the individuals before computation of the average Hausdorff distance. The function must have the formal arguments
“set” and “aspiration.set”. Default isNULL, i.e., no normalization at all.
dist.fun [function]
Distance function used internally by Hausdorff metric to compute distance be- tween two points. Expects a single vector of coordinate-wise differences be- tween points. Default iscomputeEuclideanDistance.
p [numeric(1)]
Parameter p for the average Hausdorff metric. Default is 1.
parent.selector
[ecr_selector]
Selection operator which implements a procedure to copy individuals from a given population to the mating pool, i. e., allow them to become parents.
mutator [ecr_mutator]
Mutation operator of typeecr_mutator.
recombinator [ecr_recombinator]
Recombination operator of typeecr_recombinator.
max.iter [integer(1)]
Maximal number of iterations. Default ist100L.
max.evals [integer(1)]
Maximal number of iterations/generations. Default isInf.
max.time [integer(1)]
Time budget in seconds. Default istInf.
... [any]
Further arguments passed tosetupECRControl.
Value
ecr_asemoa_result, ecr_multi_objective_result
Note
This is a pure R implementation of the AS-EMOA algorithm. It hides the regular ecr interface and offers a more R like interface while still being quite adaptable.
6 autoplot.ecr_single_objective_result References
[1] Rudolph, G., Schuetze, S., Grimme, C., Trautmann, H: An Aspiration Set EMOA Based on Averaged Hausdorff Distances. LION 2014: 153-156. [2] G. Rudolph, O. Schuetze, C. Grimme, and H. Trautmann: A Multiobjective Evolutionary Algorithm Guided by Averaged Hausdorff Dis- tance to Aspiration Sets, pp. 261-273 in A.-A. Tantar et al. (eds.): Proceedings of EVOLVE - A bridge between Probability, Set Oriented Numerics and Evolutionary Computation V, Springer:
Berlin Heidelberg 2014.
Examples
library(smoof)
obj.fn = makeDTLZ2Function(dimensions = 2L, n.objectives = 2L)
# define the aspiration set, i.e., a set of reference points aspiration.set = matrix(
c(0.1531, 0.1594, 0.1656, 0.1719, 0.1781, 0.1844, 0.1906, 0.1969, 0.2031, 0.2094, 0.2094, 0.2031, 0.1969, 0.1906, 0.1844, 0.1781, 0.1719, 0.1656, 0.1594, 0.1531), byrow = TRUE,
nrow = 2L )
## Not run:
res = asemoa(
task = obj.fn, n.population = 10L,
aspiration.set = aspiration.set, max.evals = 1000L
)
## End(Not run)
autoplot.ecr_single_objective_result Plot optimization trace.
Description
Call this function on the result object of andoTheEvolutionfunction call to visualize the optimiza- tion trace.
Usage
## S3 method for class 'ecr_single_objective_result' autoplot(object, show.process = FALSE,
log.fitness = FALSE, complete.trace = TRUE, ...)
buildInitialPopulation 7 Arguments
object [ecr_result]
ecr result object.
show.process [logical(1)]
Should the function itself with the population be plotted as well? Thinks makes in particular sense withcomplete.trace = FALSE to see the progress. Keep in mind, that this is possible only if the representation is “float” and the objective function has at most two decision variables. Default isFALSE.
log.fitness [logical(1)]
Log-transform fitness values? Default isFALSE.
complete.trace [logical(1)]
Direct show the plot with the fitness for all generations. Default isTRUE.
... [any]
Not used.
Value
invisible(TRUE)
buildInitialPopulation
Helper function to build initial population.
Description
Generates the initial population of an EA based on a list of initial individuals and/or the control object and the corresponding population generator.
Usage
buildInitialPopulation(n.population, task, control, initial.population = NULL)
Arguments
n.population [integer(1)]
Size of the population.
task [ecr_optimization_task]
Optimization task.
control [ecr_control]
Control object.
initial.population
[list | NULL]
Eventually a list of initial individuals.
Value
ecr_population
8 computeCrowdingDistance
computeAverageHausdorffDistance
Average Hausdorff Distance computation.
Description
Computes the average Hausdroff distance measure between two point sets.
Usage
computeAverageHausdorffDistance(A, B, p = 1, dist.fun = computeEuclideanDistance)
Arguments
A [matrix]
First point set (each column corresponds to a point).
B [matrix]
Second point set (each column corresponds to a point).
p [numeric(1)]
Parameter p of the average Hausdoff metrix. Default is 1. See the description for details.
dist.fun [matrix]
Distance function to compute distance between points x and y. Expects a single numeric vector d with the coordinate-wise differences di = (xi - yi). Default is computeEuclideanDist.
Value
numeric(1) Average Hausdorff distance of sets A and B.
computeCrowdingDistance
Compute the crowding distance of a set of points.
Description
The crowding distance is a measure of spread of solutions in the approximation of the Pareto front.
It is used, e.g., in the NSGA-II algorithm as a second selection criterion.
Usage
computeCrowdingDistance(x)
computeDistanceFromPointToSetOfPoints 9 Arguments
x [matrix]
Numeric matrix with each column representing a point.
Value
numeric Vector of crowding distance values.
References
K. Deb, A. Pratap, S. Agarwal, T. Meyarivan, A fast and elitist multiobjective genetic algorithm:
NSGA-II, IEEE Transactions on Evolutionary Computation In Evolutionary Computation, IEEE Transactions on, Vol. 6, No. 2. (07 April 2002), pp. 182-197, doi:10.1109/4235.996017
computeDistanceFromPointToSetOfPoints
Computes distance between a single point and set of points.
Description
Helper to compute distance between a single point and a point set.
Usage
computeDistanceFromPointToSetOfPoints(a, B, dist.fun = computeEuclideanDistance)
Arguments
a [numeric(1)]
Point given as a numeric vector.
B [matrix]
Point set (each column corresponds to a point).
dist.fun [matrix]
Distance function to compute distance between points x and y. Expects a single numeric vector d with the coordinate-wise differences di = (xi - yi). Default is computeEuclideanDist.
Value numeric(1)
10 computeEpsilonIndicator
computeDominatedHypervolume
Functions for the calculation of the dominated hypervolume (contri- bution).
Description
The functioncomputeDominatedHypervolume computes the dominated hypervolume of a set of points given a reference set wherebycomputeHypervolumeContribution computes the hypervol- ume contribution of each point.
If no reference point is given the nadir point of the setx is determined and a positive offset with default 1 is added. This is to ensure that the reference point dominates all of the points in the reference set.
Usage
computeDominatedHypervolume(x, ref.point = NULL)
computeHypervolumeContribution(x, ref.point = NULL, offset = 1)
Arguments
x [matrix]
Matrix of points (column-wise).
ref.point [numeric | NULL]
Reference point. Set to the maximum in each dimension by default if not pro- vided.
offset [numeric(1)]
Offset to be added to each component of the reference point only in the case where no reference is provided and one is calculated automatically.
Value
numeric(1) Dominated hypervolume in the case of computeDominatedHypervolume and the dominated hypervolume of a single point in the case ofcomputeHypervolumeContribution.
computeEpsilonIndicator
Computation of the unary epsilon-indicator.
computeEpsilonIndicator 11 Description
Functions for the computation of unary and binary measures which are useful for the evaluation of the performace of EMOAs. See the references section for literature on these indicators.
Given a set of pointspoints, computeEpsilonIndicator computes the unary epsilon-indicator provided a set of reference pointsref.points.
ThecomputeHypervolumeIndicator function computes the hypervolume indicator Hyp(X, R, r).
Given a set of point X (points), another set of reference points R (ref.points) (which maybe the true Pareto front) and a reference point r (ref.point) it is defined as Hyp(X, R, r) = HV(X, r) - HV(R, r).
Usage
computeEpsilonIndicator(points, ref.points)
computeHypervolumeIndicator(points, ref.points, ref.point = NULL) computeR1Indicator(points, ref.points, ideal.point = NULL,
nadir.point = NULL, lambda = NULL, utility = "tschebycheff") computeR2Indicator(points, ref.points, ideal.point = NULL,
nadir.point = NULL, lambda = NULL, utility = "tschebycheff") computeR3Indicator(points, ref.points, ideal.point = NULL,
nadir.point = NULL, lambda = NULL, utility = "tschebycheff")
Arguments
points [matrix]
Matrix of points.
ref.points [matrix]
Set of reference points.
ref.point [numeric]
A single reference point used e.g. for the computation of the hypervolume indi- cator viacomputeHypervolumeIndicator. If NULL the nadir point of the union of thepoints and ref.points is used.
ideal.point [numeric]
The utopia point of the true Pareto front, i.e., each component of the point con- tains the best value if the other objectives are neglected.
nadir.point [numeric]
Nadir point of the true Pareto front.
lambda [integer(1)]
Number of weight vectors to use in estimating the utility function.
utility [character(1)]
Name of the utility function to use. Must be one of “weightedsum”, “tscheby- cheff” or “augmented tschbycheff”.
12 computeInvertedGenerationalDistance Value
numeric(1) Epsilon indicator.
computeGenerationalDistance
Computes Generational Distance.
Description
Helper to compute the Generational Distance (GD) between two sets of points.
Usage
computeGenerationalDistance(A, B, p = 1, dist.fun = computeEuclideanDistance)
Arguments
A [matrix]
First point set (each column corresponds to a point).
B [matrix]
Second point set (each column corresponds to a point).
p [numeric(1)]
Parameter p of the average Hausdoff metrix. Default is 1. See the description for details.
dist.fun [matrix]
Distance function to compute distance between points x and y. Expects a single numeric vector d with the coordinate-wise differences di = (xi - yi). Default is computeEuclideanDist.
Value numeric(1)
computeInvertedGenerationalDistance
Computes Inverted Generational Distance.
Description
Helper to compute the Inverted Generational Distance (IGD) between two sets of points.
dominated 13 Usage
computeInvertedGenerationalDistance(A, B, p = 1, dist.fun = computeEuclideanDistance)
Arguments
A [matrix]
First point set (each column corresponds to a point).
B [matrix]
Second point set (each column corresponds to a point).
p [numeric(1)]
Parameter p of the average Hausdoff metrix. Default is 1. See the description for details.
dist.fun [matrix]
Distance function to compute distance between points x and y. Expects a single numeric vector d with the coordinate-wise differences di = (xi - yi). Default is computeEuclideanDist.
Value numeric(1)
dominated Check for pareto dominance.
Description
This functions takes a numeric matrixx where each column corresponds to a point and returns a logical vector. The i-th position of the latter isTRUE if the i-th point is dominated by at least one other point fordominated and FALSE for nonDominated.
Usage
dominated(x) nondominated(x)
Arguments
x [matrix]
Numeric (d x n) matrix where d is the number of objectives and n is the number of points.
Value logical
14 doNondominatedSorting
dominates Dominance relation check.
Description
Check if a vector dominates another (dominates) or is dominated by another (isDominated). There are corresponding infix operatorsdominates and isDominatedBy.
Usage
dominates(x, y) isDominated(x, y) x %dominates% y x %isDominatedBy% y
Arguments
x [numeric]
First vector.
y [numeric]
Second vector.
Value logical(1)
doNondominatedSorting Fast non-dominated sorting algorithm.
Description
Pure R implementation of the fast non-dominated sorting algorithm proposed by Deb. Non-dominated sorting expects a set of points and returns a set of non-dominated fronts. In short words this is done as follows: the non-dominated points of the entire set are determined and assigned rank 1. After- wards all points with the current rank are removed, the rank is increased by one and the procedure starts again. This is done until the set is empty, i.~e., each point is assigned a rank.
Usage
doNondominatedSorting(x)
doTheEvolution 15 Arguments
x [matrix]
Numeric matrix of points. Each column contains one objective vector.
Value
list List with the following components
ranks Integer vector of ranks of lengthncol(x). The higher the rank, the higher the domination front the corresponding point is located on.
dom.counter Integer vector of lengthncol(x). The i-th element is the domination number of the i-th point.
Note
This procedure is the key survival selection of the famous NSGA-II multi-objective evolutionary algorithm (seensga2).
References
[1] Deb, K., Pratap, A., and Agarwal, S. A Fast and Elitist Multiobjective Genetic Algorithm:
NSGA-II. IEEE Transactions on Evolutionary Computation, 6 (8) (2002), 182-197.
doTheEvolution Working horse of the ecr package.
Description
Takes a function and searches for a global optimum with an evolutionary approach.
Usage
doTheEvolution(task, control, initial.population = NULL, more.args = list())
Arguments
task [ecr_optimization_task]
Optimization task. If asmoof_function is passed it is automatically converted into a task.
control [ecr_control]
ECR control object generated viasetupECRControl. initial.population
[list]
List of individuals which should be placed in the initial population. The func- tion will stop with an error message if the number of passed individuals is larger thancontrol$n.population. If the number of passed individuals is lower than
16 doTheEvolution control$n.population, the population will be filled up by individuals gener- ated by the corresponding generator. Default isNULL, i.e., the entire population is generated by the population generator.
more.args [list]
Additional arguments passed to objective function.
Value ecr_result
See Also
setupECRControl Examples
library(smoof) library(ParamHelpers) library(ggplot2)
# We want to find the minimum of the function f(x) = x sin(2x) on the interval
# [0, 2pi]. The optimal value is about -5.5 for x = 5.54.
# First we wrap the function with the smoof package:
obj.fn = makeSingleObjectiveFunction(
name = "My obj. function", fn = function(x) x * sin(2 * x),
par.set = makeParamSet(makeNumericParam("x", lower = 0, upper = 2 * pi)) )
# We want to solve this with a (10 + 10) evolutionary strategy based on
# the floating point representation of the input vectors with the default
# operators: intermediate recombinator and Gaussian mutation ctrl = setupECRControl(
n.population = 10L, n.offspring = 10L,
survival.strategy = "plus", representation = "float",
stopping.conditions = setupTerminators(max.iter = 100L) )# use the default operators for representation "float"
ctrl = setupEvolutionaryOperators(ctrl) res = doTheEvolution(obj.fn, ctrl) print(res)
# Now let us choose a (10, 10) strategy with intermediate recombination. Moreover,
# we want the "fittest" individual to surive each time and therefore set n.elite
# to 1.
ctrl = setupECRControl(
n.population = 10L, n.offspring = 10L,
survival.strategy = "comma",
ecr 17 n.elite = 1L,
representation = "float",
stopping.conditions = setupTerminators(max.iter = 100L) )ctrl = setupEvolutionaryOperators(ctrl)
res = doTheEvolution(obj.fn, ctrl) print(res)
# Now let us tackle a two-dimensional problem
# Here we aim to find the global optimum of the 2D-Rastrigin function set.seed(1234)
obj.fn = makeRastriginFunction(2L) autoplot(obj.fn, show.optimum = TRUE)
# The global optimum is located in x1 = x2 = 0 with a function value of 0.
# We choose a (100 + 10) strategy with crossover recombination here and save
# each population. This way we can visualize the population later on.
ctrl = setupECRControl(
n.population = 100L, n.offspring = 10L,
survival.strategy = "plus", representation = "float",
logger = setupOptPathLoggingMonitor(),
stopping.conditions = setupTerminators(max.iter = 50L) )
ctrl = setupEvolutionaryOperators(
ctrl,
parent.selector = setupRouletteWheelSelector(), recombinator = setupCrossoverRecombinator(), survival.selector = setupGreedySelector() )## Not run:
res = doTheEvolution(obj.fn, ctrl) print(res)
autoplot(res, show.process = TRUE)
## End(Not run)
ecr Interface toecr similar to theoptimfunction.
Description
The most flexible way to setup evolutionary algorithms with ecr is by explicitely generating a task and a control object and passing both todoTheEvolution. Although this approach is highly flexible and very readable it requires quite a lot of code. However, in everyday life R users frequently need
18 ecr to optimize a single-objective R function. Theecr function thus provides a more R like interface for single objective optimization similar to the interface of theoptimfunction.
Usage
ecr(obj.fun, n.dim, lower = NULL, upper = NULL, n.bits, representation, n.population, n.offspring, n.mating.pool = floor(n.population/2),
survival.strategy = "plus", n.elite = 0L, vectorized.evaluation = FALSE, custom.constants = list(), logger = NULL,
monitor = setupConsoleMonitor(), max.iter = 100L, max.evals = NULL, max.time = NULL, more.args = list(), initial.population = NULL, parent.selector = getDefaultEvolutionaryOperators(representation,
"parent.selector"),
survival.selector = getDefaultEvolutionaryOperators(representation,
"survival.selector"),
generator = getDefaultEvolutionaryOperators(representation, "generator"), mutator = getDefaultEvolutionaryOperators(representation, "mutator"), recombinator = getDefaultEvolutionaryOperators(representation,
"recombinator"))
Arguments
obj.fun [function]
The single-objective target function. Can be any R function which takes a single vector as input and returns a scalar value describing the vectors fitness.
n.dim [integer(1)]
Dimension of the decision space.
lower [numeric]
Vector of minimal values for each parameter of the decision space in case of float or permutation encoding.
upper [numeric]
Vector of maximal values for each parameter of the decision space in case of float or permutation encoding.
n.bits [integer(1)]
Number of bits to use for binary representation.
representation [character(1)]
Genotype representation of the parameters. Available are “binary”, “float”, “per- mutation” and “custom”.
n.population [integer(1)]
Number of individuals in the population.
n.offspring [integer(1)]
Number of individuals generated in each generation.
n.mating.pool [integer(1)]
Number of individuals which can potentially participate in the generation of offspring. Default is half of the population size.
ecr 19 survival.strategy
[character(1)]
Determines the survival strategy used by the EA. Possible are “plus” for a clas- sical (mu + lambda) strategy and “comma” for (mu, lambda). Default is “plus”.
n.elite [integer(1)]
Number of fittest individuals of the current generation that shall be copied to the next generation without changing. Keep in mind, that the algorithm does not care about this option if thesurvival.strategy is set to ’plus’. Default is 0.
vectorized.evaluation [logical(1L)]
Is the fitness/objective function vectorized? I.e., does the fitness function accept a list? This allows for faster execution or parallelization by hand. IfTRUE the following destinction on the type of the objective function is made:
Issmoof_function If the objective function is of type smoof_function from package smoof and the smoof function is vectorized, the population - which is a list internally - is reduced to a matrix and passed to the smoof function (vectorization in smoof is allowed for continuous functions only).
Is not asmoof_function In this case the individuals of the population are passed entirely as a list to the objective function.
Default isFALSE.
custom.constants [list]
Additional constants which should be available to all generators and operators.
Defaults to empty list.
logger [function]
Monitoring object used to log stuff. Default isNULL which means no logging at all. SeesetupOptPathLoggingMonitorfor ecr’s build-in logger.
monitor [function]
Monitoring function. Default isNULL, i.e. no monitoring.
max.iter [integer(1)]
Maximal number of iterations. Default ist100L.
max.evals [integer(1)]
Maximal number of iterations/generations. Default isInf.
max.time [integer(1)]
Time budget in seconds. Default istInf.
more.args [list]
Additional arguments passed to objective function.
initial.population [list]
List of individuals which should be placed in the initial population. The func- tion will stop with an error message if the number of passed individuals is larger thancontrol$n.population. If the number of passed individuals is lower than control$n.population, the population will be filled up by individuals gener- ated by the corresponding generator. Default isNULL, i.e., the entire population is generated by the population generator.
20 ecrpackage parent.selector
[ecr_selector]
Selection operator which implements a procedure to copy individuals from a given population to the mating pool, i. e., allow them to become parents.
survival.selector
[ecr_selector]
Selection operator which implements a procedurce to extract individuals from a given set, which should survive and set up the next generation.
generator [ecr_generator]
Generator operator of typeecr_generator for the generation of the initial pop- ulation.
mutator [ecr_mutator]
Mutation operator of typeecr_mutator.
recombinator [ecr_recombinator]
Recombination operator of typeecr_recombinator.
Value ecr_result
Note
This helper function is applicable for single-objective optimization based on default encodings, i.e., binary, float and permutation, only. If your function at hand has multiple objectives or you need special encodings and operators you need to work withdoTheEvolutiondirectly.
See Also
setupECRControlfor building the control object,makeOptimizationTaskto define an optimiza- tion problem anddoTheEvolutionfor the main working horse of ecr.
Examples
fn = function(x) { sum(x^2) }
res = ecr(fn, n.dim = 2L, lower = c(-5, -5), upper = c(5, 5),
representation = "float", n.population = 20L, n.offspring = 10L, max.iter = 30L)
ecrpackage ecr: Evolutionary Computing in R
ecr_parallelization 21 Description
The ecr package offers a comprehensive collection of building blocks for both single- and multi- objective evolutionary algorithms.
Problems in Optimization Practisioners we are frequently faced with optimization problems. Un- fortunately these problems often consist of a variety of undesirable characteristics, e.g., nondif- ferentiability or noisyness. Besides, in particular in engineering, objective functions are often not given as an analytical formula. Instead a function evaluation is a run of a numerical simulation or even a physical experiment. Anyhow, optimization problems at hand are seldom easily tractable and thus well-known methods from mathematical optimization, e.g., Newton-Method or gradient descent algorithms, often cannot be appied for solving.
Evolutionary Optimization Evolutionary Algorithms (EAs) have proven very successful in a wide variety of real-world problems and they can handle objective functions with one or more of the aforementioned properties very well. In principle EAs follow a very easy principle which mimicks natural evoluation due to Darwin: instead of iteratively working on a single solution an EA generates a multiset of solution canditates, termned individuals, in the decision space. This multiset forms the initial population. Consequitively the following steps are applied until a stopping condition is met: Select a good subset of the individuals based on some selection criterion to form a socalled mating pool (selection criteria work randomly and mostly assign higher selection probabilities for individuals with high fitness, i.e., low fitness values). Then combine individuals from the mating pool using recombination operators to form new individuals which are further perturbed by mutation operators. Perform another selection to choose the next population.
Evolutionary Algorithms with ecr All evolutionary algorithms are build up of the same evolutionary operators: After initilizing an initial population, evolutionary operators, i.e., in particular parental selection, recombination, mutation and survival selection are applied until a stopping condition is met. This package offers a lot of ready to use building blocks, which can easily be combined to set up evolutionary algorithms, visualize results, monitor the optimization progress and compare different evolutionary operators and/or parametrizations.
See Also
setupECRControl,setupEvolutionaryOperators,makeOptimizationTask,doTheEvolution
ecr_parallelization Parallelization in ecr
Description
In ecr it is possible to parallelize different levels of computation to make use, e.g., of multiple CP cores or nodes in a HPC cluster. For maximal flexibility this is realized by means of the paral- lelMap package (see theofficial GitHub pagefor instructions on how to set up parallelization).
The different levels of parallelization can be specified in theparallelStart* function. At them moment the following levels are available:
ecr.evaluateFitness Do the fitness evaluation in parallel.
ecr.generateOffspring The generation of offspring individuals is performed in parallel.
22 ecr_result Keep in mind that parallelization comes along with some overhead. Thus activating paralleliza- tion, e.g., for evaluation a fitness function which is evaluated lightning-fast, may result in higher computation time. However, if the function evaluations are computationally more expensive, paral- lelization leads to impressive running time benefits.
ecr_result Result object.
Description
S3 object returned bydoTheEvolutioncontaining the best found parameter setting and value in the single-objective case and the Pareto-front/-set in case of a multi-objective optimization prob- lem. Moreover a set of further information, e.g., reason of termination, the control object etc. are returned.
The single objective result object contains the following fields:
final.opt.state The last optimization state.
task Theecr_optimization_task.
control Theecr_control object passed todoTheEvolution.
best.param Overall best parameter setting.
best.value Overall best objective value.
opt.path Optimization pathOptPath. last.population Last population.
population.storage Named list of populations stored during the process.
message Character string describing the reason of termination.
In case of a solved multi-objective function the result object contains the following fields:
final.opt.state The last optimization state.
task Theecr_optimization_task.
control Theecr_control object passed todoTheEvolution.
pareto.idx Indizes of the non-dominated solutions in the last population.
pareto.front (n x d) matrix of the approximated non-dominated front where n is the number of non-dominated points and d is the number of objectives.
pareto.set Matrix of decision space values resulting with objective values given in pareto.front.
last.population Last population.
population.storage Named list of populations stored during the process.
message Character string describing the reason of termination.
evaluateFitness 23
evaluateFitness Computes the fitness values for each member of a given population.
Description
This function expects a population, computes the fitness and returns the matrix of fitness values.
This function makes use ofparallelMapto allow parallelization of fitness evaluation. Keep in mind, that the return value is a 1xn matrix in case of single-objective optimization.
Usage
evaluateFitness(population, fitness.fun, task, control)
Arguments
population [list]
Population.
fitness.fun [function]
Fitness function.
task [ecr_optimization_task]
Optimization task.
control [ecr_control]
Control object containing all operators and further parameters. SeesetupECRControl andsetupEvolutionaryOperators.
Value matrix .
generateOffspring Creates offspring from a given mating pool of parents.
Description
Given and optimization state and a mating pool of individuals this function generates offspring individuals based on the parameters specified in the control object.
Usage
generateOffspring(opt.state, mating.pool, control)
24 getEvaluations Arguments
opt.state [ecr_opt_state]
Optimization state.
mating.pool [ecr_population]
Mating pool to select individuals from.
control [ecr_control]
Control object.
Value
ecr_population Generated offspring.
getAvailableEventNames
Receive a character vector of all valid event names.
Description
Receive a character vector of all valid event names.
Usage
getAvailableEventNames()
getEvaluations Get number of function evaluations.
Description
Determine the number of function evaluations needed by the EA.
Usage
getEvaluations(result)
Arguments
result [ecr_result]
ecr result object.
Value integer(1)
getGenerations 25
getGenerations Get number of generations.
Description
Determine the number of function evaluations needed by the EA.
Usage
getGenerations(result)
Arguments
result [ecr_result]
ecr result object.
Value integer(1)
getNextGeneration Performs survival selection.
Description
Given the current optimization state and the list of offspring individuals, the function selects the next generation. The selection type is based on the parameters given in the control object.
Usage
getNextGeneration(opt.state, offspring, control)
Arguments
opt.state [ecr_opt_state]
Optimization state.
offspring [ecr_population]
Generated offspring.
control [ecr_control]
Control object.
Value
ecr_population
26 getOperatorParameters
getOperatorName Get name of a operator.
Description
Returns the name of the passed operator.
Usage
getOperatorName(operator)
Arguments
operator [ecr_operator]
Operator object.
Value
character(1) Name of the operator.
getOperatorParameters Get the operator’s parameters.
Description
Return a named list of parameters the operator was initialized with.
Usage
getOperatorParameters(operator)
Arguments
operator [ecr_operator]
Operator object.
Value
list Named list of parameters.
getSupportedRepresentations 27
getSupportedRepresentations
Get supported representations.
Description
Returns the character vector of representation which the operator supports.
Usage
getSupportedRepresentations(operator)
Arguments
operator [ecr_operator]
Operator object.
Value
character Vector of representation types.
is.supported Check if ecr operator supports given representation.
Description
Check if the given operator supportds a certain representation, e.g., “float”.
Usage
is.supported(operator, representation)
Arguments
operator [ecr_operator]
Object of typeecr_operator.
representation [character(1)]
Representation as a string.
Value
logical(1) TRUE, if operator supports the representation type.
28 makeGenerator
isEcrOperator Check if given function is an ecr operator.
Description
Checks if the passed object is of typeecr_operator.
Usage
isEcrOperator(obj)
Arguments
obj [any]
Arbitrary R object to check.
Value logical(1)
makeGenerator Construct a generator.
Description
Helper function which constructs a generator, i. e., a function which generates an initial population.
Usage
makeGenerator(generator, name, description,
supported = getAvailableRepresentations(), params = list())
Arguments
generator [function]
Actual generator function. Should expect the size of the populationsize as a first and a ecr control objectcontrol as the second argument.
name [character(1)]
Name of the generator.
description [character(1)]
Short description of how the generator works.
supported [character]
Vector of strings/names of supported parameter representations, i.e., ’permuta- tion’, ’float’, ’binary’ or ’custom’.
params [list]
Named list of the parameters the generator has been initialized with. Default is the empty list.
makeMonitor 29 Value
ecr_generator Generator object.
makeMonitor Factory method for monitor objects.
Description
Monitor objects serve for monitoring the optimization process. Each monitor object expects the pa- rametersbefore, step and after, each being a function and expecting envir = parent.frame() as the only parameter. This way one can access all the variables used within the evolutionary cycle.
Usage
makeMonitor(before = NULL, step = NULL, after = NULL, ...)
Arguments
before [function]
Function called one time after initialization of the EA.
step [function]
Function applied after each iteration of the algorithm.
after [function]
Function applied after the EA terminated.
... [any]
Not used.
Value
ecr_monitor Monitor object.
Examples
# We want to find the minimum of the function f(x) = x sin(2x) on the intervall
# [0, 2pi]. We optimize f here with a simple (10 + 10)
# evolutionary strategy. We overwrite the default console monitor
# (see function setupConsoleMonitor) with an enhanced console monitor :-) obj.fn = makeSingleObjectiveFunction(
name = "My obj. function", fn = function(x) x * sin(2 * x),
par.set = makeParamSet(makeNumericParam("x", lower = 0, upper = 2 * pi)) )
# Now we define our enhanced monitoring function
# Monitor functions expect the opt.state (optimization state) and ... (not used
# until now). This way we can access all the variables saved there.
monitorStep = function(opt.state, ...) {
30 makeMutator iter = opt.state$iter
best.fitness = opt.state$best.value if (iter == 1L) {
# manupulate opt.state
opt.state$first.best = best.fitness }first.best.fitness = opt.state$first.best
cat(sprintf("Best objective value in iteration %i is %.6f (overall absolute improvement is: %.6f)\n",
iter, best.fitness, first.best.fitness - best.fitness) )
}
myFancyConsoleMonitor = makeMonitor(
before = function(opt.state, ...) { catf("I am starting now buddy!") },step = monitorStep,
after = function(opt.state, ...) { catf("Finished!")
} )
# We want to solve this with a (10 + 10) evolutionary strategy based on
# the floating point representation of the input vectors with the default
# operators: intermediate recombinator and Gauss mutation ctrl = setupECRControl(
n.population = 10L, n.offspring = 10L,
survival.strategy = "plus", representation = "float",
stopping.conditions = setupTerminators(max.iter = 30L), monitor = myFancyConsoleMonitor
)
ctrl = setupEvolutionaryOperators(ctrl) res = doTheEvolution(obj.fn, ctrl) print(res)
makeMutator Construct a mutation operator.
Description
Helper function which constructs a mutator, i. e., a mutation operator.
Usage
makeMutator(mutator, name, description,
supported = getAvailableRepresentations(), params = list())
makeOperator 31 Arguments
mutator [function]
Actual mutation operator.
name [character(1)]
Name of the mutator.
description [character(1)]
Short description of how the mutator works.
supported [character]
Vector of strings/names of supported parameter representations. For example
’permutation’, ’float’, ’binary’.
params [list]
Named list of the parameters the operator has been initialized with. Default is the empty list.
Value
ecr_mutator Mutator object.
makeOperator Construct evolutionary operator.
Description
Helper function which constructs an evolutionary operator.
Usage
makeOperator(operator, name, description = NULL,
supported = getAvailableRepresentations(), params = list())
Arguments
operator [function]
Actual mutation operator.
name [character(1)]
Name of the operator.
description [character(1)]
Short description of how the mutator works. Default isNULL which means no description at all.
supported [character]
Vector of names of supported parameter representations. Possible choices: “per- mutation”, “float”, “binary” or “custom”.
params [list]
Named list of the parameters the operator has been initialized with. Default is the empty list.
32 makeOptimizationTask Value
ecr_operator Operator object.
Note
In general you will not need this function, but rather one of its deriviatives likemakeMutatoror makeSelector.
makeOptimizationTask Creates an optimization task.
Description
An optimization task consists of the fitness/objective function, the number of objectives, the “direc- tion” of optimization, i.e., which objectives should be minimized/maximized and the names of the objectives.
Usage
makeOptimizationTask(fun, n.objectives = NULL, minimize = NULL, objective.names = NULL)
Arguments
fun [function | smoof_function]
Fitness/objective function.
n.objectives [integer(1)]
Number of objectives. This must be a positive integer value unlessfun is of type smoof_function.
minimize [logical]
A logical vector indicating which objectives to minimize/maximize. By default all objectives are assumed to be minimized.
objective.names
[character]
Names for the objectuves. Default isNULL. In this case the names are set to y1, ..., yn with n equal ton.objectives and simply y in the single-objective case.
Value
ecr_optimization_task
makePopulation 33
makePopulation Generate a population.
Description
Wrap individuals in asetOfIndividuals. This function is of particular interest when one wants to write population generators for non-standard representations.
Usage
makePopulation(individuals, fitness = NULL)
Arguments
individuals [matrix]
List of individuals.
fitness [matrix]
Matrix with one row of fitness values for the individuals. Default isNULL.
Value
setOfIndividuals
makeRecombinator Construct a recombination operator.
Description
Helper function which constructs a recombinator, i. e., a recombination operator.
Usage
makeRecombinator(recombinator, name, description,
supported = getAvailableRepresentations(), params = list(), n.parents = 2L, n.children = NULL)
Arguments
recombinator [function]
Actual mutation operator.
name [character(1)]
Name of the recombinator.
description [character(1)]
Short description of how the recombinator works.
34 makeSelector supported [character]
Vector of strings/names of supported parameter representations. For example
’permutation’, ’float’, ’binary’.
params [list]
Named list of the parameters the operator has been initialized with. Default is the empty list.
n.parents [integer(1)]
Number of parents supported.
n.children [integer(1)]
How many children does the recombinator produce? Default is1.
Value
ecr_recombinator Recombinator object.
Note
If a recombinator returns more than one child, themultiple.children parameter needs to be TRUE, which is the default. In case of multiple children produced these have to be placed within a list.
makeSelector Construct a selection operator.
Description
Helper function which defines a selector method, i. e., an operator which takes the population and returns a part of it for mating or survival.
Usage
makeSelector(selector, name, description,
supported = getAvailableRepresentations(), supported.objectives, supported.opt.direction = "minimize")
Arguments
selector [function]
Actual selection operator.
name [character(1)]
Name of the selector.
description [character(1)]
Short description of how the selector works.
supported [character]
Vector of strings/names of supported parameter representations. For example
’permutation’, ’float’, ’binary’.
makeTerminator 35 supported.objectives
[character]
At least one of “single-objective” or “multi-objective”.
supported.opt.direction
[character(1-2)]
Does the selector work for maximization tasks xor minimization tasks or both?
Default is “minimize”, which means that the selector selects in favour of low fitness values.
Value
ecr_selector Selector object.
makeTerminator Generate stopping condition.
Description
Wrap a function within a stopping condition object.
Usage
makeTerminator(condition.fun, name, message)
Arguments
condition.fun [function]
Function which takes an environmentOptPathas its only parameter and return a single logical.
name [character(1)]
Identifier for the stopping condition.
message [character(1)]
Message which should be stored in the termination object, if the stopping con- dition is met.
Value
ecr_terminator
36 nsga2
mergePopulations Merge populations.
Description
Make one population out of multiple.
Usage
mergePopulations(...)
Arguments
... [list]
List of objects of typesetOfIndividuals.
Value
setOfIndividuals
nsga2 Implementation of the NSGA-II EMOA algorithm by Deb.
Description
The NSGA-II merges the current population and the generated offspring and reduces it by means of the following procedure: It first applies the non dominated sorting algorithm to obtain the nondom- inated fronts. Starting with the first front, it fills the new population until the i-th front does not fit.
It then applies the secondary crowding distance criterion to select the missing individuals from the i-th front.
Usage
nsga2(task, n.population = 100L, n.offspring = n.population,
parent.selector = setupSimpleSelector(), mutator = setupGaussMutator(), recombinator = setupCrossoverRecombinator(), max.iter = 100L,
max.evals = NULL, max.time = NULL, ...)
Arguments
task [ecr_optimization_task]
Optimization task. If asmoof_function is passed it is automatically converted into a task.
n.population [integer(1)]
Population size. Default is100.
onePlusOneGA 37 n.offspring [integer(1)]
Offspring size, i.e., number of individuals generated by variation operators in each iteration. Default isn.population.
parent.selector
[ecr_selector]
Selection operator which implements a procedure to copy individuals from a given population to the mating pool, i. e., allow them to become parents.
mutator [ecr_mutator]
Mutation operator of typeecr_mutator.
recombinator [ecr_recombinator]
Recombination operator of typeecr_recombinator.
max.iter [integer(1)]
Maximal number of iterations. Default ist100L.
max.evals [integer(1)]
Maximal number of iterations/generations. Default isInf.
max.time [integer(1)]
Time budget in seconds. Default istInf.
... [any]
Further arguments passed tosetupECRControl. Value
ecr_nsga2_result, ecr_multi_objective_result
Note
This is a pure R implementation of the NSGA-II algorithm. It hides the regular ecr interface and offers a more R like interface while still being quite adaptable.
References
Deb, K., Pratap, A., and Agarwal, S. A Fast and Elitist Multiobjective Genetic Algorithm: NSGA- II. IEEE Transactions on Evolutionary Computation, 6 (8) (2002), 182-197.
onePlusOneGA Simple (1 + 1) Genetic Algorithm.
Description
The simplest evolutionary algorithm one can imagine, namely the (1+1) EA/GA. Maintains a pop- ulation of a single individual x and uses just bitplip mutation to generate a child y (obviously no recombination takes place), i.e., each gene of x is flipped with probabilityp independently. The best individual survives. This algorithm is of particular interest in the theory of evolutionary algorithms and its performance is well understood for different function families. A lot of interesting results exist.
38 OptState Usage
onePlusOneGA(task, p = NULL, max.iter = NULL, max.evals = NULL, max.time = NULL, ...)
Arguments
task [ecr_optimization_task]
Optimization task. If asmoof_function is passed it is automatically converted into a task.
p [numeric(1)]
Mutation probability for bitplip mutation. Default is 1/n where n is the length of the gene.
max.iter [integer(1)]
Maximal number of iterations. Default ist100L.
max.evals [integer(1)]
Maximal number of iterations/generations. Default isInf.
max.time [integer(1)]
Time budget in seconds. Default istInf.
... [any]
Further arguments passed tosetupECRControl. Value
ecr_single_objective_result
Note
This helper function hides the regular ecr interface and offers a more R like interface to a simple evolutionary algorithm which works on binary valued vectors.
OptState Optimization state.
Description
The optimization state of classecr_opt_state is a S3 object containing all the information about the current state of the optimization process. It is initialized uopn the generation of the initial population right before the evolutionary loop is started and is updated after after a new generation was created, i.~e., after each iteration of the EA loop. Internally the object is an R environment which allows for manipulation in place. By default the state object contains the following slots:
iter The current iteration/generation.
time.created Time the object was initialized.
time.passed Time passed since creation.
task The optimization task (seemakeOptimizationTask).
OptStateGetter 39 pas.set The parameter set of the objective function at hand (seeParamSet).
n.evals Number of performed objective function evaluations.
control Theecr_control control object.
population The current population.
best.param/best.value Best parameter and its value (only in single-objective case).
The final optimization state object is returned by the EA (seeecr_result).
OptStateGetter Optimization state getter functions.
Description
TheOptStateis generated internally bydoTheEvolution, but it is exposed to the user in some cases. E.g., self-defined actions or stopping conditions get the currentOptState passed as an argument. The following collection of simple getter functions helps to access the properties of the optimization state.
Usage
getOptStateCurrentIter(opt.state) getOptStateTask(opt.state)
getOptStateParamSet(opt.state)
getOptStateCurrentEvaluations(opt.state) getOptStateControl(opt.state)
getOptStateBestIndividual(opt.state) getOptStatePopulation(opt.state) getOptStateFitness(opt.state) getOptStateTimePassed(opt.state) getOptStateOptPath(opt.state)
Arguments
opt.state [OptState] Optimization state.
Value
any Type depends on the property.
40 registerAction
print.ecr_control Print ecr control object.
Description
Print ecr control object.
Usage
## S3 method for class 'ecr_control' print(x, ...)
Arguments
x [ecr_control]
Control object.
... [any]
Not used.
registerAction Register an action.
Description
Register an action for a specific event in the EA circle. SeegetAvailableEventNamesfor a list of available event names.
Usage
registerAction(control, event.name, fun) Arguments
control [ecr_control]
Control object.
event.name [character(1)]
Name of the event.
fun [function()]
Function with argumentsopt.state and ....
Value
ecr_control Updated control object.
See Also
getAvailableEventNames
rescalePoints 41
rescalePoints Rescaling of points.
Description
Rescales a cloud of points so that all the point are located within the bounds given bylower and upper. If both parameters are missing the minimal/maximal values per dimension are extracted.
Usage
rescalePoints(x, lower = NULL, upper = NULL)
Arguments
x [matrix]
Matrix of points.
lower [numeric(1)]
Lower bound of the new bounding box.
upper [numeric(1)]
Upper bound of the new bounding box.
Value matrix
selectForMating Generate mating pool.
Description
Given the current optimization state this function selects a subset of individuals which form the mating pool, i.e., the set of possible parents for later recombination.
Usage
selectForMating(opt.state, control)
Arguments
opt.state [ecr_opt_state]
Optimization state.
control [ecr_control]
ECR control object generated viasetupECRControl.
42 selectForSurvival Value
ecr_population
Note
Basically this is a wrapper for the call to the parent selector of the control object which occasionally transforms the fitness values (e.g., if maximzation should be performed, but the selection operator actualy minimizes).
selectForSurvival Generate mating pool.
Description
Given the current optimization state this function selects a subset of individuals which should sur- vive and form the next generation.
Usage
selectForSurvival(opt.state, population, control, n.select = control$n.population)
Arguments
opt.state [ecr_opt_state]
Optimization state.
population [list]
Current population.
control [ecr_control]
ECR control object generated viasetupECRControl. n.select [integer(1L)]
Number of offspring to select for survival.
Value
ecr_population
Note
Basically this is a wrapper for the call to the parent selector of the control object which occasionally transforms the fitness values (e.g., if maximzation should be performed, but the selection operator actualy minimizes).
setupBinaryGenerator 43
setupBinaryGenerator Generates a generator object for the initial population.
Description
The generated operator samples uniformally distributed points in the design space of the target function taking care not to violate box constraints.
Usage
setupBinaryGenerator()
Value ecr_generator
setupBitFlipMutator Generator of the Bitplip mutation operator.
Description
This operator works only on binary representation and flips each bit with a given probability p ∈ (0, 1). Usually it is recommended to set p =n1 where n is the number of bits in the representation.
Usage
setupBitFlipMutator(p = 0.1)
Arguments
p [numeric(1)]
Probability to flip a single bit. Default is0.1.
Value ecr_mutator
See Also
Other mutators:setupGaussMutator,setupInsertionMutator,setupPolynomialMutator,setupScrambleMutator, setupSwapMutator,setupUniformMutator
44 setupConsoleMonitor
setupCloseToOptimumTerminator
Stopping condition: close to optimum.
Description
Stop the EA if the best fitness value is close to the given optimum.
Usage
setupCloseToOptimumTerminator(eps = 1e-04, opt = NULL)
Arguments
eps [numeric(1)]
Maximal deviation from optimal value.
opt [numeric(1)]
Optimal value.
Value function
See Also
Other stopping conditions:setupMaximumEvaluationsTerminator,setupMaximumIterationsTerminator, setupMaximumTimeTerminator
setupConsoleMonitor Simple stdout monitoring function.
Description
This is the default monitoring function used by ecr. It simply outputs the iteration as well as mini- mal, mean and maximal target values from the current population.
Usage
setupConsoleMonitor(show.info.stepsize = 5L, num.format = "%g")
Arguments
show.info.stepsize
[integer(1)]
Adjust the stepsize of iterations with informative messages.
num.format [character(1)]
Number format for output of numeric parameters. See the details section of the manual forsprintffor details. Default is “%g”.
setupCrossoverRecombinator 45 Value
ecr_monitor
setupCrossoverRecombinator
Generator of the one-point crossover recombination operator.
Description
The one-point crossover recombinator is defined for float and binary representations. Given two real-valued/binary vectors of length n, the selector samples a random position i between 1 and n-1.
In the next step it creates two children. The first part of the first child contains of the subvector from position 1 to position i of the first parent, the second part from position i+1 to n is taken from the second parent. The second child is build analogously. If the parents are list of real-valued/binary vectors, the procedure described above is applied to each element of the list.
Usage
setupCrossoverRecombinator(p = 1)
Arguments
p [numeric(1)]
Cross over probability to form an offspring. Default is1.
Value
ecr_recombinator
See Also
Other recombinators:setupIntermediateRecombinator,setupNullRecombinator,setupOXRecombinator, setupPMXRecombinator,setupSBXRecombinator
setupDominatedHypervolumeSelector
Dominated hypervolume selector.
Description
Performs nondominated sorting and drops the individual from the last front with minimal hypervol- ume contribution.
Usage
setupDominatedHypervolumeSelector()
46 setupECRControl Value
setOfIndividuals
See Also
Other selectors:setupGreedySelector,setupNondomSelector,setupRouletteWheelSelector, setupSimpleSelector,setupTournamentSelector
setupECRControl Generates control object.
Description
The ecr package offers a framework for evolutionary computing and therefore offers a lot of cus- tomization options. The control object is a simple wrapper for all these options and sets convenient defaults.
Usage
setupECRControl(n.population, n.offspring,
n.mating.pool = floor(n.population/2), representation, survival.strategy = "plus", n.elite = 0L,
monitor = setupConsoleMonitor(), stopping.conditions = list(),
logger = NULL, custom.constants = list(), vectorized.evaluation = FALSE)
Arguments
n.population [integer(1)]
Number of individuals in the population.
n.offspring [integer(1)]
Number of individuals generated in each generation.
n.mating.pool [integer(1)]
Number of individuals which can potentially participate in the generation of offspring. Default is half of the population size.
representation [character(1)]
Genotype representation of the parameters. Available are “binary”, “float”, “per- mutation” and “custom”.
survival.strategy
[character(1)]
Determines the survival strategy used by the EA. Possible are “plus” for a clas- sical (mu + lambda) strategy and “comma” for (mu, lambda). Default is “plus”.
n.elite [integer(1)]
Number of fittest individuals of the current generation that shall be copied to the next generation without changing. Keep in mind, that the algorithm does not care about this option if thesurvival.strategy is set to ’plus’. Default is 0.
setupEvolutionaryOperators 47 monitor [function]
Monitoring function. Default isNULL, i.e. no monitoring.
stopping.conditions [list]
List of functions of type ecr_terminator. At least one stopping condition needs to be passed. Default is the empty list.
logger [function]
Monitoring object used to log stuff. Default isNULL which means no logging at all. SeesetupOptPathLoggingMonitorfor ecr’s build-in logger.
custom.constants [list]
Additional constants which should be available to all generators and operators.
Defaults to empty list.
vectorized.evaluation [logical(1L)]
Is the fitness/objective function vectorized? I.e., does the fitness function accept a list? This allows for faster execution or parallelization by hand. IfTRUE the following destinction on the type of the objective function is made:
Issmoof_function If the objective function is of type smoof_function from package smoof and the smoof function is vectorized, the population - which is a list internally - is reduced to a matrix and passed to the smoof function (vectorization in smoof is allowed for continuous functions only).
Is not asmoof_function In this case the individuals of the population are passed entirely as a list to the objective function.
Default isFALSE.
Value
S3 object of typeecr_control.
setupEvolutionaryOperators
Enhance control object with evolutionary operators.
Description
Define the toolbox of all the evolutionary operators you wish to operate on your problem.
Usage
setupEvolutionaryOperators(control,
parent.selector = getDefaultEvolutionaryOperators(control$representation,
"parent.selector"),
survival.selector = getDefaultEvolutionaryOperators(control$representation,
"survival.selector"),
48 setupGaussMutator generator = getDefaultEvolutionaryOperators(control$representation,
"generator"),
mutator = getDefaultEvolutionaryOperators(control$representation,
"mutator"),
recombinator = getDefaultEvolutionaryOperators(control$representation,
"recombinator"))
Arguments
control [ecr_control]
ECR control object generated viasetupECRControl. parent.selector
[ecr_selector]
Selection operator which implements a procedure to copy individuals from a given population to the mating pool, i. e., allow them to become parents.
survival.selector
[ecr_selector]
Selection operator which implements a procedurce to extract individuals from a given set, which should survive and set up the next generation.
generator [ecr_generator]
Generator operator of typeecr_generator for the generation of the initial pop- ulation.
mutator [ecr_mutator]
Mutation operator of typeecr_mutator.
recombinator [ecr_recombinator]
Recombination operator of typeecr_recombinator.
Value
ecr_control Modified control object.
Note
Keep in mind, that all of the provided operators need to be compatible with the “representation”
stored in thecontrol object.
setupGaussMutator Generator of the Gaussian mutation operator.
Description
Default Gaussian mutation operator known from Evolutionary Algorithms. This mutator is applica- ble only forrepresentation="float". Given an individual x ∈ Rlthis mutator adds a Gaussian distributed random value to each component of x, i.~e., ˜xi= xi+ σN (0, 1).
setupGreedySelector 49 Usage
setupGaussMutator(p = 1L, sdev = 0.05)
Arguments
p [numeric(1)]
Probability of mutation for the gauss mutation operator.
sdev [numeric(1)
Standard deviance of the Gauss mutation, i. e., the mutation strength.
Value ecr_mutator
See Also
Other mutators: setupBitFlipMutator,setupInsertionMutator, setupPolynomialMutator, setupScrambleMutator,setupSwapMutator,setupUniformMutator
setupGreedySelector Simple “greedy” selector.
Description
Sorts the individuals according to their fitness value in increasing order and selects the best ones.
Usage
setupGreedySelector()
Value
setOfIndividuals
See Also
Other selectors:setupDominatedHypervolumeSelector,setupNondomSelector,setupRouletteWheelSelector, setupSimpleSelector,setupTournamentSelector
50 setupIntermediateRecombinator
setupInsertionMutator Generator for the Insertion mutation operator.
Description
The Insertion mutation operator selects a position random and inserts it at a random position.
Usage
setupInsertionMutator()
Value ecr_mutator
See Also
Other mutators:setupBitFlipMutator,setupGaussMutator,setupPolynomialMutator,setupScrambleMutator, setupSwapMutator,setupUniformMutator
setupIntermediateRecombinator
Generator of the indermediate recombination operator.
Description
Intermediate recombination computes the component-wise mean value of thek given parents. It is applicable only for float representation.
Usage
setupIntermediateRecombinator(k = 2L)
Arguments
k [integer(1)]
Number of parents required for mating. Default is2.
Value
ecr_recombinator
See Also
Other recombinators:setupCrossoverRecombinator,setupNullRecombinator,setupOXRecombinator, setupPMXRecombinator,setupSBXRecombinator
setupInversionMutator 51
setupInversionMutator Generator for the Inversion mutation operator.
Description
The Inversion mutation operator selects two positions within the chromosome at random and inverts this sub-permutation.
Usage
setupInversionMutator()
Value ecr_mutator
setupMaximumEvaluationsTerminator
Stopping condition: maximum number of function evaluations.
Description
Stop the EA after at mostmax.evals evaluations of the fitness function.
Usage
setupMaximumEvaluationsTerminator(max.evals = NULL)
Arguments
max.evals [integer(1)]
Maximal number of function evaluations. Default istInf.
Value function
See Also
Other stopping conditions:setupCloseToOptimumTerminator,setupMaximumIterationsTerminator, setupMaximumTimeTerminator