alogos.systems.dsge.mapping

Forward and reverse mapping functions for DSGE.

Functions

forward(grammar, genotype, parameters=None, raise_errors=True, return_derivation_tree=False, verbose=False)

Map a DSGE genotype to a string phenotype.

reverse(grammar, phenotype_or_derivation_tree, parameters=None, return_derivation_tree=False)

Map a string phenotype (or derivation tree) to a DSGE genotype.


Detailed object descriptions

alogos.systems.dsge.mapping.forward(grammar, genotype, parameters=None, raise_errors=True, return_derivation_tree=False, verbose=False)[source]

Map a DSGE genotype to a string phenotype.

Parameters:
  • grammar (Grammar)

  • genotype (Genotype or data that can be converted to it)

  • parameters (dict or ParameterCollection, optional) – Following keyword-value pairs are considered by this function:

    • max_expansions (int): Maximum number of nonterminal expansions allowed in the derivation created by the mapping process.

  • 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) – If True, not only the phenotype is returned but additionally also the derivation tree.

  • verbose (bool, optional) – If True, output about steps of the mapping process is printed.

Returns:

  • phenotype (str) – If return_derivation_tree is False, which is the default.

  • (phenotype, derivation_tree) (tuple with two elements of type str and DerivationTree) – If return_derivation_tree is True.

Raises:

MappingError – If raise_errors is True and the mapping process can not generate a full derivation before reaching a limit provided in the parameters.

Notes

The 2018 paper describes that the mapping function sometimes has to randomly select rules during a derivation. This is necessary when the genotype was modified by a variation operator in such a way that not enough codons are available in a gene of the genotype to fully encode a phenotype. Here, in this implementation of DSGE, the random selection of rules was removed from the mapping function. Instead, a dedicated repair function was added to the system, which is responsible to add missing or remove superfluous codons of a genotype after it was modified by a variation operator. The advantage with this approach is that the mapping function becomes deterministic, meaning that the same genotype is always mapped to the same phenotype, as is the usually the case for systems inspired by Grammatical Evolution (GE). This eases the analysis of completed runs and the reuse of genotypes in future runs.

alogos.systems.dsge.mapping.reverse(grammar, phenotype_or_derivation_tree, parameters=None, return_derivation_tree=False)[source]

Map a string phenotype (or derivation tree) to a DSGE genotype.