alogos.systems.cfggpst.init_individual

Initialization functions to create a CFG-GP-ST individual.

Functions

given_genotype(grammar, parameters=None)

Create an individual from a given genotype.

given_derivation_tree(grammar, parameters=None)

Create an individual from a given derivation tree.

given_phenotype(grammar, parameters=None)

Create an individual from a given phenotype.

random_genotype(grammar, parameters=None)

Create an individual from a random genotype.

gp_grow_tree(grammar, parameters=None)

Create an individual from a random tree grown.

pi_grow_tree(grammar, parameters=None)

Create an individual from a random tree grown in a position-independently fashion.

gp_full_tree(grammar, parameters=None)

Create an individual from a random tree that is grown fully to a maximum depth.

ptc2_tree(grammar, parameters=None)

Create an individual from a tree grown with Nicolau's "PTC2".


Detailed object descriptions

alogos.systems.cfggpst.init_individual.given_genotype(grammar, parameters=None)[source]

Create an individual from a given genotype.

Parameters:
  • grammar (Grammar)

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

    • init_ind_given_genotype : Data for a CFG-GP-ST Genotype.

Raises:

InitializationError – If the initialization of the individual fails.

Notes

The genotype is converted to a derivation tree and phenotype with the forward mapping function of this system.

alogos.systems.cfggpst.init_individual.given_derivation_tree(grammar, parameters=None)[source]

Create an individual from a given derivation tree.

Parameters:
Raises:

InitializationError – If the initialization of the individual fails.

Notes

The leaf nodes of the derivation tree are read to create the phenotype. The phenotype is converted to a genotype with the reverse mapping function of this system.

alogos.systems.cfggpst.init_individual.given_phenotype(grammar, parameters=None)[source]

Create an individual from a given phenotype.

Parameters:
  • grammar (Grammar)

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

    • init_ind_given_phenotype (str) : Data for a phenotype, which needs to be a string of the grammar’s language.

Raises:

InitializationError – If the initialization of the individual fails.

Notes

The phenotype is converted to a genotype and derivation tree with the reverse mapping function of this system.

alogos.systems.cfggpst.init_individual.random_genotype(grammar, parameters=None)[source]

Create an individual from a random genotype.

Parameters:
  • grammar (Grammar)

  • parameters (dict or ParameterCollection, optional) – No keyword-value pairs are considered by this function. This argument is only available to have a consistent interface.

Raises:

InitializationError – If the initialization of the individual fails.

alogos.systems.cfggpst.init_individual.gp_grow_tree(grammar, parameters=None)[source]

Create an individual from a random tree grown.

alogos.systems.cfggpst.init_individual.pi_grow_tree(grammar, parameters=None)[source]

Create an individual from a random tree grown in a position-independently fashion.

alogos.systems.cfggpst.init_individual.gp_full_tree(grammar, parameters=None)[source]

Create an individual from a random tree that is grown fully to a maximum depth.

alogos.systems.cfggpst.init_individual.ptc2_tree(grammar, parameters=None)[source]

Create an individual from a tree grown with Nicolau’s “PTC2”.

The original PTC2 method for growing random trees was invented by Sean Luke in 2000. Some slightly modified variants were introduced later by other authors. This function implements a PTC2 variant described by Miguel Nicolau in 2017 in section “3.3 Probabilistic tree-creation 2 (PTC2)” of the publication. It restricts tree size not with a maximum tree depth but rather with a maximum number of expansions and if possible remains strictly below this limit.

Parameters:
  • grammar (Grammar)

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

    • init_ind_ptc2_max_expansions (int): The maximum number of nonterminal expansions that may be used to grow the tree.

Raises:

InitializationError – If the initialization of the individual fails.

Notes

The leaf nodes of the derivation tree are read to create the phenotype. The phenotype is converted to a genotype with the reverse mapping function of this system.

References

  • 2000, Luke: Two Fast Tree-Creation Algorithms for Genetic Programming

    • “PTC1 is a modification of GROW that allows the user to provide probabilities of appearance of functions in the tree, plus a desired expected tree size, and guarantees that, on average, trees will be of that size.”

    • “With PTC2, the user provides a probability distribution of requested tree sizes. PTC2 guarantees that, once it has picked a random tree size from this distribution, it will generate and return a tree of that size or slightly larger.”

  • 2010, Harper: GE, explosive grammars and the lasting legacy of bad initialisation

    • “The PTC2 methodology is extended to GE and found to produce a more uniform distribution of parse trees.”

    • “If the algorithm is called in a ramped way (i.e. starting with a low number of expansions, say 20, and increasing until say 240) then a large number of trees of different size and shapes will be generated.”

  • 2017, Nicolau: Understanding grammatical evolution: initialisation:

    • 3.3 Probabilistic tree-creation 2 (PTC2)

    • 3.6 Probabilistic tree-creation 2 with depth limit (PTC2D)

  • 2018, Ryan, O’Neill, Collins: Handbook of Grammatical Evolution

    • p. 13: “More recent work on initialisation includes that of Nicolau, who demonstrated that across the problems examined in their study, a variant of Harper’s PTC2 consistently outperforms other initialisations”