Key words: Evolutionary algorithms, genetic programming, grammat- ical evolution, shared ... syntactically legal. With CFG-GP, Whigham [2] not only introduced the use of ... We do so by deriving a solution candidate from the original grammar, which again involves ..... Strategizing Machine for Game Playing and Beyond.
Fast Grammar-Based Evolution Using Memoization Martin Luerssen and David Powers Artificial Intelligence Laboratory, School of Computer Science, Engineering and Mathematics, Flinders University, Adelaide, Australia {martin.luerssen,david.powers}@flinders.edu.au
Abstract. A streamlined, open-source implementation of Shared Grammar Evolution represents candidate solutions as grammars that can share production rules. It offers competitive search performance, while requiring little user-tuning of parameters. Uniquely, the system natively supports the memoization of return values computed during evaluation, which are stored with each rule and also shared between solutions. Significant improvements in evaluation time, up to 3.9-fold in one case, were observed when solving a set of classic GP problems – and even greater improvements can be expected for computation-intensive tasks. Additionally, the rule-based caching of intermediate representations, specifically of the terminal stack, was explored. It was shown to produce significant, although lesser speedups that were partly negated by computational overhead, but may be useful in dynamic and memory-bound tasks otherwise not amenable to memoization. Key words: Evolutionary algorithms, genetic programming, grammatical evolution, shared grammar evolution, memoization
1
Introduction
Genetic Programming (GP) [1] operates on variable-length n-ary syntax trees, which offer greater representational flexibility than the fixed-length strings used in the canonical genetic algorithm. One of the main constraints of GP is the need for closure, i.e., the requirement that any combination of arguments is syntactically legal. With CFG-GP, Whigham [2] not only introduced the use of context-free grammars (CFGs) for this purpose, but also included an automatic mechanism for modifying the grammar based on the fittest solutions, an idea that has since found further refinement in Grammar-Model-based Program Evolution [3]. Adapting the CFG in this way improves the search bias towards not just valid, but better performing solutions. Grammars can also assist in another GP challenge: that of achieving scalability. For a variable length representation, search spaces are effectively unbounded; solutions can exist in higher-dimensional spaces, even if they are structurally simple. Scalability can be facilitated here by a “divide and conquer” approach, which
2
Martin Luerssen and David Powers
decomposes the larger problem into weakly correlated subproblems that can be dealt with independently. Software engineering practice has inspired techniques such as Automatically Defined Functions (ADFs) [4] that extend GP by enabling the creation and reuse of discovered modules. Nature, however, has its own means of promoting modularity. Embryogenesis efficiently captures the difference between a compact, searchable representation (genotype) and the functional, highdimensional solution (phenotype). This mapping process can be modelled with a generative grammar; L-systems have been particularly popular in this context [5]. Shared Grammar Evolution (SGE) [6] combines the three uses of grammars for closure, bias, and modularity. Solutions obtained through SGE comply with a user-defined CFG – but are also represented directly as simple, deterministic CFGs. One of the notable side-benefits of this is an intrinsic support of memoization, that is, the caching of return values for parts of the evolved solution. As an evolved population converges, we can expect the similarity between members to increase, so memoization can accelerate evolution by reducing or even eliminating evaluation time of shared modules. This paper explores the performance benefits of memoization on solving several classic GP problems with SGE. Toward this purpose, we present a streamlined version of SGE that is now publicly available under an open source license. 1.1
Grammatical Evolution
Grammatical Evolution (GE) [7] is currently the most well-published technique of applying grammars to evolution. GE and SGE can be used towards the same tasks and share in common that solutions are derived from context-free grammars (CFGs) defined in Backus-Naur Form (BNF). However, the underlying mechanics differ substantially. GE employs a genetic algorithm, where the genotype is a variable-length bit string that is read left to right to generate 8-bit integers (so-called codons). The modulus of each codon and the total number of production rules in the CFG specifies the rule to be applied to the currently replaced nonterminal, starting from the axiom (starting symbol) and ending when all nonterminals have been replaced. If all codons are read but not all nonterminals are replaced, the expansion wraps and continues from the start of the genome, unless a pre-determined maximum number of wrappings has already been exceeded.
2
Shared Grammar Evolution
With SGE, the user must likewise provide an initial template CFG, which delimits the space of valid solution candidates. If we had knowledge of what made a good solution, we could perhaps define a grammar that only contains good solutions. The user rarely has this information in advance, but it is possible to sample this space. We do so by deriving a solution candidate from the original grammar, which again involves choosing between alternative production rules according to
Fast Grammar-Based Evolution Using Memoization
3
the original CFG. However, in SGE, these choices specify an i -grammar (individual grammar; see Figure 1) that produces just that one solution. i -grammar rules that originate from the same template rule are legal alternatives to each other, just as i -grammar axioms constitute alternative solution candidates. Applying selection to the solution population implies selection of i -grammar rules through their contribution to the selected solutions. The rule alternatives that survive are those that contribute to better solutions. As our search converges towards the optimum, so should the suitability of the production rules and hence the building blocks from which we build the solutions. Template grammar