C# Class AForge.Genetic.GEPChromosome

The chromosome represents a Gene Expression, which is used for different tasks of Genetic Expression Programming (GEP).

This type of chromosome represents combination of ideas taken from Genetic Algorithms (GA), where chromosomes are linear structures of fixed length, and Genetic Programming (GP), where chromosomes are expression trees. The GEP chromosome is also a fixed length linear structure, but with some additional features which make it possible to generate valid expression tree from any GEP chromosome.

The theory of Gene Expression Programming is well described in the next paper: Ferreira, C., 2001. Gene Expression Programming: A New Adaptive Algorithm for Solving Problems. Complex Systems, Vol. 13, issue 2: 87-129. A copy of the paper may be obtained on the gene expression programming web site.

Inheritance: ChromosomeBase
Afficher le fichier Open project: holisticware-admin/MonoVersal.AForgeNET Class Usage Examples

Protected Properties

Свойство Type Description
genes IGPGene[]
headLength int
length int
rand ThreadSafeRandom

Méthodes publiques

Méthode Description
Clone ( ) : IChromosome

Clone the chromosome.

The method clones the chromosome returning the exact copy of it.

CreateNew ( ) : IChromosome

Create new random chromosome with same parameters (factory method).

The method creates new chromosome of the same type, but randomly initialized. The method is useful as factory method for those classes, which work with chromosome's interface, but not with particular chromosome type.

Crossover ( IChromosome pair ) : void

Crossover operator.

The method performs one-point or two-point crossover selecting them randomly with equal probability.

GEPChromosome ( IGPGene ancestor, int headLength ) : System

Initializes a new instance of the GEPChromosome class.

This constructor creates a randomly generated GEP chromosome, which has all genes of the same type and properties as the specified ancestor.

Generate ( ) : void

Generate random chromosome value.

Regenerates chromosome's value using random number generator.

Mutate ( ) : void

Mutation operator.

The method performs chromosome's mutation by calling on of the methods randomly: MutateGene, TransposeIS, TransposeRoot.

RecombinationOnePoint ( GEPChromosome pair ) : void

One-point recombination (crossover).

RecombinationTwoPoint ( GEPChromosome pair ) : void

Two point recombination (crossover).

ToString ( ) : string

Get string representation of the chromosome by providing its expression in reverse polish notation (postfix notation).

ToStringNative ( ) : string

Get string representation of the chromosome.

The method is used for debugging mostly.

Méthodes protégées

Méthode Description
GEPChromosome ( GEPChromosome source ) : System

Initializes a new instance of the GEPChromosome class.

GetTree ( ) : GPTreeNode

Get tree representation of the chromosome.

The method builds expression's tree for the native linear representation of the GEP chromosome.

MutateGene ( ) : void

Usual gene mutation.

The method performs usual gene mutation by randomly changing randomly selected gene.

Recombine ( IGPGene src1, IGPGene src2, int point, int length ) : void

Swap parts of two chromosomes.

The method performs interchanging of genes between two chromosomes starting from the point position.

TransposeIS ( ) : void

Transposition of IS elements (insertion sequence).

The method performs transposition of IS elements by copying randomly selected region of genes into chromosome's head (into randomly selected position). First gene of the chromosome's head is not affected - can not be selected as target point.

TransposeRoot ( ) : void

Root transposition.

The method performs root transposition of the GEP chromosome - inserting new root of the chromosome and shifting existing one. The method first of all randomly selects a function gene in chromosome's head - starting point of the sequence to put into chromosome's head. Then it randomly selects the length of the sequence making sure that the entire sequence is located within head. Once the starting point and the length of the sequence are known, it is copied into chromosome's head shifting existing elements in the head.

Method Details

Clone() public méthode

Clone the chromosome.

The method clones the chromosome returning the exact copy of it.

public Clone ( ) : IChromosome
Résultat IChromosome

CreateNew() public méthode

Create new random chromosome with same parameters (factory method).

The method creates new chromosome of the same type, but randomly initialized. The method is useful as factory method for those classes, which work with chromosome's interface, but not with particular chromosome type.

public CreateNew ( ) : IChromosome
Résultat IChromosome

Crossover() public méthode

Crossover operator.

The method performs one-point or two-point crossover selecting them randomly with equal probability.

public Crossover ( IChromosome pair ) : void
pair IChromosome Pair chromosome to crossover with.
Résultat void

GEPChromosome() protected méthode

Initializes a new instance of the GEPChromosome class.
protected GEPChromosome ( GEPChromosome source ) : System
source GEPChromosome Source GEP chromosome to clone from.
Résultat System

GEPChromosome() public méthode

Initializes a new instance of the GEPChromosome class.

This constructor creates a randomly generated GEP chromosome, which has all genes of the same type and properties as the specified ancestor.

public GEPChromosome ( IGPGene ancestor, int headLength ) : System
ancestor IGPGene A gene, which is used as generator for the genetic tree.
headLength int Length of GEP chromosome's head (see ).
Résultat System

Generate() public méthode

Generate random chromosome value.

Regenerates chromosome's value using random number generator.

public Generate ( ) : void
Résultat void

GetTree() protected méthode

Get tree representation of the chromosome.

The method builds expression's tree for the native linear representation of the GEP chromosome.

protected GetTree ( ) : GPTreeNode
Résultat GPTreeNode

Mutate() public méthode

Mutation operator.

The method performs chromosome's mutation by calling on of the methods randomly: MutateGene, TransposeIS, TransposeRoot.

public Mutate ( ) : void
Résultat void

MutateGene() protected méthode

Usual gene mutation.

The method performs usual gene mutation by randomly changing randomly selected gene.

protected MutateGene ( ) : void
Résultat void

RecombinationOnePoint() public méthode

One-point recombination (crossover).
public RecombinationOnePoint ( GEPChromosome pair ) : void
pair GEPChromosome Pair chromosome to crossover with.
Résultat void

RecombinationTwoPoint() public méthode

Two point recombination (crossover).
public RecombinationTwoPoint ( GEPChromosome pair ) : void
pair GEPChromosome Pair chromosome to crossover with.
Résultat void

Recombine() protected static méthode

Swap parts of two chromosomes.

The method performs interchanging of genes between two chromosomes starting from the point position.

protected static Recombine ( IGPGene src1, IGPGene src2, int point, int length ) : void
src1 IGPGene First chromosome participating in genes' interchange.
src2 IGPGene Second chromosome participating in genes' interchange.
point int Index of the first gene in the interchange sequence.
length int Length of the interchange sequence - number of genes /// to interchange.
Résultat void

ToString() public méthode

Get string representation of the chromosome by providing its expression in reverse polish notation (postfix notation).
public ToString ( ) : string
Résultat string

ToStringNative() public méthode

Get string representation of the chromosome.

The method is used for debugging mostly.

public ToStringNative ( ) : string
Résultat string

TransposeIS() protected méthode

Transposition of IS elements (insertion sequence).

The method performs transposition of IS elements by copying randomly selected region of genes into chromosome's head (into randomly selected position). First gene of the chromosome's head is not affected - can not be selected as target point.

protected TransposeIS ( ) : void
Résultat void

TransposeRoot() protected méthode

Root transposition.

The method performs root transposition of the GEP chromosome - inserting new root of the chromosome and shifting existing one. The method first of all randomly selects a function gene in chromosome's head - starting point of the sequence to put into chromosome's head. Then it randomly selects the length of the sequence making sure that the entire sequence is located within head. Once the starting point and the length of the sequence are known, it is copied into chromosome's head shifting existing elements in the head.

protected TransposeRoot ( ) : void
Résultat void

Property Details

genes protected_oe property

Array of chromosome's genes.
protected IGPGene[] genes
Résultat IGPGene[]

headLength protected_oe property

Length of GEP chromosome's head.

GEP chromosome's head is a part of chromosome, which may contain both functions' and arguments' nodes. The rest of chromosome (tail) may contain only arguments' nodes.

protected int headLength
Résultat int

length protected_oe property

GEP chromosome's length.

The variable keeps chromosome's length, but not expression length represented by the chromosome.

protected int length
Résultat int

rand protected_oe static_oe property

Random generator used for chromosoms' generation.
protected static ThreadSafeRandom rand
Résultat ThreadSafeRandom