gena.crossover {gena} | R Documentation |
Crossover
Description
Crossover method (algorithm) to be used in the genetic algorithm.
Usage
gena.crossover(
parents,
fitness = NULL,
prob = 0.8,
method = "local",
par = NULL,
iter = NULL
)
Arguments
parents |
numeric matrix which rows are parents i.e. vectors of parameters values. |
fitness |
numeric vector which |
prob |
probability of crossover. |
method |
crossover method to be used for making children. |
par |
additional parameters to be passed depending on the |
iter |
iteration number of the genetic algorithm. |
Details
Denote parents
by which
i
-th row
parents[i, ]
is a chromosome i.e. the vector of
parameter values of the function being optimized
that is
provided via
fn
argument of gena
.
The elements of chromosome are genes
representing parameters values.
Crossover algorithm determines the way parents produce children.
During crossover each of randomly selected pairs of parents
,
produce two children
,
,
where
is odd. Each pair of parents is selected with
probability
prob
. If pair of parents have not been selected
for crossover then corresponding children and parents are coincide i.e.
and
.
Argument method
determines particular crossover algorithm to
be applied. Denote by the vector of parameters used by the
algorithm. Note that
corresponds to
par
.
If method = "split"
then each gene of the first child will
be equiprobably picked from the first or from the second parent. So
may be equal to
or
with equal probability. The second
child is the reversal of the first one in a sense that if the first child
gets particular gene of the first (second) parent then the second child gets
this gene from the first (second) parent i.e. if
then
; if
then
.
If method = "arithmetic"
then:
where is
par[1]
. By default par[1] = 0.5
.
If method = "local"
then the procedure is the same as
for "arithmetic" method but is a uniform random
value between 0 and 1.
If method = "flat"
then is a uniform
random number between
and
.
Similarly for the second child
.
For more information on crossover algorithms please see Kora, Yadlapalli (2017).
Value
The function returns a matrix which rows are children.
References
P. Kora, P. Yadlapalli. (2017). Crossover Operators in Genetic Algorithms: A Review. International Journal of Computer Applications, 162 (10), 34-36, <doi:10.5120/ijca2017913370>.
Examples
# Randomly initialize the parents
set.seed(123)
parents.n <- 10
parents <- gena.population(pop.n = parents.n,
lower = c(-5, -5),
upper = c(5, 5))
# Perform the crossover
children <- gena.crossover(parents = parents,
prob = 0.6,
method = "local")
print(children)