Title: Gene Operations for Real-Coded Genes
Version: 1.0.0.3
Description: Representation-dependent gene-level operations for genetic and evolutionary algorithms with real-coded genes are collected in this package. The common feature of the gene operations is that all of them are useful for derivation-free optimization algorithms. At the moment the package implements initialization, mutation, crossover, and replication operations for differential evolution as described in Price, Kenneth V., Storn, Rainer M. and Lampinen, Jouni A. (2005) <doi:10.1007/3-540-31306-0>.
License: MIT + file LICENSE
URL: https://github.com/ageyerschulz/xegaDfGene
Encoding: UTF-8
RoxygenNote: 7.3.2
Suggests: testthat (≥ 3.0.0)
Imports: xegaSelectGene
NeedsCompilation: no
Packaged: 2025-04-16 09:57:24 UTC; dj2333
Author: Andreas Geyer-Schulz ORCID iD [aut, cre]
Maintainer: Andreas Geyer-Schulz <Andreas.Geyer-Schulz@kit.edu>
Repository: CRAN
Date/Publication: 2025-04-16 10:50:05 UTC

Package xegaDfGene.

Description

Genetic operations for real-coded genetic and evolutionary algorithms.

Details

For real-coded genes, the xegaDfGene package provides

Current support: Functions for differential evolution (de). See Price et al. (2005).

Real-Coded Gene Representation

A real-coded gene is a named list:

Abstract Interface of Problem Environment

We reuse the abstract interface of a problem environment for binary-coded genes. The number of parameters is given by length(penv$bitlength()).

A problem environment penv must provide:

The Architecture of the xegaX-Packages

The xegaX-packages are a family of R-packages which implement eXtended Evolutionary and Genetic Algorithms (xega). The architecture has 3 layers, namely the user interface layer, the population layer, and the gene layer:

Copyright

(c) 2023 Andreas Geyer-Schulz

License

MIT

<URL

https://github.com/ageyerschulz/xegaDfGene>

Installation

From CRAN by install.packages('xegaDfGene')

Author(s)

Andreas Geyer-Schulz

References

Price, Kenneth V., Storn, Rainer M. and Lampinen, Jouni A. (2005) The Differential Evolution Algorithm (Chapter 2), pp. 37-134. In: Differential Evolution. A Practical Approach to Global Optimization. Springer, Berlin. <doi:10.1007/3-540-31306-0>

See Also

Useful links:


Constant scale factor for differential evolution.

Description

Constant scale factor for differential evolution.

Usage

ConstScaleFactor(lF)

Arguments

lF

Local configuration.

Value

A constant scale factor.

See Also

Other Scale Factor: UniformRandomScaleFactor()

Examples

parm<-function(x){function() {return(x)}}
lF<-list()
lF$ScaleFactor1<-parm(0.90)
ConstScaleFactor(lF)
lF$ScaleFactor1<-parm(1.10)
ConstScaleFactor(lF)

Uniform random scale factor for differential evolution.

Description

The scale factor is drawn from 0.000001 to 1.0.

Usage

UniformRandomScaleFactor(lF)

Arguments

lF

Local configuration.

Value

A constant scale factor.

See Also

Other Scale Factor: ConstScaleFactor()

Examples

parm<-function(x){function() {return(x)}}
lF<-list()
lF$ScaleFactor1<-parm(0.90)
UniformRandomScaleFactor(lF)
lF$ScaleFactor1<-parm(1.10)
UniformRandomScaleFactor(lF)

Generate local functions and objects

Description

lFxegaDfGene() is the list of functions containing a definition of all local objects required for the use of evaluation functions. We reference this object as local configuration. When adding additional functions, this list must be extended by the constant (functions) needed to configure them.

Usage

lFxegaDfGene

Format

An object of class list of length 32.

Details

We use the local configuration for:

  1. Replacing all constants with constant functions.

    Rationale: We need one formal argument (the local function list lF) and we can dispatch multiple functions. E.g., lF$verbose().

  2. Dynamically binding a local function with a definition from a proper function factory. E.g., the selection methods lF$SelectGene() and lF$SelectMate().

  3. Gene representations requiring special functions to handle them: lF$InitGene(), lF$DecodeGene(), lF$EvalGene(), lF$ReplicateGene(), ...

See Also

Other Configuration: xegaDfCrossoverFactory(), xegaDfGeneMapFactory(), xegaDfMutationFactory(), xegaDfReplicationFactory(), xegaDfScaleFactorFactory()


One point crossover of 2 genes.

Description

xegaDfCrossGene() randomly determines a cut point. It combines the parameters before the cut point of the first gene with the parameters after the cut point from the second gene (kid 1).

Usage

xegaDfCrossGene(gg1, gg2, lF)

Arguments

gg1

Real-coded gene.

gg2

Real-coded gene.

lF

Local configuration of the genetic algorithm.

Value

Real-coded gene.

See Also

Other Crossover (Returns 1 Kid): xegaDfUCrossGene(), xegaDfUPCrossGene()

Examples

gene1<-xegaDfInitGene(lFxegaDfGene)
gene2<-xegaDfInitGene(lFxegaDfGene)
gene3<-xegaDfCrossGene(gene1, gene2, lFxegaDfGene)

Configure the crossover function of a genetic algorithm.

Description

xegaDfCrossoverFactory() implements the selection of one of the crossover functions in this package by specifying a text string. The selection fails ungracefully (produces a runtime error) if the label does not match. The functions are specified locally.

Current support:

Crossover functions with one kid:

  1. "CrossGene" returns CrossGene().

  2. "UCrossGene" returns UCrossGene(). Default.

  3. "UPCrossGene" returns UPCrossGene().

Usage

xegaDfCrossoverFactory(method = "UCrossGene")

Arguments

method

A string specifying the crossover function.

Details

All crossover operations return a 1 kid. This implies that some part of the genetic material is lost.

Value

Crossover function for genes.

See Also

Other Configuration: lFxegaDfGene, xegaDfGeneMapFactory(), xegaDfMutationFactory(), xegaDfReplicationFactory(), xegaDfScaleFactorFactory()

Examples

XGene<-xegaDfCrossoverFactory("UCrossGene")
gene1<-xegaDfInitGene(lFxegaDfGene)
gene2<-xegaDfInitGene(lFxegaDfGene)
XGene(gene1, gene2, lFxegaDfGene)

Decode a gene

Description

xegaDfDecodeGene() decodes a real gene.

Usage

xegaDfDecodeGene(gene, lF)

Arguments

gene

Real gene.

lF

Local configuration of the genetic algorithm.

Details

xegaDfDecodeGene() is the identity function.

Value

Decoded gene.

See Also

Other Decoder: xegaDfGeneMapIdentity()

Examples

gene<-xegaDfInitGene(lFxegaDfGene)
xegaDfDecodeGene(gene, lFxegaDfGene)


Configure the gene map function of a genetic algorithm.

Description

xegaDfGeneMapFactory() implements the selection of one of the GeneMap functions in this package by specifying a text string. The selection fails ungracefully (produces a runtime error) if the label does not match. The functions are specified locally.

Current support:

  1. "Identity" returns GeneMapIdentity(). (Default)

Usage

xegaDfGeneMapFactory(method = "Identity")

Arguments

method

String specifying the GeneMap function.

Value

Gene map function for genes.

See Also

Other Configuration: lFxegaDfGene, xegaDfCrossoverFactory(), xegaDfMutationFactory(), xegaDfReplicationFactory(), xegaDfScaleFactorFactory()

Examples

XGene<-xegaDfGeneMapFactory("Identity")
gene1<-xegaDfInitGene(lFxegaDfGene)
XGene(gene1, lFxegaDfGene$penv)

Map the parameter vector of a real-coded gene to an identical vector.

Description

xegaDfGeneMapIdentity() maps the real parameter vector to an identical vector.

Usage

xegaDfGeneMapIdentity(gene, penv)

Arguments

gene

Real-coded gene (the genotype).

penv

Problem environment.

Details

A gene is a list with

  1. $evaluated: Boolean. TRUE if the fitness is known.

  2. $fit: The fitness of the genotype of $gene1.

  3. $gene1: A real parameter vector (the genotopye).

Value

Decoded gene (the phenotype).

See Also

Other Decoder: xegaDfDecodeGene()

Examples

gene<-xegaDfInitGene(lFxegaDfGene)
xegaDfGeneMapIdentity(gene$gene1, lFxegaDfGene$penv)


Initialize a real-coded gene.

Description

xegaDfInitGene() generates a random real-coded gene with a given length.

Usage

xegaDfInitGene(lF)

Arguments

lF

Local configuration of the genetic algorithm.

Details

In the real-coded representation of package xegaDf, gene is at least a list with

  1. $evaluated: Boolean. TRUE if the fitness is known.

  2. $fit: The fitness of the genotype of $gene1.

  3. $gene1: a real vector (the genotype).

Value

A real-coded gene (a named list):

References

Price, Kenneth V., Storn, Rainer M. and Lampinen, Jouni A. (2005) The Differential Evolution Algorithm (Chapter 2), pp. 37-134. In: Differential Evolution. A Practical Approach to Global Optimization. Springer, Berlin. <doi:10.1007/3-540-31306-0>

See Also

Other Intialization: xegaGedeInitGene()

Examples

xegaDfInitGene(lFxegaDfGene)


Mutate a gene (differential mutation).

Description

xegaDfMutateGeneDE() mutates a real-coded gene. The scale factor is given by lF$ScaleFactor().

Usage

xegaDfMutateGeneDE(gene0, gene1, gene2, lF)

Arguments

gene0

Real-coded gene (the base vector).

gene1

Real-coded gene.

gene2

Real-coded gene.

lF

Local configuration.

Details

The difference between gene1 and gene2 is scaled by lF$ScaleFactor() and added to gene0.

Value

Real-coded gene.

References

Price, Kenneth V., Storn, Rainer M. and Lampinen, Jouni A. (2005) The Differential Evolution Algorithm (Chapter 2), pp. 37-134. In: Differential Evolution. A Practical Approach to Global Optimization. Springer, Berlin. <doi:10.1007/3-540-31306-0>

Examples

gene0<-xegaDfInitGene(lFxegaDfGene)
gene1<-xegaDfInitGene(lFxegaDfGene)
gene2<-xegaDfInitGene(lFxegaDfGene)
gene<-xegaDfMutateGeneDE(gene0, gene1, gene2, lFxegaDfGene)

Configure the mutation function of a genetic algorithm.

Description

xegaDfMutationFactory() implements the selection of one of the mutation functions in this package by specifying a text string. The selection fails ungracefully (produces a runtime error), if the label does not match. The functions are specified locally.

Current support:

  1. "MutateGene" returns xegaDfMutateGeneDE(). To provide a working default for more than one gene representation.

  2. "MutateGeneDE" returns xegaDfMutateGeneDE().

Usage

xegaDfMutationFactory(method = "MutateGene")

Arguments

method

A string specifying the mutation function.

Value

A mutation function for genes.

See Also

Other Configuration: lFxegaDfGene, xegaDfCrossoverFactory(), xegaDfGeneMapFactory(), xegaDfReplicationFactory(), xegaDfScaleFactorFactory()

Examples

Mutate<-xegaDfMutationFactory("MutateGene")
gene1<-xegaDfInitGene(lFxegaDfGene)
gene2<-xegaDfInitGene(lFxegaDfGene)
gene3<-xegaDfInitGene(lFxegaDfGene)
Mutate(gene1, gene2, gene3, lFxegaDfGene)

Replicates a gene (differential evolution).

Description

xegaDfReplicateGeneDE() replicates a gene. Replication is the reproduction function which uses crossover and mutation. The control flow of differential evolution is as follows:

Usage

xegaDfReplicateGeneDE(pop, fit, lF)

Arguments

pop

Population of real-coded genes.

fit

Fitness vector.

lF

Local configuration of the genetic algorithm.

Details

For selection="UniformP", for crossover="UPCrossGene" and for accept="Best" this is the algorithm of Price, Storn and Lampinen (2005), page 41.

Value

A list of one gene.

References

Price, Kenneth V., Storn, Rainer M. and Lampinen, Jouni A. (2005) The Differential Evolution Algorithm (Chapter 2), pp. 37-134. In: Differential Evolution. A Practical Approach to Global Optimization. Springer, Berlin. <doi:10.1007/3-540-31306-0>

Examples

pop10<-lapply(rep(0,10), function(x) xegaDfGene::xegaDfInitGene(lFxegaDfGene))
epop10<-lapply(pop10, lFxegaDfGene$EvalGene, lF=lFxegaDfGene)
fit10<-unlist(lapply(epop10, function(x) {x$fit}))
newgenes<-xegaDfReplicateGeneDE(pop10, fit10, lFxegaDfGene)

Configure the replication function of a genetic algorithm.

Description

xegaDfReplicationFactory() implements the selection of a replication method.

Current support:

  1. "DE" returns xegaDfReplicateGeneDE().

Usage

xegaDfReplicationFactory(method = "DE")

Arguments

method

A string specifying the replication function.

Value

A replication function for genes.

See Also

Other Configuration: lFxegaDfGene, xegaDfCrossoverFactory(), xegaDfGeneMapFactory(), xegaDfMutationFactory(), xegaDfScaleFactorFactory()

Examples

pop10<-lapply(rep(0,10), function(x) xegaDfInitGene(lFxegaDfGene))
epop10<-lapply(pop10, lFxegaDfGene$EvalGene, lF=lFxegaDfGene)
fit10<-unlist(lapply(epop10, function(x) {x$fit}))
Replicate<-xegaDfReplicationFactory("DE")
newgenes2<-Replicate(pop10, fit10, lFxegaDfGene)

Configure the scale factor function for differential mutation.

Description

xegaDfScaleFactorFactory() implements the selection of one of the scale factor functions in this package by specifying a text string. The selection fails ungracefully (produces a runtime error) if the label does not match. The functions are specified locally.

Current support:

  1. "Const" returns ConstScaleFactor().

  2. "Uniform" returns UniformRandomScaleFactor().

Usage

xegaDfScaleFactorFactory(method = "Const")

Arguments

method

A string specifying the scale factor function.

Details

In the literature, several approaches have been suggested. For a review see Sharma et al. (2019).

Value

A scale factor function for genes.

References

Sharma, Prashant; Sharma, Harish; Kumar, Sandeep; Bansal, Jagdish Chand (2019): A Review on Scale Factor Strategies in Differential Evolution Algorithm. pp. 925-934. In: Bansal, Jagdish Chand et al. (2019) Soft Computing for Problem Solving. Advances in Intelligent Systems and Computing, Vol. 817. Springer, Singapore, 2019. (ISBN:978-981-13-1594-7)

See Also

Other Configuration: lFxegaDfGene, xegaDfCrossoverFactory(), xegaDfGeneMapFactory(), xegaDfMutationFactory(), xegaDfReplicationFactory()

Examples

f<-xegaDfScaleFactorFactory("Const")
f(lFxegaDfGene)
f<-xegaDfScaleFactorFactory("Uniform")
f(lFxegaDfGene)
f(lFxegaDfGene)

Uniform crossover of 2 genes.

Description

xegaDfUCrossGene() swaps alleles of both genes with a probability of 0.5. It generates a random mask which is used to build the new gene.

Usage

xegaDfUCrossGene(gg1, gg2, lF)

Arguments

gg1

Real-coded gene.

gg2

Real-coded gene.

lF

Local configuration of the genetic algorithm.

Value

Real-coded gene.

References

Syswerda, Gilbert (1989): Uniform Crossover in Genetic Algorithms. In: Schaffer, J. David (Ed.) Proceedings of the Third International Conference on Genetic Algorithms, Morgan Kaufmann Publishers, Los Altos, California, pp. 2-9. (ISBN:1-55860-066-3)

See Also

Other Crossover (Returns 1 Kid): xegaDfCrossGene(), xegaDfUPCrossGene()

Examples

gene1<-xegaDfInitGene(lFxegaDfGene)
gene2<-xegaDfInitGene(lFxegaDfGene)
gene3<-xegaDfUCrossGene(gene1, gene2, lFxegaDfGene)

Parameterized uniform crossover of 2 genes.

Description

xegaDfUPCrossGene() swaps alleles of both genes with a probability of lF$UCrossSwap(). It generate a random mask which is used to build the new gene.

Usage

xegaDfUPCrossGene(gg1, gg2, lF)

Arguments

gg1

Real-coded gene.

gg2

Real-coded gene.

lF

Local configuration of the genetic algorithm.

Value

Real-coded gene.

References

Spears William and De Jong, Kenneth (1991): On the Virtues of Parametrized Uniform Crossover. In: Belew, Richard K. and Booker, Lashon B. (Ed.) Proceedings of the Fourth International Conference on Genetic Algorithms, Morgan Kaufmann Publishers, Los Altos, California, pp. 230-236. (ISBN: 1-55860-208-9)

Price, Kenneth V., Storn, Rainer M. and Lampinen, Jouni A. (2005) The Differential Evolution Algorithm (Chapter 2), pp. 37-134. In: Differential Evolution. A Practical Approach to Global Optimization. Springer, Berlin. <doi:10.1007/3-540-31306-0>

See Also

Other Crossover (Returns 1 Kid): xegaDfCrossGene(), xegaDfUCrossGene()

Examples

gene1<-xegaDfInitGene(lFxegaDfGene)
gene2<-xegaDfInitGene(lFxegaDfGene)
gene3<-xegaDfUPCrossGene(gene1, gene2, lFxegaDfGene)

Initialize a real-coded gene for grammar evolution

Description

xegaGedeInitGene() generates a random real-coded gene with a given length.

Usage

xegaGedeInitGene(lF)

Arguments

lF

Local configuration of the genetic algorithm.

Details

In the real-coded representation of package xegaDf, gene is at least a list with

  1. $evaluated: Boolean. TRUE if the fitness is known.

  2. $fit: The fitness of the genotype of $gene1.

  3. $gene1: a real vector (the genotype).

Value

A real-coded gene (a named list):

References

Price, Kenneth V., Storn, Rainer M. and Lampinen, Jouni A. (2005) The Differential Evolution Algorithm (Chapter 2), pp. 37-134. In: Differential Evolution. A Practical Approach to Global Optimization. Springer, Berlin. <doi:10.1007/3-540-31306-0>

See Also

Other Intialization: xegaDfInitGene()

Examples

xegaGedeInitGene(lFxegaDfGene)