C# Class Accord.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
Datei anzeigen Open project: accord-net/framework Class Usage Examples

Protected Properties

Property Type Description
genes IGPGene[]
headLength int
length int

Public Methods

Method 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.

Protected Methods

Method 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 method

Clone the chromosome.

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

public Clone ( ) : IChromosome
return IChromosome

CreateNew() public method

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
return IChromosome

Crossover() public method

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.
return void

GEPChromosome() protected method

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

GEPChromosome() public method

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 ).
return System

Generate() public method

Generate random chromosome value.

Regenerates chromosome's value using random number generator.

public Generate ( ) : void
return void

GetTree() protected method

Get tree representation of the chromosome.

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

protected GetTree ( ) : GPTreeNode
return GPTreeNode

Mutate() public method

Mutation operator.

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

public Mutate ( ) : void
return void

MutateGene() protected method

Usual gene mutation.

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

protected MutateGene ( ) : void
return void

RecombinationOnePoint() public method

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

RecombinationTwoPoint() public method

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

Recombine() protected static method

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.
return void

ToString() public method

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

ToStringNative() public method

Get string representation of the chromosome.

The method is used for debugging mostly.

public ToStringNative ( ) : string
return string

TransposeIS() protected method

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
return void

TransposeRoot() protected method

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
return void

Property Details

genes protected_oe property

Array of chromosome's genes.
protected IGPGene[] genes
return 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
return 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
return int