ecr: Interface to 'ecr' similar to the 'optim' function.

Description Usage Arguments Value Note See Also Examples

Description

The most flexible way to setup evolutionary algorithms with ecr is by explicitely generating a task and a control object and passing both to doTheEvolution. Although this approach is highly flexible and very readable it requires quite a lot of code. 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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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”, “permutation” 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.

survival.strategy

[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”.

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 the survival.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. If TRUE the following destinction on the type of the objective function is made:

Is smoof_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 a smoof_function

In this case the individuals of the population are passed entirely as a list to the objective function.

Default is FALSE.

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 is NULL which means no logging at all. See setupOptPathLoggingMonitor for ecr's build-in logger.

monitor

[function]
Monitoring function. Default is NULL, i.e. no monitoring.

max.iter

[integer(1)]
Maximal number of iterations. Default ist 100L.

max.evals

[integer(1)]
Maximal number of iterations/generations. Default is Inf.

max.time

[integer(1)]
Time budget in seconds. Default ist Inf.

more.args

[list]
Additional arguments passed to objective function.

initial.population

[list]
List of individuals which should be placed in the initial population. The function will stop with an error message if the number of passed individuals is larger than control$n.population. If the number of passed individuals is lower than control$n.population, 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.

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 type ecr_generator for the generation of the initial population.

mutator

[ecr_mutator]
Mutation operator of type ecr_mutator.

recombinator

[ecr_recombinator]
Recombination operator of type ecr_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 with doTheEvolution directly.

See Also

setupECRControl for building the control object, makeOptimizationTask to define an optimization problem and doTheEvolution for the main working horse of ecr.

Examples

1
2
3
4
5
6
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)

jakobbossek/ecr documentation built on May 18, 2019, 9:09 a.m.