setup: Set up parameters for evolutionary operator.

View source: R/setup.R

setupR Documentation

Set up parameters for evolutionary operator.

Description

This function builds a simple wrapper around an evolutionary operator, i.e., mutator, recombinator or selector and defines its parameters. The result is a function that does not longer depend on the parameters. E.g., fun = setup(mutBitflip, p = 0.3) initializes a bitflip mutator with mutation probability 0.3. Thus, the following calls have the same behaviour: fun(c(1, 0, 0)) and mutBitflip(fun(c(1, 0, 0), p = 0.3). Basically, this type of preinitialization is only neccessary if operators with additional parameters shall be initialized in order to use the black-box ecr.

Usage

setup(operator, ...)

Arguments

operator

[ecr_operator]
Evolutionary operator.

...

[any]
Furhter parameters for operator.

Value

[function] Wrapper evolutionary operator with parameters x and ....

Examples

# initialize bitflip mutator with p = 0.3
bf = setup(mutBitflip, p = 0.3)
# sample binary string
x = sample(c(0, 1), 100, replace = TRUE)

set.seed(1)
# apply preinitialized function
print(bf(x))

set.seed(1)
# apply raw function
print(mutBitflip(x, p = 0.3))

# overwrite preinitialized values with mutate
ctrl = initECRControl(fitness.fun = function(x) sum(x), n.objectives = 1L)
# here we define a mutation probability of 0.3
ctrl = registerECROperator(ctrl, "mutate", setup(mutBitflip, p = 0.3))
# here we overwrite with 1, i.e., each bit is flipped
print(x)
print(mutate(ctrl, list(x), p.mut = 1, p = 1)[[1]])

ecr documentation built on March 31, 2023, 10:07 p.m.