alogos.systems._shared.init_individual

Shared individual initialization functions of different systems.

Functions

given_genotype(grammar, parameters, default_parameters, representation, mapping)

Create an individual from a given genotype.

given_derivation_tree(grammar, parameters, default_parameters, representation, mapping)

Create an individual from a given derivation tree.

given_phenotype(grammar, parameters, default_parameters, representation, mapping)

Create an individual from a given phenotype.

random_genotype(grammar, parameters, default_parameters, representation, mapping)

Create an individual from a random genotype.

random_valid_genotype(grammar, parameters, default_parameters, representation, mapping)

Create an individual from a random genotype likely to be valid.

gp_grow_tree(grammar, parameters, default_parameters, representation, mapping)

Create an individual from a tree created with "Grow" from GP.

gp_full_tree(grammar, parameters, default_parameters, representation, mapping)

Create an individual from a tree created with "Full" from GP.

pi_grow_tree(grammar, parameters, default_parameters, representation, mapping)

Create an individual from a tree created with Fagan's "PI Grow".

ptc2_tree(grammar, parameters, default_parameters, representation, mapping)

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


Detailed object descriptions

alogos.systems._shared.init_individual.given_genotype(grammar, parameters, default_parameters, representation, mapping)[source]

Create an individual from a given genotype.

Parameters:
  • grammar (Grammar)

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

    • init_ind_given_genotype : Data for a Genotype.

  • default_parameters (ParameterCollection) – Default parameters of the system that calls this generic function.

  • representation (module) – Representation module of the system that calls this generic function. This module contains the specific Genotype subclass of the system, which is used here to create the genotype for the individual.

  • mapping (function) – Mapping module of the system that calls this generic function. This module contains the specific forward function of the system, which is used here to map the genotype of the individual to a derivation tree and phenotype.

Raises:

InitializationError – If the initialization of the individual fails.

alogos.systems._shared.init_individual.given_derivation_tree(grammar, parameters, default_parameters, representation, mapping)[source]

Create an individual from a given derivation tree.

Parameters:
  • grammar (Grammar)

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

  • default_parameters (ParameterCollection) – Default parameters of the system that calls this generic function.

  • representation (module) – Representation module of the system that calls this generic function. This module contains the specific Genotype subclass of the system, which is used here to create the genotype for the individual.

  • mapping (function) – Mapping module of the system that calls this generic function. This module contains the specific reverse function of the system, which is used here to map the phenotype (read from the leaves of the derivation tree) to a genotype.

Raises:

InitializationError – If the initialization of the individual fails.

alogos.systems._shared.init_individual.given_phenotype(grammar, parameters, default_parameters, representation, mapping)[source]

Create an individual from a given phenotype.

Parameters:
  • grammar (Grammar)

  • parameters (dict or ParameterCollection) – 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.

  • default_parameters (ParameterCollection) – Default parameters of the system that calls this generic function.

  • representation (module) – Representation module of the system that calls this generic function. This module contains the specific Genotype subclass of the system, which is used here to create the genotype for the individual.

  • mapping (function) – Mapping module of the system that calls this generic function. This module contains the specific reverse function of the system, which is used here to map the phenotype to a genotype and derivation tree.

Raises:

InitializationError – If the initialization of the individual fails.

alogos.systems._shared.init_individual.random_genotype(grammar, parameters, default_parameters, representation, mapping)[source]

Create an individual from a random genotype.

Parameters:
  • grammar (Grammar)

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

    • genotype_length (int) : Number of integers in the GE or piGE Genotype.

    • codon_size (int) : Number of bits used for a codon, which determines the maximum integer value a codon can take. For example, a codon size of 8 bits allows integers from 0 to 255 (from 2**8-1).

  • default_parameters (ParameterCollection) – Default parameters of the system that calls this generic function.

  • representation (module) – Representation module of the system that calls this generic function. This module contains the specific Genotype subclass of the system, which is used here to create the genotype for the individual.

  • mapping (function) – Mapping module of the system that calls this generic function. This module contains the specific forward function of the system, which is used here to map the genotype to a phenotype and derivation tree.

Raises:

InitializationError – If the initialization of the individual fails.

alogos.systems._shared.init_individual.random_valid_genotype(grammar, parameters, default_parameters, representation, mapping)[source]

Create an individual from a random genotype likely to be valid.

Parameters:
  • grammar (Grammar)

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

    • genotype_length (int) : Number of integers in the GE or piGE Genotype.

    • codon_size (int) : Number of bits used for a codon, which determines the maximum integer value a codon can take. For example, a codon size of 8 bits allows integers from 0 to 255 (from 2**8-1).

    • init_ind_random_valid_genotype_max_tries (int) : Number of tries to generate a random valid genotype.

  • default_parameters (ParameterCollection) – Default parameters of the system that calls this generic function.

  • representation (module) – Representation module of the system that calls this generic function. This module contains the specific Genotype subclass of the system, which is used here to create the genotype for the individual.

  • mapping (function) – Mapping module of the system that calls this generic function. This module contains the specific forward function of the system, which is used here to map the genotype to a phenotype and derivation tree.

Raises:

InitializationError – If the initialization of the individual fails.

Notes

This function repeatedly calls random_genotype until it returns a genotype that can be mapped to a phenotype or a given maximum number of tries is reached.

alogos.systems._shared.init_individual.gp_grow_tree(grammar, parameters, default_parameters, representation, mapping)[source]

Create an individual from a tree created with “Grow” from GP.

References

  • 2016, Fagan et al.: Exploring position independent initialisation in grammatical evolution

    • “Traditional Grow in GP looks to construct a tree that is at most a certain depth. The trees are generally grown in a recursive manner, randomly picking production choices until only leaf nodes remain. If the tree approaches the depth limit then a terminating sequence is selected to make sure the depth limit is not breached”

    • “Grow randomly builds a tree up to a maximum specified depth. If a branch of the tree reaches the imposed depth limit the branch is finished by selecting only terminals. There is no guarantee of the tree reaching the depth limit.”

alogos.systems._shared.init_individual.gp_full_tree(grammar, parameters, default_parameters, representation, mapping)[source]

Create an individual from a tree created with “Full” from GP.

References

alogos.systems._shared.init_individual.pi_grow_tree(grammar, parameters, default_parameters, representation, mapping)[source]

Create an individual from a tree created with Fagan’s “PI Grow”.

References

  • 2016, Fagan et al.: Exploring position independent initialisation in grammatical evolution

    • “PI Grow now randomly selects a new non-terminal from the queue and again a production is done and the resulting symbols are added to the queue in the position from which the parent node was removed.”

    • “As the tree is being expanded, the algorithm checks to see if the current symbol is the last recursive symbol remaining in the queue. If the depth limit hasn’t been reached, and PI Grow currently has the last recursive symbol to expand, Pi Grow will only pick a production that results in recursive symbols. This process guarantees that at least one branch will reach the specified depth limit. This gives the initialiser the freedom to generate trees of both a Full and Grow nature.”

alogos.systems._shared.init_individual.ptc2_tree(grammar, parameters, default_parameters, representation, mapping)[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.

  • default_parameters (ParameterCollection) – Default parameters of the system that calls this generic function.

  • representation (module) – Representation module of the system that calls this generic function. This module contains the specific Genotype subclass of the system, which is used here to create the genotype for the individual.

  • mapping (function) – Mapping module of the system that calls this generic function. This module contains the specific reverse function of the system, which is used here to map the phenotype to a genotype and derivation tree.

Raises:

InitializationError – If the initialization of the individual fails.

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”