C# Класс 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.

Наследование: ChromosomeBase
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
genes IGPGene[]
headLength int
length int
rand ThreadSafeRandom

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
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.

Описание методов

Clone() публичный метод

Clone the chromosome.

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

public Clone ( ) : IChromosome
Результат IChromosome

CreateNew() публичный метод

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
Результат IChromosome

Crossover() публичный метод

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.
Результат void

GEPChromosome() защищенный метод

Initializes a new instance of the GEPChromosome class.
protected GEPChromosome ( GEPChromosome source ) : System
source GEPChromosome Source GEP chromosome to clone from.
Результат System

GEPChromosome() публичный метод

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 ).
Результат System

Generate() публичный метод

Generate random chromosome value.

Regenerates chromosome's value using random number generator.

public Generate ( ) : void
Результат void

GetTree() защищенный метод

Get tree representation of the chromosome.

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

protected GetTree ( ) : GPTreeNode
Результат GPTreeNode

Mutate() публичный метод

Mutation operator.

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

public Mutate ( ) : void
Результат void

MutateGene() защищенный метод

Usual gene mutation.

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

protected MutateGene ( ) : void
Результат void

RecombinationOnePoint() публичный метод

One-point recombination (crossover).
public RecombinationOnePoint ( GEPChromosome pair ) : void
pair GEPChromosome Pair chromosome to crossover with.
Результат void

RecombinationTwoPoint() публичный метод

Two point recombination (crossover).
public RecombinationTwoPoint ( GEPChromosome pair ) : void
pair GEPChromosome Pair chromosome to crossover with.
Результат void

Recombine() защищенный статический метод

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.
Результат void

ToString() публичный метод

Get string representation of the chromosome by providing its expression in reverse polish notation (postfix notation).
public ToString ( ) : string
Результат string

ToStringNative() публичный метод

Get string representation of the chromosome.

The method is used for debugging mostly.

public ToStringNative ( ) : string
Результат string

TransposeIS() защищенный метод

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
Результат void

TransposeRoot() защищенный метод

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
Результат void

Описание свойств

genes защищенное свойство

Array of chromosome's genes.
protected IGPGene[] genes
Результат IGPGene[]

headLength защищенное свойство

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
Результат int

length защищенное свойство

GEP chromosome's length.

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

protected int length
Результат int

rand защищенное статическое свойство

Random generator used for chromosoms' generation.
protected static ThreadSafeRandom rand
Результат ThreadSafeRandom