| Title: | Port of the Sheffield Genetic Algorithm Toolbox for 'MATLAB' |
|---|---|
| Description: | Provides the functions of the Genetic Algorithm Toolbox for 'MATLAB' developed at the University of Sheffield (Chipperfield et al. 1994, <https://github.com/UoS-CODeM/GA-Toolbox>), rewritten in R. It includes operators for creating binary, integer and real-valued populations, rank-based and linear fitness assignment, roulette wheel and stochastic universal sampling selection, single-point, multi-point, shuffle and reduced surrogate crossover, discrete, intermediate and line recombination, discrete and breeder genetic algorithm mutation, reinsertion of offspring, and migration between subpopulations. |
| Authors: | Liang Zhao [aut, cre, trl] (R implementation), Andrew Chipperfield [aut, cph] (Author of the original 'MATLAB' toolbox), Peter Fleming [aut, cph] (Author of the original 'MATLAB' toolbox), Hartmut Pohlheim [aut, cph] (Author of the original 'MATLAB' toolbox), Carlos Fonseca [aut, cph] (Author of the original 'MATLAB' toolbox), Alex Shenfield [ctb] (Tested the original 'MATLAB' toolbox), The University of Sheffield [cph] (Copyright holder of the original 'MATLAB' toolbox) |
| Maintainer: | Liang Zhao <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.2.0 |
| Built: | 2026-11-14 07:03:00 UTC |
| Source: | https://github.com/cran/gatbxr |
This function decodes binary chromosomes into vectors of reals. The chromosomes are seen as the concatenation of binary strings of given length, and decoded into real numbers in a specified interval using either standard binary or Gray decoding.
bs2rv(Chrom, FieldD)bs2rv(Chrom, FieldD)
Chrom |
matrix containing the chromosomes of the current population. Each row corresponds to one individual's concatenated binary string representation. Leftmost bits are the most significant bits and rightmost are the least significant bits. |
FieldD |
a list describing how to decode each substring in the chromosome. It must contain the following 7 elements:
Except for |
a real matrix containing the population phenotypes. Each row corresponds to one individual and each column to one variable.
The original 'MATLAB' implementation of bs2rv was written by Carlos Fonseca and updated by Andrew Chipperfield. The R implementation was written by Liang Zhao.
## Create a population of 40 chromosomes of length 400 Chrom = crtbp(Nind = 40, Lind = 400)$Chrom ## Convert to reals in the range [-512, 512] with a precision of 20 ## (20 bits represent one real number) on an arithmetic scale by binary decoding. Phen = bs2rv(Chrom = Chrom, FieldD = list(prec=20,lb=-512,ub=512,code="binary",scale="arith",lbin=TRUE,ubin=TRUE)) ## Two variables with different bounds, decoded with Gray code Chrom = crtbp(5, 16)$Chrom Phen = bs2rv(Chrom, FieldD = list(prec=8,lb=c(-1,10),ub=c(1,100),code="gray", scale=c("arith","log"),lbin=TRUE,ubin=TRUE))## Create a population of 40 chromosomes of length 400 Chrom = crtbp(Nind = 40, Lind = 400)$Chrom ## Convert to reals in the range [-512, 512] with a precision of 20 ## (20 bits represent one real number) on an arithmetic scale by binary decoding. Phen = bs2rv(Chrom = Chrom, FieldD = list(prec=20,lb=-512,ub=512,code="binary",scale="arith",lbin=TRUE,ubin=TRUE)) ## Two variables with different bounds, decoded with Gray code Chrom = crtbp(5, 16)$Chrom Phen = bs2rv(Chrom, FieldD = list(prec=8,lb=c(-1,10),ub=c(1,100),code="gray", scale=c("arith","log"),lbin=TRUE,ubin=TRUE))
This function creates a vector containing the base of the loci in a chromosome.
crtbase(Lind, Base = NULL)crtbase(Lind, Base = NULL)
Lind |
a number or vector containing the lengths
of the alleles. |
Base |
a number or vector containing the base of the loci contained in the Alleles. Default is set to binary representation. |
a vector whose elements correspond to the base of the loci of the associated chromosome structure.
The original 'MATLAB' implementation of crtbase was written by Andrew Chipperfield. The R implementation was written by Liang Zhao.
## 10 binary loci Base = crtbase(10) ## 3 loci of base 8 followed by 2 loci of base 4 Base = crtbase(c(3,2), c(8,4))## 10 binary loci Base = crtbase(10) ## 3 loci of base 8 followed by 2 loci of base 4 Base = crtbase(c(3,2), c(8,4))
This function creates a binary population of given size and structure.
crtbp(Nind, Lind = NULL, Base = NULL)crtbp(Nind, Lind = NULL, Base = NULL)
Nind |
either a number containing the number of individuals in the new population or a vector of length two containing the number of individuals and their length. |
Lind |
an optional number containing the length of the individual chromosomes, or a vector containing the base of each locus of the chromosomes. |
Base |
an optional number containing the base of the chromosome elements or a vector containing the base(s) of the loci of the chromosomes. |
a list containing following components:
Chrom |
a matrix containing the random valued chromosomes row wise. |
Lind |
a scalar containing the length of the chromosome. |
BaseV |
a vector containing the base of the chromosome loci. |
The original 'MATLAB' implementation of crtbp was written by Andrew Chipperfield. The R implementation was written by Liang Zhao.
## 40 individuals with 10 binary loci Chrom = crtbp(40,10)$Chrom ## 6 individuals with 5 loci of base 8 Chrom = crtbp(6,5,8)$Chrom ## 6 individuals whose loci have bases 2, 4 and 8 Chrom = crtbp(6,c(2,4,8))$Chrom## 40 individuals with 10 binary loci Chrom = crtbp(40,10)$Chrom ## 6 individuals with 5 loci of base 8 Chrom = crtbp(6,5,8)$Chrom ## 6 individuals whose loci have bases 2, 4 and 8 Chrom = crtbp(6,c(2,4,8))$Chrom
This function creates a population of given size of random real-values.
crtrp(Nind, FieldDR)crtrp(Nind, FieldDR)
Nind |
a value containing the number of individuals in the new population. |
FieldDR |
a matrix of 2 rows by number of variables describing the boundaries of each variable. |
The first step in a genetic algorithm is to create an initial population consisting of
random individuals. crtrp produces a matrix, Chrom, containing uniformly
distributed random values in its elements.
Chrom = crtrp(Nind, FieldDR) creates a random real-valued matrix of
size Nind * Nvar, where Nind specifies the number of individuals in the
population and Nvar the number of variables of each individual. Nvar is derived
from FieldDR with Nvar = NCOL(FieldDR).
FieldDR is a matrix of size 2 * Nvar and contains
the boundaries of each variable of an individual. The first row contains the lower
bounds, the second row the upper bounds.
FieldDR is also used in other functions such as mutate.
a matrix containing the random valued individuals of the
new population of size Nind by number of variables.
The original 'MATLAB' implementation of crtrp was written by Hartmut Pohlheim and tested by Alex Shenfield. The R implementation was written by Liang Zhao.
mutbga, recdis, recint, reclin
## To create a random population of 6 individuals with 4 variables each: ## Define boundaries on the variables, FieldDR = matrix(c(-100,-50,-30,-20, 100,50,30,20),2,4,byrow=TRUE) ## Create initial population Chrom = crtrp(6,FieldDR)## To create a random population of 6 individuals with 4 variables each: ## Define boundaries on the variables, FieldDR = matrix(c(-100,-50,-30,-20, 100,50,30,20),2,4,byrow=TRUE) ## Create initial population Chrom = crtrp(6,FieldDR)
This function performs migration of individuals.
migrate( Chrom, SUBPOP = 1, ObjV, MIGR = 0.2, Select = FALSE, Structure = c("net", "neighbourhood", "ring") )migrate( Chrom, SUBPOP = 1, ObjV, MIGR = 0.2, Select = FALSE, Structure = c("net", "neighbourhood", "ring") )
Chrom |
a matrix containing the individuals of the current population. Each row corresponds to one individual. |
SUBPOP |
an optional number indicating subpopulations. Default is set to 1 subpopulation. |
ObjV |
an optional vector containing the objective values (cost values, to be minimized) of the individuals in the current population. |
MIGR |
a number indicating rate of individuals to be migrated per subpopulation. Default is set to 0.2. |
Select |
a logical value indicating whether fitness-based selection
will be used. Default is set to FALSE. If set to TRUE, then |
Structure |
a character string indicating the name of structure of the subpopulations
for migration: one of |
gatbxr provides support for multiple subpopulations through the use of
high-level genetic operator functions and a routine for exchanging individuals
between subpopulations. In the literature, the use of multiple populations has
been shown, in most cases, to improve the quality of the results obtained using GAs
compared to the single population GA.
gatbxr supports the use of a single population divided into a number of
subpopulations or by modifying the use of data structures such that
subpopulations are stored in contiguous blocks within a single matrix.
In this model each subpopulation is evolved over generations by a traditional GA and
from time to time individuals migrate from one subpopulation to another. The amount of
migration of individuals and the pattern of that migration determines how much genetic
diversity can occur.
migrate implements the transfer of individuals between subpopulations, in which
Structure specifies the population topology over which migration will take place.
The default unrestricted migration topology (net) is the most general
migration strategy. Here, individuals may migrate from any subpopulation to another. For each
subpopulation, a pool of potential immigrants is constructed from the other subpopulations.
The individual migrants are then determined according to the appropriate selection
strategy.
Structure ring transfers individuals between directionally adjacent subpopulations.
And neighbourhood is a similar strategy. Like the ring topology, migration
is made only between nearest neighbours, however, migration may occur in either direction
between subpopulations. For each subpopulation, the possible immigrants are determined,
according to the desired selection method, from the adjacent subpopulations and a final
selection made from this pool of individuals. This ensures that individuals will not
migrate from a subpopulation to the same population.
a list containing following components:
Chrom |
a matrix containing the individuals of the current population after reinsertion. |
ObjV |
if |
The original 'MATLAB' implementation of migrate was written by Hartmut Pohlheim. The R implementation was written by Liang Zhao.
select, recombin, mutate,
reins
## create initial population of 5 subpopulations with 10 individuals each Chrom = crtbp(50,10)$Chrom ## calculate objective values (to be minimized) with sum function ObjV = apply(Chrom,1,sum) ## choose 20% of the individuals of one subpopulation and replace ## these individuals with the fittest individuals from an adjacent ## subpopulation in a unidirectional ring structure res = migrate(Chrom, SUBPOP = 5, ObjV, Select = TRUE, Structure = "ring")## create initial population of 5 subpopulations with 10 individuals each Chrom = crtbp(50,10)$Chrom ## calculate objective values (to be minimized) with sum function ObjV = apply(Chrom,1,sum) ## choose 20% of the individuals of one subpopulation and replace ## these individuals with the fittest individuals from an adjacent ## subpopulation in a unidirectional ring structure res = migrate(Chrom, SUBPOP = 5, ObjV, Select = TRUE, Structure = "ring")
This function takes the representation of the current population, mutates each element with given probability and returns the resulting population.
mut(OldChrom, Pm = NULL, BaseV = NULL)mut(OldChrom, Pm = NULL, BaseV = NULL)
OldChrom |
a matrix containing the chromosomes of the current population. Each row corresponds to an individual's string representation. |
Pm |
a value indicating mutation probability. Default value
is |
BaseV |
an optional vector of the same length as the chromosome structure defining the base of the individual elements of the chromosome. Default is set to binary representation. |
a matrix containing a mutated version of OldChrom.
The original 'MATLAB' implementation of mut was written by Andrew Chipperfield. The R implementation was written by Liang Zhao.
Chrom = crtbp(40,10)$Chrom NewChrom = mut(OldChrom=Chrom)Chrom = crtbp(40,10)$Chrom NewChrom = mut(OldChrom=Chrom)
This function takes a matrix OldChrom containing the
representation of the individuals in the current population,
mutates the individuals and returns the resulting population.
The function handles multiple populations and calls the low-level mutation function for the actual mutation process.
mutate(MUT_F = "mut", OldChrom, FieldDR = NULL, MutOpt = NULL, SUBPOP = 1, ...)mutate(MUT_F = "mut", OldChrom, FieldDR = NULL, MutOpt = NULL, SUBPOP = 1, ...)
MUT_F |
character string containing the name of the low-level mutation
function, e.g. |
OldChrom |
matrix containing the chromosomes of the old population. Each line corresponds to one individual. |
FieldDR |
matrix describing the boundaries of each variable (real-values) or defining the base of the variables of each individual (discrete values). Optional for (binary) discrete values |
MutOpt |
an optional vector containing mutation rate and shrink value:
|
SUBPOP |
an optional number of subpopulations. Default is set to 1. |
... |
other arguments passed on to the mutation function. |
a matrix containing the chromosomes of the population
after mutation in the same format as OldChrom.
mutate has the same name as functions in other packages (for example
dplyr::mutate); use gatbxr::mutate if another package masks it.
The original 'MATLAB' implementation of mutate was written by Hartmut Pohlheim. The R implementation was written by Liang Zhao.
## Binary population Chrom = crtbp(40,10)$Chrom NewChrom = mutate(MUT_F="mut",OldChrom=Chrom) ## Real-valued population FieldDR = matrix(c(-100,-50,-30,-20,100,50,30,20),2,4,byrow=TRUE) Chrom = crtrp(6,FieldDR) NewChrom = mutate("mutbga",Chrom,FieldDR)## Binary population Chrom = crtbp(40,10)$Chrom NewChrom = mutate(MUT_F="mut",OldChrom=Chrom) ## Real-valued population FieldDR = matrix(c(-100,-50,-30,-20,100,50,30,20),2,4,byrow=TRUE) Chrom = crtrp(6,FieldDR) NewChrom = mutate("mutbga",Chrom,FieldDR)
This function implements the mutation operator of the Breeder Genetic Algorithm.
mutbga(OldChrom, FieldDR, MutOpt = NULL)mutbga(OldChrom, FieldDR, MutOpt = NULL)
OldChrom |
a matrix containing the chromosomes of the old population. Each row corresponds to one individual. |
FieldDR |
a matrix of 2 rows by number of variables describing the boundaries of each variable. |
MutOpt |
an optional vector containing mutation rate and shrink value:
|
mutbga takes a matrix OldChrom containing the real
representation of the individuals in the current population,
mutates the individuals with given probability and returns
the resulting population.
The mutation of a variable is computed as follows:
mutated variable = variable + ,
where = 1 or -1 with probability (+ or - with equal
probability), else 0. domain of variable (search interval defined
by FieldDR). with probability
, else 0, m = 20.
With , the mutation operator is able to locate the optimum up to a
precision of .
mutbga is able to generate most points in the hypercube defined by the
variables of the individual and the range of the mutation. However, it tests more
often near the variable, that is, the probability of small step sizes is greater
than that of larger step sizes.
a matrix containing the chromosomes of the population
after mutation in the same format as OldChrom.
The original 'MATLAB' implementation of mutbga was written by Hartmut Pohlheim. The R implementation was written by Liang Zhao.
Muhlenbein, H. and Schlierkamp-Voosen, D. (1993) Predictive Models for the Breeder Genetic Algorithm: I. Continuous Parameter Optimization. Evolutionary Computation, 1(1), 25–49. doi:10.1162/evco.1993.1.1.25
mutate, recdis, recint, recmut,
reclin
## Initialise a real-valued population FieldDR = matrix(c(-100,-50,-30,-20,100,50,30,20),2,4,byrow=TRUE) Chrom = crtrp(6,FieldDR) ## Perform mutation NewChrom = mutbga(Chrom,FieldDR)## Initialise a real-valued population FieldDR = matrix(c(-100,-50,-30,-20,100,50,30,20),2,4,byrow=TRUE) Chrom = crtrp(6,FieldDR) ## Perform mutation NewChrom = mutbga(Chrom,FieldDR)
This function ranks individuals represented by their associated
cost, to be minimized, and returns a vector FitnV
containing the corresponding individual fitnesses. For multiple
subpopulations the ranking is performed separately for each
subpopulation.
ranking(ObjV, RFun = c(2, 0), SUBPOP = 1)ranking(ObjV, RFun = c(2, 0), SUBPOP = 1)
ObjV |
a vector containing the objective values of the individuals in the current population (cost values). |
RFun |
if |
SUBPOP |
an optional number indicating subpopulations. Default is set to 1 subpopulation. |
Individuals with equal objective values receive the same fitness, namely the average of the fitness values assigned to their ranks.
a vector containing the fitness values of the individuals in the current population.
The original 'MATLAB' implementation of ranking was written by Hartmut Pohlheim and Carlos Fonseca. The R implementation was written by Liang Zhao.
Chrom = crtbp(40,10)$Chrom ## Objective function is the sum of individuals ObjV = apply(Chrom,1,sum) ## Linear ranking with selective pressure 2 FitnV = ranking(ObjV) ## Non-linear ranking with selective pressure 3 FitnV = ranking(ObjV, RFun = c(3,1))Chrom = crtbp(40,10)$Chrom ## Objective function is the sum of individuals ObjV = apply(Chrom,1,sum) ## Linear ranking with selective pressure 2 FitnV = ranking(ObjV) ## Non-linear ranking with selective pressure 3 FitnV = ranking(ObjV, RFun = c(3,1))
This function performs discrete recombination between pairs of individuals and returns the new individuals after mating.
recdis(OldChrom)recdis(OldChrom)
OldChrom |
a matrix containing the chromosomes of the old population. Each line corresponds to one individual. |
recdis is a function applicable to both populations of real-value variables
and binary or integer variables. The pairs are mated in order, odd row with the next even row.
If the number of rows in the matrix OldChrom is odd then the last row is not
mated and added at the end of NewChrom. The population should therefore be organised
into contiguous pairs that require mating. This can be achieved by using the function
ranking to assign a fitness level to each individual and a selection function
(e.g. select) to select individuals with a probability related to their
fitness in the current population.
a matrix containing the chromosomes of the population after mating, ready to be mutated and/or evaluated, in the same format as OldChrom.
Discrete recombination exchanges variable values between the individuals. For
each variable the parent who contributes its variable value to the offspring is
chosen randomly with equal probability.
Discrete recombination can generate the corners of the hypercube defined by the parents.
The original 'MATLAB' implementation was written by Hartmut Pohlheim. The R implementation was written by Liang Zhao.
recombin, recint, reclin, ranking,
sus, rws
## Initial a real-valued population FieldDR = matrix(c(-100,-50,-30,-20,100,50,30,20),2,4,byrow=TRUE) Chrom = crtrp(6,FieldDR) ## Perform discrete recombination NewChrom = recdis(Chrom)## Initial a real-valued population FieldDR = matrix(c(-100,-50,-30,-20,100,50,30,20),2,4,byrow=TRUE) Chrom = crtrp(6,FieldDR) ## Perform discrete recombination NewChrom = recdis(Chrom)
This function performs extended intermediate recombination between pairs of individuals and returns the new individuals after mating.
recint(OldChrom)recint(OldChrom)
OldChrom |
a matrix containing the chromosomes of the old population. Each line corresponds to one individual. |
recint is a function only applicable to populations of real-value variables
(and not binary or integer). The pairs are mated in order, odd row with the next even row.
If the number of rows in the matrix OldChrom is odd then the last row is not
mated and added at the end of NewChrom. The population should therefore be organised
into contiguous pairs that require mating. This can be achieved by using the function
ranking to assign a fitness level to each individual and a selection function
(e.g. select) to select individuals with a probability related to their
fitness in the current population.
a matrix containing the chromosomes of the population after mating, ready to be mutated and/or evaluated, in the same format as OldChrom.
Intermediate recombination combines parent values using the following rule:
where is a scaling factor chosen uniformly at random in the interval
. recint produces a new Alpha for each pair of values to be
combined.
Intermediate recombination can generate any point within a hypercube slightly
larger than that defined by the parents.
Intermediate recombination is similar to line recombination reclin. Whereas
recint uses a new Alpha factor for each pair of values combined together,
reclin uses one Alpha factor for each pair of parents.
The original 'MATLAB' implementation was written by Hartmut Pohlheim. The R implementation was written by Liang Zhao.
recombin, recdis, reclin, ranking,
sus, rws
## Initial a real-valued population FieldDR = matrix(c(-100,-50,-30,-20,100,50,30,20),2,4,byrow=TRUE) Chrom = crtrp(6,FieldDR) ## Perform intermediate recombination NewChrom = recint(Chrom)## Initial a real-valued population FieldDR = matrix(c(-100,-50,-30,-20,100,50,30,20),2,4,byrow=TRUE) Chrom = crtrp(6,FieldDR) ## Perform intermediate recombination NewChrom = recint(Chrom)
This function performs line recombination between pairs of individuals and returns the new individuals after mating.
reclin(OldChrom)reclin(OldChrom)
OldChrom |
a matrix containing the chromosomes of the old population. Each line corresponds to one individual. |
reclin is a function only applicable to populations of real-value variables
(and not binary or integer). The pairs are mated in order, odd row with the next even row.
If the number of rows in the matrix OldChrom is odd then the last row is not
mated and added at the end of NewChrom. The population should therefore be organised
into contiguous pairs that require mating. This can be achieved by using the function
ranking to assign a fitness level to each individual and a selection function
(e.g. select) to select individuals with a probability related to their
fitness in the current population.
a matrix containing the chromosomes of the population after mating, ready to be mutated and/or evaluated, in the same format as OldChrom.
Line recombination combines parent values using the following rule:
where is a scaling factor chosen uniformly at random in the interval
. reclin produces one Alpha factor for each pair of parents
combined.
Line recombination can generate any point on a slightly longer
line than that defined by the parents.
Line recombination is similar to intermediate recombination recint. Whereas
reclin uses one Alpha factor for each pair of parents combined together,
recint uses a new Alpha factor for each pair of values.
The original 'MATLAB' implementation was written by Hartmut Pohlheim. The R implementation was written by Liang Zhao.
recombin, recdis, recint, ranking,
sus, rws
## Initial a real-valued population FieldDR = matrix(c(-100,-50,-30,-20,100,50,30,20),2,4,byrow=TRUE) Chrom = crtrp(6,FieldDR) ## Perform line recombination NewChrom = reclin(Chrom)## Initial a real-valued population FieldDR = matrix(c(-100,-50,-30,-20,100,50,30,20),2,4,byrow=TRUE) Chrom = crtrp(6,FieldDR) ## Perform line recombination NewChrom = reclin(Chrom)
This function performs line recombination with mutation features between pairs of individuals.
recmut(OldChrom, FieldDR, MutOpt = NULL)recmut(OldChrom, FieldDR, MutOpt = NULL)
OldChrom |
matrix containing the chromosomes of the old population. Each line corresponds to one individual. |
FieldDR |
matrix describing the boundaries of each variable (real-values) or defining the base of the variables of each individual (discrete values). Optional for (binary) discrete values |
MutOpt |
an optional vector containing recombination rate and shrink value:
|
recmut is a function only applicable to populations of real-value variables
(and not binary or integer). The pairs are mated in order, odd row with the next even row.
If the number of rows in the matrix OldChrom is odd then the last row is not
mated and added at the end of NewChrom. The population should therefore be organised
into contiguous pairs that require mating. This can be achieved by using the function
ranking to assign a fitness level to each individual and a selection function
(e.g. select) to select individuals with a probability related to their
fitness in the current population.
The offspring of a pair of two parents are computed as follows:
where, = 1 or -1 with probability (- with
probability 0.9), else 0. domain of variable (search interval defined
by FieldDR). with probability
, else 0, m = 20..
Pairs of parents with equal norms are not moved.
The recombination operator recmut generates offspring in a direction defined by
the parents (line recombination). It tests more often outside the area defined by the
parents and in the direction of parent1. The point for the offspring is defined by
features of the mutation operator. The probability of small step sizes is greater than
that of bigger steps (see mutbga).
a matrix containing the chromosomes of the population after mating, ready to be mutated and/or evaluated, in the same format as OldChrom.
This function doesn't work with high level recombination function recombin
The original 'MATLAB' implementation of recmut was written by Hartmut Pohlheim. The R implementation was written by Liang Zhao.
## Initial a real-valued population FieldDR = matrix(c(-100,-50,-30,-20,100,50,30,20),2,4,byrow=TRUE) Chrom = crtrp(6,FieldDR) ## Perform line recombination with mutation NewChrom = recmut(Chrom,FieldDR)## Initial a real-valued population FieldDR = matrix(c(-100,-50,-30,-20,100,50,30,20),2,4,byrow=TRUE) Chrom = crtrp(6,FieldDR) ## Perform line recombination with mutation NewChrom = recmut(Chrom,FieldDR)
This function performs recombination between pairs of individuals and returns the new individuals after mating. The function handles multiple populations and calls the low-level recombination function for the actual recombination process.
recombin(REC_F, Chrom, RecOpt = 0.7, SUBPOP = 1, ...)recombin(REC_F, Chrom, RecOpt = 0.7, SUBPOP = 1, ...)
REC_F |
character string containing the name of the recombination or
crossover function, e.g. |
Chrom |
a matrix containing the chromosomes of the old population. Each row corresponds to one individual. |
RecOpt |
an optional value containing the probability of
recombination/crossover occurring between pairs of individuals.
It is only used by the crossover functions ( |
SUBPOP |
an optional number indicating subpopulations. Default is set to 1. |
... |
other arguments passed on to the crossover function. |
a matrix containing the chromosomes of the population
after recombination in the same format as Chrom.
This function doesn't work with low level recombination function recmut.
The original 'MATLAB' implementation of recombin was written by Hartmut Pohlheim. The R implementation was written by Liang Zhao.
Selch = crtbp(40,10)$Chrom NewChrom = recombin(REC_F="xovsp",Chrom=Selch)Selch = crtbp(40,10)$Chrom NewChrom = recombin(REC_F="xovsp",Chrom=Selch)
This function reinserts offspring in the population.
reins( Chrom, SelCh, SUBPOP = 1, InsOpt = c(0, 1), ObjVCh = NULL, ObjVSel = NULL )reins( Chrom, SelCh, SUBPOP = 1, InsOpt = c(0, 1), ObjVCh = NULL, ObjVSel = NULL )
Chrom |
matrix containing the individuals (parents) of the current population. Each row corresponds to one individual. |
SelCh |
matrix containing the offspring of the current population. Each row corresponds to one individual. |
SUBPOP |
an optional number indicating subpopulations. Default is set to 1 subpopulation. |
InsOpt |
an optional vector containing the insertion method parameters.
|
ObjVCh |
an optional vector containing the objective values
of the individuals (parents, |
ObjVSel |
an optional vector containing the objective values
of the offspring ( |
a list containing following components:
ObjVCh |
if |
Chrom |
matrix containing the individuals of the current population after reinsertion. |
The original 'MATLAB' implementation of reins was written by Hartmut Pohlheim and tested by Alex Shenfield. The R implementation was written by Liang Zhao.
## Parents and their objective values (to be minimized) Chrom = crtbp(10,8)$Chrom ObjVCh = apply(Chrom,1,sum) ## Offspring and their objective values SelCh = crtbp(6,8)$Chrom ObjVSel = apply(SelCh,1,sum) ## Replace the worst parents with all offspring (fitness-based insertion) res = reins(Chrom, SelCh, InsOpt = c(1,1), ObjVCh = ObjVCh, ObjVSel = ObjVSel) ## Insert the best 50% of the offspring at uniformly random positions res = reins(Chrom, SelCh, InsOpt = c(0,0.5), ObjVSel = ObjVSel)## Parents and their objective values (to be minimized) Chrom = crtbp(10,8)$Chrom ObjVCh = apply(Chrom,1,sum) ## Offspring and their objective values SelCh = crtbp(6,8)$Chrom ObjVSel = apply(SelCh,1,sum) ## Replace the worst parents with all offspring (fitness-based insertion) res = reins(Chrom, SelCh, InsOpt = c(1,1), ObjVCh = ObjVCh, ObjVSel = ObjVSel) ## Insert the best 50% of the offspring at uniformly random positions res = reins(Chrom, SelCh, InsOpt = c(0,0.5), ObjVSel = ObjVSel)
This function selects a given number of individuals from a population.
rws(FitnV, Nsel)rws(FitnV, Nsel)
FitnV |
a vector containing the fitness values of the individuals in the population. |
Nsel |
a number indicating how many individuals are to be selected. |
rws probabilistically selects Nsel individuals for reproduction according
to their fitness, FitnV, in the current population.
NewChrIx = rws(FitnV,Nsel) selects Nsel individuals from a
population using roulette wheel selection. FitnV is a vector containing a
performance measure for each individual in the population. This can be achieved
by using the function ranking or scaling to assign a
fitness level to each individual.
rws is a low-level selection function normally called by select.
a vector containing the indexes of the selected individuals relative to the original population, shuffled. The new population, ready for mating, can be obtained by calculating OldChrom[NewChrIx,].
A form of roulette wheel selection is implemented by obtaining a cumulative sum
of the fitness vector, FitnV, and generating Nsel uniformly at random
distributed numbers between 0 and sum(FitnV). The index of the individuals
selected is determined by comparing the generated numbers with the cumulative
sum vector. The probability of an individual being selected is then given by:
where is the fitness of individual and
is the probability of that individual being selected.
The original 'MATLAB' implementation of rws was written by Carlos Fonseca and Andrew Chipperfield. The R implementation was written by Liang Zhao.
select, sus, reins, ranking,
scaling
## Consider a population of 8 individuals with the assigned fitness values, FitnV: FitnV = c(1.5,1.35,1.21,1.07,0.92,0.78,0.64,0.5) ## Select the indices of 6 individuals: NewChrIx = rws(FitnV,6)## Consider a population of 8 individuals with the assigned fitness values, FitnV: FitnV = c(1.5,1.35,1.21,1.07,0.92,0.78,0.64,0.5) ## Select the indices of 6 individuals: NewChrIx = rws(FitnV,6)
This function implements a linear fitness scaling algorithm. For multiple
subpopulations scaling is performed separately for each
subpopulation.
scaling(ObjV, Smul = 2, SUBPOP = 1)scaling(ObjV, Smul = 2, SUBPOP = 1)
ObjV |
a vector containing the non-negative objective values of the individuals. |
Smul |
an optional value used to determine the upper bound, default is set to 2. |
SUBPOP |
an optional value indicating subpopulations. Default is set to 1 subpopulation. |
scaling converts the objective values, ObjV, into a fitness
measure with a known upper bound, determined by the value of Smul, such that,
where is the objective value of individual ,
is a scaling coefficient, is an offset and is
the resulting fitness value of individual . If is the average
objective value in the current generation, then the maximum fitness of the scaled population
is upper bounded at . If Smul is omitted then the default
value is set to 2. The average fitness of the scaled population is also set to
.
If the upper bound cannot be reached without producing negative fitness
values, scaling instead chooses the offset such that the
smallest scaled fitness value is zero. If all objective values of a
subpopulation are equal, every individual is assigned the average value.
a vector containing the individual fitnesses for the current population.
Negative objective values are not supported, as linear scaling becomes
unreliable in that case. ranking is generally recommended
instead; scaling is included only for the sake of completeness.
The original 'MATLAB' implementation of scaling was written by Andrew Chipperfield. The R implementation was written by Liang Zhao.
Goldberg, D. E. (1989) Genetic Algorithms in Search, Optimization and Machine Learning. Addison Wesley.
ranking, reins, rws, select,
sus
Chrom = crtbp(40,10)$Chrom ## Objective function is the sum of individuals ObjV = apply(Chrom,1,sum) FitnV = scaling(ObjV)Chrom = crtbp(40,10)$Chrom ## Objective function is the sum of individuals ObjV = apply(Chrom,1,sum) FitnV = scaling(ObjV)
This function performs universal selection. The function handles multiple populations and calls the low level selection function for the actual selection process.
select(SEL_F = "sus", Chrom, FitnV, GGAP = 1, SUBPOP = 1, ...)select(SEL_F = "sus", Chrom, FitnV, GGAP = 1, SUBPOP = 1, ...)
SEL_F |
character string containing the name of the low-level selection
function, e.g. |
Chrom |
a matrix containing the individuals (parents) of the current population. Each row corresponds to one individual. |
FitnV |
a vector containing the fitness values of the individuals in the population. |
GGAP |
an optional number indicating rate of individuals to be selected. Default is set to 1. |
SUBPOP |
an optional number indicating subpopulations. Default is set to 1 subpopulation. |
... |
other arguments passed on to the selection function. |
a matrix containing the selected individuals.
select has the same name as functions in other packages (for example
dplyr::select); use gatbxr::select if another package masks it.
The original 'MATLAB' implementation of select was written by Hartmut Pohlheim. The R implementation was written by Liang Zhao.
Chrom = crtbp(40,10)$Chrom ## Objective function is the sum of individuals FitnV = ranking(apply(Chrom,1,sum)) Selch = select(SEL_F="sus",Chrom=Chrom,FitnV=FitnV,GGAP=0.9)Chrom = crtbp(40,10)$Chrom ## Objective function is the sum of individuals FitnV = ranking(apply(Chrom,1,sum)) Selch = select(SEL_F="sus",Chrom=Chrom,FitnV=FitnV,GGAP=0.9)
This function performs selection with stochastic universal sampling.
sus(FitnV, Nsel)sus(FitnV, Nsel)
FitnV |
a vector containing the fitness values of the individuals in the population. |
Nsel |
a number indicating how many individuals are to be selected. |
a vector containing the indexes of the selected individuals relative to the original population, shuffled. The new population, ready for mating, can be obtained by calculating OldChrom[NewChrIx,].
The original 'MATLAB' implementation of sus was written by Hartmut Pohlheim and Carlos Fonseca. The R implementation was written by Liang Zhao.
Chrom = crtbp(40,10)$Chrom ## Objective function is the sum of individuals FitnV = ranking(apply(Chrom,1,sum)) Selch = sus(FitnV=FitnV,Nsel=2)Chrom = crtbp(40,10)$Chrom ## Objective function is the sum of individuals FitnV = ranking(apply(Chrom,1,sum)) Selch = sus(FitnV=FitnV,Nsel=2)
These functions take a matrix OldChrom containing the binary
representation of the individuals in the current population,
apply crossover to consecutive pairs of individuals with
defined probability and return the resulting population.
xovmp(OldChrom, Px = 0.7, Npt = 0, Rs = FALSE) xovsp(OldChrom, Px = 0.7) xovdp(OldChrom, Px = 0.7) xovsh(OldChrom, Px = 0.7) xovsprs(OldChrom, Px = 0.7) xovdprs(OldChrom, Px = 0.7) xovshrs(OldChrom, Px = 0.7)xovmp(OldChrom, Px = 0.7, Npt = 0, Rs = FALSE) xovsp(OldChrom, Px = 0.7) xovdp(OldChrom, Px = 0.7) xovsh(OldChrom, Px = 0.7) xovsprs(OldChrom, Px = 0.7) xovdprs(OldChrom, Px = 0.7) xovshrs(OldChrom, Px = 0.7)
OldChrom |
a matrix containing the chromosomes of the old population. Each row corresponds to one individual. |
Px |
a number indicating the probability of recombination occurring between pairs of individuals. If omitted, 0.7 is used. |
Npt |
an optional number indicating the number of crossover points to use. Specifically, 1 indicates single point recombination; 2 indicates double point recombination; and 0 indicates shuffle point recombination. Default is set to 0. |
Rs |
an optional logical value indicating whether or not to force the production of offspring different from their parents. Default is set to FALSE. |
xovmp is the general crossover function for binary representation and
is called by all other crossover functions. When xovmp is called by
the high-level function recombin, its additional arguments can
be passed through .... With different combinations of arguments, it can
be used identically to xovsp, xovdp, xovsh, xovsprs,
xovdprs and xovshrs. Although these functions are redundant, they
are kept for completeness.
xovsp performs single-point crossover between pairs of individuals. When called by
recombin, recombin("xovsp",Chrom) is identical to
recombin("xovmp",Chrom,Npt=1).
xovdp performs double-point crossover between pairs of individuals. When called by
recombin, recombin("xovdp",Chrom) is identical to
recombin("xovmp",Chrom,Npt=2).
xovsh performs shuffle-point crossover between pairs of individuals. When called by
recombin, recombin("xovsh",Chrom) is identical to
recombin("xovmp",Chrom).
xovsprs performs single-point reduced surrogate crossover between
pairs of individuals. When called by recombin,
recombin("xovsprs",Chrom) is identical to
recombin("xovmp",Chrom,Npt=1,Rs=TRUE).
xovdprs performs double-point reduced surrogate crossover between
pairs of individuals. When called by recombin,
recombin("xovdprs",Chrom) is identical to
recombin("xovmp",Chrom,Npt=2,Rs=TRUE).
xovshrs performs shuffle-point reduced surrogate crossover between
pairs of individuals. When called by recombin,
recombin("xovshrs",Chrom) is identical to
recombin("xovmp",Chrom,Rs=TRUE).
a matrix containing the offspring after mating, ready to be mutated and/or evaluated, in the same format as OldChrom.
The original 'MATLAB' implementation of xovmp was written by Carlos Fonseca and updated by Andrew Chipperfield; the other crossover functions were written by Hartmut Pohlheim. The R implementation was written by Liang Zhao.
Chrom = crtbp(40,10)$Chrom ## Shuffle crossover Selch = xovmp(OldChrom=Chrom) ## Single-point crossover Selch = xovsp(Chrom, Px = 0.8)Chrom = crtbp(40,10)$Chrom ## Shuffle crossover Selch = xovmp(OldChrom=Chrom) ## Single-point crossover Selch = xovsp(Chrom, Px = 0.8)