Learn R Programming

ecr (version 2.1.1)

ecr: Interface to ecr similar to the optim function.

Description

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.

Usage

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)),
  ...
)

Value

[ecr_result]

Arguments

fitness.fun

[function]
The fitness function.

minimize

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

n.objectives

[integer(1)]
Number of objectives of obj.fun. Optional if obj.fun is a benchmark function from package smoof.

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. Optional if obj.fun is a benchmark function from package smoof.

upper

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

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

mu

[integer(1)]
Number of individuals in the population.

lambda

[integer(1)]
Number of individuals generated in each generation.

perm

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

p.recomb

[numeric(1)]
Probability of two parents to perform crossover. Default is 0.7.

p.mut

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

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.

log.stats

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

log.pop

[logical(1)]
Shall the entire population be saved in each generation? Default is FALSE.

monitor

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

initial.solutions

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

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.

mutator

[ecr_mutator]
Mutation operator of type ecr_mutator.

recombinator

[ecr_recombinator]
Recombination operator of type ecr_recombinator.

terminators

[list]
List of stopping conditions of type “ecr_terminator”. Default is to stop after 100 iterations.

...

[any]
Further arguments passed down to fitness.fun.

Examples

Run this code
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