Genetic Programming (GP)
Genetic programming (GP) searches a mathematical expression, e.g. a formula that fits a table of
values (symbolic regression). It represents an expression as a tree: the inner nodes are
functions such as plus or multiply, the leaves are terminals, the input variables and
constants.
In EvoAl, an expression is a model: a tree of DL objects that is the structured search data of
the problem (data 'f' of instance 'expression'). The plugin de.evoal.optimisation.gp adds
the functions, a fitness function and a check; the search itself is the one of every model
search space:
'random-population'builds the initial trees withgrow,fullor'ramped-half-and-half'(see Optimisers);- the evolutionary algorithm changes them with the operators of a
'model-chromosome':'subtree-crossover','subtree-mutation'and the value mutations of the constants (see Evolutionary Algorithm); - the candidate checks
'maximum-size'and'maximum-depth'limit the trees.
Random search can search the same models.
The 'subtype-weights' of a 'tree-method' restrict the function set without changing the DL
module and set the share of the terminals: a weight of 0 for
"de.evoal.optimisation.gp.genetic-programming.protected-square-root" keeps the square root out
of the trees of that method, a weight of 2 for
"de.evoal.optimisation.gp.genetic-programming.constant" makes every constant twice as likely
(see Optimisers). Name the
weights in the method of 'random-population' and in the one of 'subtree-mutation'.
Function set and terminal set
The module de.evoal.optimisation.gp.genetic-programming declares the functions and the
abstract types of the terminals:
| DL type | Value |
|---|---|
plus, minus, multiply |
left + right, left - right, left * right |
'protected-division' |
left / right, 1 if right is 0 |
'protected-square-root' |
the square root of \|operand\| |
'protected-power' |
\|left\|^right, 1 if the result is not finite |
subtypes of variable |
the value of the input data the variable is bound to |
subtypes of constant |
their attribute 'value' |
The terminals belong to the problem, so its own DL module declares them as subtypes:
import "definitions" from 'de.evoal.core.constraints';
import "definitions" from 'de.evoal.optimisation.gp.genetic-programming';
module 'gp-example' {
type x extends variable {}
type 'c' extends constant {
@Scale { scale := 'measurement-scale.cardinal'; }
@LowerBoundary { boundary := -50.0; }
@UpperBoundary { boundary := 50.0; }
'value' : real;
}
}
A variable type has no attribute. A constant type has exactly one real attribute 'value' with
its boundaries and scale. A constant is an ephemeral random constant: its value is drawn when
the tree is built and then changed only by mutations ('gaussian-mutation',
'random-reset-mutation'); a fixed constant has equal boundaries. A tree may contain every
concrete subtype of 'expression' of the loaded modules. 'expression' and 'c' are written
in quotes: expression is a keyword, and c is the unit prefix centi.
A variable type and a data must not have the same qualified name: a type x0 in a DL module
'gp-example' and a data 'x0' in a DDL module 'gp-example' clash. The example therefore
names its variable type x.
Fitness 'symbolic-regression-fitness'
'optimisation-function' := 'symbolic-regression-fitness' {
function := data 'regression-function';
input := [ 'variable-binding' { variable := x {}; 'data' := data 'x0'; } ];
output := data 'y0';
reference := "gp-example-function-data.csv";
error := data 'error';
measure := 'regression-error.sum-of-absolute-errors';
};
function: the searched expression.input: binds every variable type to the data that holds its value.output: the data with the target value.reference: the table; its columns are named by the data, e.g. a CSV file with the headerx0,y0. The reader is chosen by the file extension.error: the numeric objective that gets the error.measure:'regression-error.sum-of-absolute-errors'or'regression-error.mean-squared-error'.
When the configuration is loaded, the function checks that every variable type has exactly one
binding, that every constant type has one real 'value', that every subtype of 'expression'
is a function, a variable or a constant, and that the table has a value of every bound data in
every row. A prediction that is not finite gives an error that is not finite, which ranks worst
when the error is minimised.
Check 'uses-variable'
'uses-variable' { model := data 'f'; count := 1; } fails a new candidate whose expression uses
fewer than count different variable types, e.g. a constant expression. Its reactions are
warn, replace and resample.
Example
The example
genetic-programming
searches an expression for the table of y = 5 x^3 + 42 on x = -1000, -998, ..., 1000 with
the evolutionary algorithm; its README explains the configuration. The
README of the plugin
gives the details and the literature: Koza 1992 (ISBN 0-262-11170-5); Poli, Langdon and McPhee
2008, A Field Guide to Genetic Programming (ISBN 978-1-4092-0073-4); Montana 1995,
https://doi.org/10.1162/evco.1995.3.2.199.