alogos.systems._shared._cached_calculations
¶
Functions¶
|
Calculate for each production whether it contains a recursive nonterminal. |
|
Calculate for each production the depth required to reach only terminals. |
|
Calculate for each production the number of expansions required to reach only terminals. |
|
Calculate for each production the number of nodes required to reach only terminals. |
|
Create a dictionary of index to number of min nodes associations. |
Detailed object descriptions¶
- alogos.systems._shared._cached_calculations.is_recursive(grammar)[source]¶
Calculate for each production whether it contains a recursive nonterminal.
A nonterminal is considered to be recursive if it can produce itself, i.e. if starting from it some derivation can be constructed where the nonterminal appears again.
References
PonyGE2: src/representation/grammar.py
def check_recursion(self, cur_symbol, seen)
solves the same task in a different way with recursive function calls
Examples
S => SS => 1S => 12
means thatS
is trivially recursive, because there is a rule that replacesS
directly with a sequence of symbols that containsS
again.S => A => BB => 5B => 5S => 51
meansS
is non-trivially recursive, becauseS
can be replaced indirectly (via other nonterminals and their rules) with a sequence of symbols that containsS
again.
- alogos.systems._shared._cached_calculations.min_depths_to_terminals(grammar)[source]¶
Calculate for each production the depth required to reach only terminals.
This information is used during a derivation in order to remain within a maximum depth limit.
Algorithms that utilize it:
Initialization of an inidividual with “grow”, “pi grow” and “full” methods that are part of ramped half-and-half (rhh) population initialization.
References
PonyGE2: src/representation/grammar.py: Sensible initialization from GE (and other systems) uses this information to select rules
def check_depths(self)
solves the same task with other data structures
- alogos.systems._shared._cached_calculations.min_expansions_to_terminals(grammar)[source]¶
Calculate for each production the number of expansions required to reach only terminals.
This information is used during a derivation in order to remain within a maximum expansions limit.
Algorithms that utilize it:
Initialization of an inidividual with “PTC2” method.