alogos.systems.ge.mapping
¶
Forward and reverse mapping functions for GE.
Functions¶
|
Map a GE genotype to a string phenotype. |
|
Map a string phenotype (or derivation tree) to a GE genotype. |
Detailed object descriptions¶
- alogos.systems.ge.mapping.forward(grammar, genotype, parameters=None, raise_errors=True, return_derivation_tree=False, verbose=False)[source]¶
Map a GE genotype to a string phenotype.
It converts a genotype (=originally a list of integers) to a derivation tree (=linked nodes that each contain a nonterminal or terminal symbol), which can be further converted to a phenotype (=a string of the grammar’s language).
- Parameters:
grammar (
Grammar
)genotype (
Genotype
or data that can be converted to it)parameters (
dict
orParameterCollection
, optional) –raise_errors (
bool
, optional) – Possible values:True
: A mapping error will be raised if a derivation is not finished within a limit provided in the parameters.False
: A partial derivation is allowed. In this case, the returned string will contain unexpanded nonterminal symbols. Therefore it is not a valid phenotype, i.e. not a string of the grammar’s language but a so-called sentential form.
return_derivation_tree (
bool
, optional) – IfTrue
, not only the phenotype is returned but additionally also the derivation tree.verbose (
bool
, optional) – IfTrue
, output about steps of the mapping process is printed.
- Returns:
- Raises:
MappingError – If
raise_errors
isTrue
and the mapping process can not generate a full derivation before reaching a limit provided in the parameters.
- alogos.systems.ge.mapping.reverse(grammar, phenotype_or_derivation_tree, parameters=None, return_derivation_tree=False)[source]¶
Map a string phenotype (or derivation tree) to a GE genotype.
This is a reversal of the mapping procedure of Grammatical Evolution (GE). Note that many different GE genotypes can encode the same derivation tree and phenotype. It is possible to return a deterministic GE genotype that uses the lowest possible integer value for each choice of expansion, or a random GE genotype that uses a random integer value within the codon size limit. The latter is describes in literature as using an “unmod” operation to find a random codon value which is valid, in the sense that after applying the “mod” operation to it the result is the lowest possible integer.
- Parameters:
grammar (
Grammar
)phenotype_or_derivation_tree (
str
orDerivationTree
)parameters (
dict
orParameterCollection
, optional) – Following keyword-value pairs are considered by this function:codon_size
(int
): Codon size in bits. The number of different integer values a codon can assume is therefore determined by2**codon_size
.codon_randomization
(bool
): IfTrue
, the reverse mapping will use the so-called “unmod” operation and therefore generate random integers that encode the required rule choice. IfFalse
, the lowest possible integer will be used and the reverse mapping becomes deterministic.
return_derivation_tree (
bool
, optional) – IfTrue
, not only the genotype is returned but additionally also the derivation tree.
- Returns:
- Raises:
MappingError – If the reverse mapping fails because the string does not belong to the grammar’s language or the derivation tree does not represent a valid derivation.
References
Ryan, O’Neill, Collins - Handbook of Grammatical Evolution (2018)
p. 12: “Unmod produces the actual codons that will be used and essentially performs the opposite operation to mod, returning a number that, when divided by the number of choices available for the particular non-terminal, will return the choice made.”