The most flexible way to setup evolutionary algorithms with ecr is by
explicitely writing the evolutionary loop utilizing various ecr utlity functions.
However, in everyday life R users frequently need to optimize a single-objective R function.
The ecr
function thus provides a more R like interface for single
objective optimization similar to the interface of the optim
function.
ecr(
fitness.fun,
minimize = NULL,
n.objectives = NULL,
n.dim = NULL,
lower = NULL,
upper = NULL,
n.bits,
representation,
mu,
lambda,
perm = NULL,
p.recomb = 0.7,
p.mut = 0.3,
survival.strategy = "plus",
n.elite = 0L,
log.stats = list(fitness = list("min", "mean", "max")),
log.pop = FALSE,
monitor = NULL,
initial.solutions = NULL,
parent.selector = NULL,
survival.selector = NULL,
mutator = NULL,
recombinator = NULL,
terminators = list(stopOnIters(100L)),
...
)
[ecr_result
]
[function
]
The fitness function.
[logical(n.objectives)
]
Logical vector with ith entry TRUE
if the ith objective of fitness.fun
shall be minimized. If a single logical is passed, it is assumed to be valid
for each objective.
[integer(1)
]
Number of objectives of obj.fun
.
Optional if obj.fun
is a benchmark function from package smoof.
[integer(1)
]
Dimension of the decision space.
[numeric
]
Vector of minimal values for each parameter of the decision space in case
of float or permutation encoding.
Optional if obj.fun
is a benchmark function from package smoof.
[numeric
]
Vector of maximal values for each parameter of the decision space in case
of float or permutation encoding.
Optional if obj.fun
is a benchmark function from package smoof.
[integer(1)
]
Number of bits to use for binary representation.
[character(1)
]
Genotype representation of the parameters. Available are “binary”,
“float”, “permutation” and “custom”.
[integer(1)
]
Number of individuals in the population.
[integer(1)
]
Number of individuals generated in each generation.
[integer(1)
| vector
]
Either a single integer number. In this case the set is assumed to be 1:perm
.
Alternatively, a set, i.e., a vector of elements can be passed which should form each
individual.
[numeric(1)
]
Probability of two parents to perform crossover.
Default is 0.7.
[numeric(1)
]
The probability that the mutation operator will be applied to a child.
Refers only to the application of the mutation operator, not to the
probability of mutating individual genes of the respective child.
Default is 0.1.
[character(1)
]
Determines the survival strategy used by the EA. Possible are “plus” for
a classical (mu + lambda) strategy and “comma” for (mu, lambda).
Default is “plus”.
[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 the survival.strategy
is set to 'plus'.
Default is 0.
[list
]
(Named) list of scalar functions to compute statistics on the fitness values
in each generation. See initLogger
for more information.
Default is to log fitness minimum, mean and maximum values.
[logical(1)
]
Shall the entire population be saved in each generation?
Default is FALSE
.
[function
]
Monitoring function.
Default is NULL
, i.e. no monitoring.
[list
]
List of individuals which should be placed in the initial population.
If the number of passed individuals
is lower than mu
, the population will be filled up
by individuals generated by the corresponding generator.
Default is NULL
, i.e., the entire population is generated by the
population generator.
[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.
[ecr_selector
]
Selection operator which implements a procedurce to extract individuals from
a given set, which should survive and set up the next generation.
[ecr_mutator
]
Mutation operator of type ecr_mutator
.
[ecr_recombinator
]
Recombination operator of type ecr_recombinator
.
[list
]
List of stopping conditions of type “ecr_terminator”.
Default is to stop after 100 iterations.
[any]
Further arguments passed down to fitness.fun
.
fn = function(x) {
sum(x^2)
}
lower = c(-5, -5); upper = c(5, 5)
res = ecr(fn, n.dim = 2L, n.objectives = 1L, lower = lower, upper = lower,
representation = "float", mu = 20L, lambda = 10L,
mutator = setup(mutGauss, lower = lower, upper = upper))
Run the code above in your browser using DataLab